diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-16 22:20:17 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-16 22:20:17 +0530 |
commit | 05fe09f3ec167417ea94fc04148ac110f18c4ad6 (patch) | |
tree | 19d7c2713c8e24772ccbacc1572c354d48707dc9 /user/anime/update_animelist.go | |
parent | 71210ebc8e04d49a6afeeecee842b2e8b53f3c4f (diff) |
added api error handling to user/anime and user/manga packages
Diffstat (limited to 'user/anime/update_animelist.go')
-rw-r--r-- | user/anime/update_animelist.go | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/user/anime/update_animelist.go b/user/anime/update_animelist.go index 780f079..ec0d60d 100644 --- a/user/anime/update_animelist.go +++ b/user/anime/update_animelist.go @@ -18,8 +18,8 @@ package anime import ( e "github.com/MikunoNaka/MAL2Go/errhandlers" "fmt" - "net/url" - "strconv" + "net/url" + "strconv" ) // generate the endpoint url with the anime id @@ -28,12 +28,12 @@ func endpointGenerator(id int) string { } // update just an anime's status -func (c Client)SetStatus(id int, status string) (serverResponse, error) { +func (c Client)SetStatus(id int, status string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified list status is valid if !e.IsValidListStatus(status) { - return serverResponse{}, e.InvalidStatusError + return UpdateResponse{}, e.InvalidStatusError } // data to be sent to the server @@ -41,11 +41,11 @@ func (c Client)SetStatus(id int, status string) (serverResponse, error) { params.Set("status", status) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's num of episodes watched -func (c Client)SetWatchedEpisodes(id int, episodesWatched int) (serverResponse, error) { +func (c Client)SetWatchedEpisodes(id int, episodesWatched int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -53,11 +53,11 @@ func (c Client)SetWatchedEpisodes(id int, episodesWatched int) (serverResponse, params.Set("num_watched_episodes", strconv.Itoa(episodesWatched)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's rewatching status -func (c Client)SetIsRewatching(id int, isRewatching bool) (serverResponse, error) { +func (c Client)SetIsRewatching(id int, isRewatching bool) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -65,16 +65,16 @@ func (c Client)SetIsRewatching(id int, isRewatching bool) (serverResponse, error params.Set("is_rewatching", strconv.FormatBool(isRewatching)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just the anime's score -func (c Client)SetScore(id int, score int) (serverResponse, error) { +func (c Client)SetScore(id int, score int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified score is valid if !e.IsValidScore(score) { - return serverResponse{}, e.InvalidScoreError + return UpdateResponse{}, e.InvalidScoreError } // data to be sent to the server @@ -82,16 +82,16 @@ func (c Client)SetScore(id int, score int) (serverResponse, error) { params.Set("score", strconv.Itoa(score)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's priority -func (c Client)SetPriority(id int, priority int) (serverResponse, error) { +func (c Client)SetPriority(id int, priority int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified priority is valid if !e.IsValidPriority(priority) { - return serverResponse{}, e.InvalidPriorityError + return UpdateResponse{}, e.InvalidPriorityError } // data to be sent to the server @@ -99,16 +99,16 @@ func (c Client)SetPriority(id int, priority int) (serverResponse, error) { params.Set("priority", strconv.Itoa(priority)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's rewatch value -func (c Client)SetRewatchValue(id int, rewatchValue int) (serverResponse, error) { +func (c Client)SetRewatchValue(id int, rewatchValue int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified rewatch value is valid if !e.IsValidRewatchValue(rewatchValue) { - return serverResponse{}, e.InvalidRewatchValueError + return UpdateResponse{}, e.InvalidRewatchValueError } // data to be sent to the server @@ -116,11 +116,11 @@ func (c Client)SetRewatchValue(id int, rewatchValue int) (serverResponse, error) params.Set("rewatch_value", strconv.Itoa(rewatchValue)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's rewatch count -func (c Client)SetRewatchCount(id int, rewatchCount int) (serverResponse, error) { +func (c Client)SetRewatchCount(id int, rewatchCount int) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -128,11 +128,11 @@ func (c Client)SetRewatchCount(id int, rewatchCount int) (serverResponse, error) params.Set("num_times_rewatched", strconv.Itoa(rewatchCount)) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's tags -func (c Client)UpdateTags(id int, tags string) (serverResponse, error) { +func (c Client)UpdateTags(id int, tags string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -140,11 +140,11 @@ func (c Client)UpdateTags(id int, tags string) (serverResponse, error) { params.Set("tags", tags) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } // update just an anime's comments -func (c Client)UpdateComments(id int, comments string) (serverResponse, error) { +func (c Client)UpdateComments(id int, comments string) (UpdateResponse, error) { endpoint := endpointGenerator(id) // data to be sent to the server @@ -152,34 +152,34 @@ func (c Client)UpdateComments(id int, comments string) (serverResponse, error) { params.Set("comments", comments) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } /* This will overwrite everything * i won't use it.. but it's pretty flexible * so this will stay here */ // Update/Add an anime to user's anime list -func (c Client)UpdateAnime(id int, data UpdateAnimeData) (serverResponse, error) { +func (c Client)UpdateAnime(id int, data UpdateAnimeData) (UpdateResponse, error) { endpoint := endpointGenerator(id) // checks if specified list status is valid if !e.IsValidListStatus(data.Status) { - return serverResponse{}, e.InvalidStatusError + return UpdateResponse{}, e.InvalidStatusError } // checks if specified score is valid if !e.IsValidScore(data.Score) { - return serverResponse{}, e.InvalidScoreError + return UpdateResponse{}, e.InvalidScoreError } // checks if specified priority is valid if !e.IsValidPriority(data.Priority) { - return serverResponse{}, e.InvalidPriorityError + return UpdateResponse{}, e.InvalidPriorityError } // checks if specified rewatch value is valid if !e.IsValidRewatchValue(data.RewatchValue) { - return serverResponse{}, e.InvalidRereadValueError + return UpdateResponse{}, e.InvalidRereadValueError } params := url.Values{} @@ -197,6 +197,6 @@ func (c Client)UpdateAnime(id int, data UpdateAnimeData) (serverResponse, error) params.Set("comments", data.Comments) // make API request - return c.putRequestHandler(endpoint, params), nil + return c.putRequestHandler(endpoint, params) } |