aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anime_list.go9
-rw-r--r--manga_list.go9
-rw-r--r--validators.go51
3 files changed, 65 insertions, 4 deletions
diff --git a/anime_list.go b/anime_list.go
index 0d8a0ff..9d0f370 100644
--- a/anime_list.go
+++ b/anime_list.go
@@ -43,8 +43,13 @@ func (c Client) DeleteAnime(id int) error {
}
func (c Client) GetAnimeList(animes *[]Anime, params *ListParams) (bool, error) {
- // TODO: validate params
- //params.Fields = append(params.Fields, "list_status")
+ err := validateAnimeListParams(params)
+ if err != nil {
+ return false, err
+ }
+
+ params.Fields = append(params.Fields, "list_status")
+
var res struct {
Data []struct {
Anime Anime `json:"node"`
diff --git a/manga_list.go b/manga_list.go
index 06fb249..1c04463 100644
--- a/manga_list.go
+++ b/manga_list.go
@@ -44,8 +44,13 @@ func (c Client) DeleteManga(id int) error {
}
func (c Client) GetMangaList(mangas *[]Manga, params *ListParams) (bool, error) {
- // TODO: validate params
- //params.Fields = append(params.Fields, "list_status")
+ err := validateMangaListParams(params)
+ if err != nil {
+ return false, err
+ }
+
+ params.Fields = append(params.Fields, "list_status")
+
var res struct {
Data []struct {
Manga Manga `json:"node"`
diff --git a/validators.go b/validators.go
index 2dafaad..7386c23 100644
--- a/validators.go
+++ b/validators.go
@@ -263,6 +263,31 @@ func validateSuggestedParams(params *SuggestedParams) error {
return validateAnimeFields(&params.Fields)
}
+func validateAnimeListParams(params *ListParams) error {
+ // if username is empty, set it to @me
+ if strings.TrimSpace(params.Username) == "" {
+ params.Username = "@me"
+ }
+
+ if params.Status != "" {
+ err := validateAnimeListStatus(params.Status)
+ if err != nil {
+ return err
+ }
+ }
+
+ err := validateAnimeListSort(params.Sort)
+ if err != nil {
+ return err
+ }
+
+ if params.Limit > 1000 || params.Limit < 1 {
+ return ErrLimitOutOfRange
+ }
+
+ return validateAnimeFields(&params.Fields)
+}
+
func validateMangaSearchParams(params *SearchParams) error {
if strings.TrimSpace(params.SearchString) == "" {
return ErrEmptySearchString
@@ -292,3 +317,29 @@ 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) == "" {
+ params.Username = "@me"
+ }
+
+ if params.Status != "" {
+ err := validateMangaListStatus(params.Status)
+ if err != nil {
+ return err
+ }
+ }
+
+ err := validateMangaListSort(params.Sort)
+ if err != nil {
+ return err
+ }
+
+ if params.Limit > 1000 || params.Limit < 1 {
+ return ErrLimitOutOfRange
+ }
+
+ return validateMangaFields(&params.Fields)
+}