From a835f9b0b8b714a76d8b2f9c49b84f7042ddbd6a Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 31 Jan 2022 10:35:43 +0530 Subject: distributed code among multiple files for simplicity --- anime/validators.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 anime/validators.go (limited to 'anime/validators.go') diff --git a/anime/validators.go b/anime/validators.go new file mode 100644 index 0000000..3f66abe --- /dev/null +++ b/anime/validators.go @@ -0,0 +1,61 @@ +package anime + +// Checks if given rankingType is valid +func isValidRankingType(rankingType string) bool { + switch rankingType { + case + "all", + "airing", + "upcoming", + "tv", + "ova", + "movie", + "special", + "bypopularity", + "favorite": + return true + } + return false +} + +// Checks if given rankingType is valid +func areValidFields(field string) bool { + switch field { + case + "id", + "title", + "main_picture", + "alternative_titles", + "start_date", + "end_date", + "synopsis", + "mean", + "rank", + "popularity", + "num_list_users", + "num_scoring_users", + "nsfw", + "created_at", + "updated_at", + "media_type", + "status", + "genres", + "my_list_status", + "num_episodes", + "start_season", + "broadcast", + "source", + "avarage_episode_duration", + "rating", + "pictures", + "background", + "related_anime", + "related_manga", + "recommendations", + "studios", + "statistics": + return true + } + return false +} + -- cgit v1.2.3 From c4c273888446b4beb215cafc165ecd9365bee357 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 31 Jan 2022 12:00:19 +0530 Subject: added error handling for GetAnimeById --- anime/validators.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'anime/validators.go') diff --git a/anime/validators.go b/anime/validators.go index 3f66abe..4cf4986 100644 --- a/anime/validators.go +++ b/anime/validators.go @@ -12,14 +12,13 @@ func isValidRankingType(rankingType string) bool { "movie", "special", "bypopularity", - "favorite": - return true + "favorite": return true } return false } // Checks if given rankingType is valid -func areValidFields(field string) bool { +func isValidField(field string) bool { switch field { case "id", @@ -45,7 +44,7 @@ func areValidFields(field string) bool { "start_season", "broadcast", "source", - "avarage_episode_duration", + "average_episode_duration", "rating", "pictures", "background", @@ -53,8 +52,7 @@ func areValidFields(field string) bool { "related_manga", "recommendations", "studios", - "statistics": - return true + "statistics": return true } return false } -- cgit v1.2.3 From caa17299f9f70addca805eb94a8174efcdda6985 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 31 Jan 2022 12:06:52 +0530 Subject: Adding copyright declarations to every file --- anime/validators.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'anime/validators.go') diff --git a/anime/validators.go b/anime/validators.go index 4cf4986..416f827 100644 --- a/anime/validators.go +++ b/anime/validators.go @@ -1,3 +1,19 @@ +/* mal2go - MyAnimeList V2 API wrapper for Go + * Copyright (C) 2022 Vidhu Kant Sharma + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + package anime // Checks if given rankingType is valid -- cgit v1.2.3 From f3ec24145da97fa7e4a5687503a6f46d59ff8c2a Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 5 Feb 2022 21:52:30 +0530 Subject: added function to get seasonal anime and added fields support to all the endpoints that have it --- anime/validators.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'anime/validators.go') diff --git a/anime/validators.go b/anime/validators.go index 416f827..7f6a7cc 100644 --- a/anime/validators.go +++ b/anime/validators.go @@ -73,3 +73,24 @@ func isValidField(field string) bool { return false } +// Checks if given season is valid +func isValidSeason(season string) bool { + switch season { + case + "winter", + "spring", + "summer", + "fall": return true + } + return false +} + +// Checks if given sort is valid +func isValidSort(sort string) bool { + switch sort { + case + "anime_score", + "anime_num_list_users": return true + } + return false +} -- cgit v1.2.3