aboutsummaryrefslogtreecommitdiff
path: root/anime_list.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-08-15 14:19:33 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-08-15 14:19:33 +0530
commitf4051d90a3e0520017020a145c1ccd129bb27aa3 (patch)
tree056da5a42467bca5f4df82fed21d399fe935e838 /anime_list.go
parentd7cf6b9ed5828d8ca5d1e56adf00ff3fd6a5a4ab (diff)
added validators for updating anime and mangav0.0.3
Diffstat (limited to 'anime_list.go')
-rw-r--r--anime_list.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/anime_list.go b/anime_list.go
index 9d0f370..440e672 100644
--- a/anime_list.go
+++ b/anime_list.go
@@ -77,10 +77,33 @@ func (c Client) GetAnimeList(animes *[]Anime, params *ListParams) (bool, error)
}
func (c Client) UpdateAnime(res *AnimeUpdateResponse, id int, params map[string]interface{}) error {
- // TODO: validate params
p := url.Values{}
for k, v := range params {
- p.Set(k, fmt.Sprint(v))
+ vString := fmt.Sprint(v)
+ var err error
+
+ // validate params
+ switch(k) {
+ case Status:
+ err = validateAnimeListStatus(vString)
+ case Score:
+ err = validateScore(v.(int))
+ case Priority:
+ err = validatePriority(v.(int))
+ case RewatchValue:
+ err = validateRewatchValue(v.(int))
+ case Tags, Comments, IsRewatching, EpisodesWatched, TimesRewatched:
+ // these ones don't need to be validated
+ err = nil
+ default:
+ err = ErrUnknownUpdateParam
+ }
+
+ if err != nil {
+ return err
+ }
+
+ p.Set(k, vString)
}
body, err := c.put(getUpdateQuery(id, "anime"), p)