aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-08-15 13:49:44 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-08-15 13:49:44 +0530
commitd7cf6b9ed5828d8ca5d1e56adf00ff3fd6a5a4ab (patch)
tree22d18647770423d335d000e0af3d933b39472278
parent9b3d6d0ec5ecb9d73b518d786a22cb3ff7f3768f (diff)
checking if season year is int or notv0.0.2
-rw-r--r--errors.go1
-rw-r--r--validators.go9
2 files changed, 7 insertions, 3 deletions
diff --git a/errors.go b/errors.go
index d2b2828..3c127b6 100644
--- a/errors.go
+++ b/errors.go
@@ -31,4 +31,5 @@ var (
ErrInvalidRewatchValue = errors.New("mg: invalid rewatch value")
ErrInvalidRereadValue = errors.New("mg: invalid reread value")
ErrEmptySearchString = errors.New("mg: invalid search string (empty string)")
+ ErrInvalidYear = errors.New("mg: invalid year (not integer)")
)
diff --git a/validators.go b/validators.go
index 7386c23..dd45014 100644
--- a/validators.go
+++ b/validators.go
@@ -19,6 +19,7 @@ package mg
import (
"strings"
+ "strconv"
"slices"
)
@@ -235,8 +236,12 @@ func validateAnimeRankingParams(params *RankingParams) error {
func validateSeasonalParams(params *SeasonalParams) error {
// check if year is int
+ _, err := strconv.Atoi(params.Year)
+ if err != nil {
+ return ErrInvalidYear
+ }
- err := validateAnimeSeason(params.Season)
+ err = validateAnimeSeason(params.Season)
if err != nil {
return err
}
@@ -302,7 +307,6 @@ func validateMangaSearchParams(params *SearchParams) error {
return err
}
-
func validateMangaRankingParams(params *RankingParams) error {
err := validateMangaRankingType(params.RankingType)
if err != nil {
@@ -318,7 +322,6 @@ func validateMangaRankingParams(params *RankingParams) error {
return err
}
-
func validateMangaListParams(params *ListParams) error {
// if username is empty, set it to @me
if strings.TrimSpace(params.Username) == "" {