aboutsummaryrefslogtreecommitdiff
path: root/errhandlers
diff options
context:
space:
mode:
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
+}