From 8a998a58e65fa435cdfc0134867a422d26af007f Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 16 Jun 2022 18:32:05 +0530 Subject: removed ListPaging from MAL2Go/anime package --- anime/README.md | 8 ------- anime/anime.go | 53 ++++++++++------------------------------- anime/general.structs.go | 34 -------------------------- anime/ranking.structs.go | 8 ------- anime/search.structs.go | 9 ------- anime/seasonal.structs.go | 8 ++++--- anime/suggestedanime.structs.go | 7 ------ 7 files changed, 18 insertions(+), 109 deletions(-) delete mode 100644 anime/general.structs.go diff --git a/anime/README.md b/anime/README.md index 72c92b7..75a48e8 100644 --- a/anime/README.md +++ b/anime/README.md @@ -56,9 +56,6 @@ fields := []string{ searchResults, err := myClient.SearchAnime(searchString, limit, offset, fields) fmt.Println(searchResults.Animes) // print list of the search results - -// results have page numbers -fmt.Println(searchResults.Paging.NextPage, searchResults.Paging.PrevPage) ``` - ### Getting an anime's info @@ -103,9 +100,6 @@ ranking, err := myClient.GetAnimeRanking(rankingType, limit, offset, fields) for _, anime := range ranking.Animes { fmt.Printf("Title: %s, Rank Number: %d", anime.Title, anime.RankNum) } - -// ranking lists have page numbers -fmt.Println(ranking.Paging.NextPage, ranking.Paging.PrevPage) ``` - ### Get seasonal anime @@ -140,7 +134,6 @@ for _, anime := range seasonalAnime.Animes { } fmt.Println(seaonalAnime.Season) -fmt.Println(seasonalAnime.Paging.NextPage, seasonalAnime.Paging.PrevPage) ``` - ### Get suggested anime @@ -159,7 +152,6 @@ for _, anime := range suggestedAnime.Animes { fmt.Println(anime.Titile) } -fmt.Println(suggestedAnime.Paging.NextPage, suggestedAnime.Paging.PrevPage) ``` ## Structure diff --git a/anime/anime.go b/anime/anime.go index 7e968ea..c6a21e2 100644 --- a/anime/anime.go +++ b/anime/anime.go @@ -30,8 +30,8 @@ const BASE_URL string = "https://api.myanimelist.net/v2/anime" const maxAnimeLimit int = 500 // in MAL documentation this is named Get Anime List -func (c Client) SearchAnime(searchString string, limit, offset int, fields []string) (AnimeSearch, error) { - var searchResults AnimeSearch +func (c Client) SearchAnime(searchString string, limit, offset int, fields []string) ([]Anime, error) { + var searchResults []Anime // error handling for limit limitErr := e.LimitErrHandler(limit, maxAnimeLimit) @@ -59,17 +59,10 @@ func (c Client) SearchAnime(searchString string, limit, offset int, fields []str json.Unmarshal([]byte(data), &animeSearchData) // Adding all the animes to another list to get formatted results later - var animes []Anime - for _, element := range animeSearchData.Data { - animes = append(animes, element.Anime) + for _, element := range animeSearchData.Data { + searchResults = append(searchResults, element.Anime) } - // finally generate AnimeList - searchResults = AnimeSearch { - Animes: animes, - Paging: animeSearchData.Paging, - } - return searchResults, nil } @@ -99,8 +92,8 @@ func (c Client) GetAnimeById(animeId int, fields []string) (Anime, error) { } // Ranking is a list of anime sorted by their rank -func (c Client) GetAnimeRanking(rankingType string, limit, offset int, fields []string) (AnimeRanking, error) { - var animeRanking AnimeRanking +func (c Client) GetAnimeRanking(rankingType string, limit, offset int, fields []string) ([]rAnime, error) { + var animeRanking []rAnime // error handling for limit limitErr := e.LimitErrHandler(limit, maxAnimeLimit) @@ -132,24 +125,12 @@ func (c Client) GetAnimeRanking(rankingType string, limit, offset int, fields [] json.Unmarshal([]byte(data), &rankingData) // Adding all the animes in ranking list to a slice - var animes []rAnime - for _, anime := range rankingData.Data { // set RankNum for anime - newManga := anime.Anime - newManga.RankNum = anime.Ranking.Rank - - // add newManga to list - animes = append(animes, newManga) - } - - // Finally, create the AnimeRanking object - animeRanking = AnimeRanking { - Animes: animes, - Paging: ListPaging { - NextPage: rankingData.Paging.NextPage, - PrevPage: rankingData.Paging.PrevPage, - }, + a := anime.Anime + a.RankNum = anime.Ranking.Rank + // add anime to slice + animeRanking = append(animeRanking, a) } return animeRanking, nil @@ -202,7 +183,6 @@ func (c Client) GetSeasonalAnime(year, season, sort string, limit, offset int, f // finally generate SeasonalAnime seasonalAnime = SeasonalAnime { Animes: animes, - Paging: seasonalAnimeData.Paging, Season: seasonalAnimeData.Season, } @@ -210,8 +190,8 @@ func (c Client) GetSeasonalAnime(year, season, sort string, limit, offset int, f } // get anime suggestions for the user -func (c Client) GetSuggestedAnime(limit, offset int, fields []string) (SuggestedAnime, error){ - var suggestedAnime SuggestedAnime +func (c Client) GetSuggestedAnime(limit, offset int, fields []string) ([]Anime, error){ + var suggestedAnime []Anime // error handling for limit // limit for this is 100 unlike others in the current package @@ -239,15 +219,8 @@ func (c Client) GetSuggestedAnime(limit, offset int, fields []string) (Suggested json.Unmarshal([]byte(data), &suggestedAnimeData) // Adding all the animes to another list to get formatted results later - var animes []Anime for _, element := range suggestedAnimeData.Data { - animes = append(animes, element.Anime) - } - - // finally generate RecommendedAnime struct - suggestedAnime = SuggestedAnime { - Animes: animes, - Paging: suggestedAnimeData.Paging, + suggestedAnime = append(suggestedAnime, element.Anime) } return suggestedAnime, nil diff --git a/anime/general.structs.go b/anime/general.structs.go deleted file mode 100644 index 152eb28..0000000 --- a/anime/general.structs.go +++ /dev/null @@ -1,34 +0,0 @@ -/* 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 - -import ( - "github.com/MikunoNaka/MAL2Go/util" -) - -// contains previous/next page for anime list -type ListPaging util.ListPaging - -type Season struct { - Year int `json:"year"` - Name string `json:"season"` -} - -type AnimeList struct { - Animes []Anime - Paging ListPaging -} diff --git a/anime/ranking.structs.go b/anime/ranking.structs.go index b0d357f..9f238e8 100644 --- a/anime/ranking.structs.go +++ b/anime/ranking.structs.go @@ -30,12 +30,4 @@ type RawRanking struct { Rank int `json:"rank"` } `json:"ranking"` } `json:"data"` - - Paging ListPaging `json:"paging"` -} - -// this is how mal2go returns data -type AnimeRanking struct { - Animes []rAnime - Paging ListPaging } diff --git a/anime/search.structs.go b/anime/search.structs.go index ff79a4b..c18d572 100644 --- a/anime/search.structs.go +++ b/anime/search.structs.go @@ -16,17 +16,8 @@ package anime -// this is how the API returns data (looks horrible) type AnimeSearchRaw struct { Data []struct { Anime Anime `json:"node"` } `json:"data"` - - Paging ListPaging `json:"paging"` -} - -// this is how mal2go returns data -type AnimeSearch struct { - Animes []Anime - Paging ListPaging } diff --git a/anime/seasonal.structs.go b/anime/seasonal.structs.go index af5f96c..cdb2dd9 100644 --- a/anime/seasonal.structs.go +++ b/anime/seasonal.structs.go @@ -21,14 +21,16 @@ type SeasonalAnimeRaw struct { Data []struct { Anime Anime `json:"node"` } `json:"data"` - - Paging ListPaging `json:"paging"` Season Season `json:"season"` } // this is how mal2go returns data type SeasonalAnime struct { Animes []Anime - Paging ListPaging Season Season } + +type Season struct { + Year int `json:"year"` + Name string `json:"season"` +} diff --git a/anime/suggestedanime.structs.go b/anime/suggestedanime.structs.go index 13e5afc..d8517b6 100644 --- a/anime/suggestedanime.structs.go +++ b/anime/suggestedanime.structs.go @@ -21,11 +21,4 @@ type SuggestedAnimeRaw struct { Data []struct { Anime Anime `json:"node"` } `json:"data"` - Paging ListPaging `json:"paging"` -} - -// this is how mal2go returns data -type SuggestedAnime struct { - Animes []Anime - Paging ListPaging } -- cgit v1.2.3