aboutsummaryrefslogtreecommitdiff
path: root/errhandlers
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-13 14:12:45 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-13 14:12:45 +0530
commit937f3b8ada85274dfe3842f3dde8aef45c4f3ae7 (patch)
tree7de3ab75005620e33f8aac32554695b7eecd552c /errhandlers
parent1d3f72c1b48998b86fd1740e893559b6dcaf7663 (diff)
completed (?) the GetAnimeList function
Diffstat (limited to 'errhandlers')
-rw-r--r--errhandlers/errhandlers.go8
-rw-r--r--errhandlers/validators.go30
2 files changed, 33 insertions, 5 deletions
diff --git a/errhandlers/errhandlers.go b/errhandlers/errhandlers.go
index 50f4aac..a9f8054 100644
--- a/errhandlers/errhandlers.go
+++ b/errhandlers/errhandlers.go
@@ -41,10 +41,10 @@ func FieldsErrHandler(fields []string) ([]string, error) {
}
// if limit or error specified are above the limit
-func LimitsErrHandler(limit, offset int) error {
- maxOffset := 500 - limit
- if limit > 500 {
- return errors.New(fmt.Sprintf("InvalidLimitError: Limit specified too high (%d > 500).", limit))
+func LimitsErrHandler(limit, offset, maxLimit int) error {
+ maxOffset := maxLimit - limit
+ if limit > maxLimit {
+ return errors.New(fmt.Sprintf("InvalidLimitError: Limit specified too high (%d > %d).", limit, maxLimit))
} else if offset > maxOffset {
return errors.New(fmt.Sprintf("InvalidOffsetError: Offset specified too high (%d > %d).", offset, maxOffset))
}
diff --git a/errhandlers/validators.go b/errhandlers/validators.go
index f9baea1..6bf7a3f 100644
--- a/errhandlers/validators.go
+++ b/errhandlers/validators.go
@@ -86,7 +86,8 @@ func IsValidSeason(season string) bool {
}
// Checks if given sort is valid
-func IsValidSort(sort string) bool {
+// For seasonal anime lists
+func IsValidSeasonalSort(sort string) bool {
switch sort {
case
"anime_score",
@@ -94,3 +95,30 @@ func IsValidSort(sort string) bool {
}
return false
}
+
+// Checks if given sort is valid
+// for user anime lists
+func IsValidListSort(sort string) bool {
+ switch sort {
+ case
+ "list_score",
+ "list_updated_at",
+ "anime_title",
+ "anime_start_date",
+ "anime_id": return true
+ }
+ return false
+}
+
+// Checks if given anime list status is valid
+func IsValidListStatus(status string) bool {
+ switch status {
+ case
+ "watching",
+ "completed",
+ "on_hold",
+ "dropped",
+ "plan_to_watch": return true
+ }
+ return false
+}