From e4f90575f920cbd429814dfc27a775c0666bf718 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 24 Feb 2022 20:39:40 +0530 Subject: error fix: refer to commit 58 in main --- user/anime/animelist.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user/anime/animelist.go') diff --git a/user/anime/animelist.go b/user/anime/animelist.go index 6516184..b27efc0 100644 --- a/user/anime/animelist.go +++ b/user/anime/animelist.go @@ -77,7 +77,7 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.An var animes []a.Anime for _, element := range animeListData.Data { a := element.Anime - a.MyListStatus = element.ListStatus + a.ListStatus = element.ListStatus animes = append(animes, a) } -- cgit v1.2.3 From 314d9bf6cad4bebec431a217c23016680c56179b Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 24 Feb 2022 21:40:43 +0530 Subject: moved DefaultListStatus back to each package seperately --- user/anime/animelist.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'user/anime/animelist.go') diff --git a/user/anime/animelist.go b/user/anime/animelist.go index b27efc0..f9ddff5 100644 --- a/user/anime/animelist.go +++ b/user/anime/animelist.go @@ -73,13 +73,13 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.An data := c.requestHandler(endpoint, "GET") json.Unmarshal([]byte(data), &animeListData) - // set MyListStatus for each element and add it to array + // set ListStatus for each element and add it to array var animes []a.Anime for _, element := range animeListData.Data { - a := element.Anime - a.ListStatus = element.ListStatus + anime := element.Anime + anime.ListStatus = element.ListStatus - animes = append(animes, a) + animes = append(animes, anime) } // finally create AnimeList -- cgit v1.2.3 From 10499ad3cf8db85a5c5ebd8112415d17a727c2ec Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 24 Feb 2022 22:05:32 +0530 Subject: added fields support for GetAnimeList --- user/anime/animelist.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'user/anime/animelist.go') diff --git a/user/anime/animelist.go b/user/anime/animelist.go index f9ddff5..f6d9965 100644 --- a/user/anime/animelist.go +++ b/user/anime/animelist.go @@ -23,6 +23,7 @@ import ( "errors" a "github.com/MikunoNaka/MAL2Go/anime" e "github.com/MikunoNaka/MAL2Go/errhandlers" + u "github.com/MikunoNaka/MAL2Go/util" ) const BASE_URL string = "https://api.myanimelist.net/v2" @@ -37,7 +38,7 @@ func (c Client)DeleteAnime(id int) string { } // Get authenticated user's anime list -func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.AnimeList, error){ +func (c Client) GetAnimeList(user, status, sort string, limit, offset int, fields []string) (a.AnimeList, error){ var userAnimeList a.AnimeList // error handling for limit limitErr := e.LimitErrHandler(limit, maxListLimit) @@ -45,6 +46,15 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.An return userAnimeList, limitErr } + // handle all the errors for the fields + fields, err := e.FieldsErrHandler(fields) + if err != nil { + return userAnimeList, err + } + + // append "list_status" field only used by this func. + fields = append(fields, "list_status") + // checks if valid sort is specified if !e.IsValidListSort(sort) { return userAnimeList, errors.New(fmt.Sprintf("GetAnimeList: Invalid sort specified: \"%s\"", sort)) @@ -60,14 +70,26 @@ func (c Client) GetAnimeList(user, status, sort string, limit, offset int) (a.An user = "@me" } - // if status is "" it returns all anime var endpoint string + // if status is "" it returns all anime if status == "" { - endpoint = BASE_URL + "/users/" + user + "/animelist?sort=" + sort + "&limit=" + strconv.Itoa(limit) + "&offset=" + strconv.Itoa(offset) + endpoint, _ = u.UrlGenerator( + BASE_URL + "/users/" + user + "/animelist", + []string{"sort", "limit", "offset", "fields"}, + [][]string{{sort}, {strconv.Itoa(limit)}, {strconv.Itoa(offset)}, fields}, + true, + ) } else { - endpoint = BASE_URL + "/users/" + user + "/animelist?status=" + status + "&sort=" + sort + "&limit=" + strconv.Itoa(limit) + "&offset=" + strconv.Itoa(offset) + // status gets included if specified + endpoint, _ = u.UrlGenerator( + BASE_URL + "/users/" + user + "/animelist", + []string{"status", "sort", "limit", "offset", "fields"}, + [][]string{{status}, {sort}, {strconv.Itoa(limit)}, {strconv.Itoa(offset)}, fields}, + true, + ) } + // get data from API var animeListData AnimeListRaw data := c.requestHandler(endpoint, "GET") -- cgit v1.2.3