From 7a68abbc9e492934cf4170d5a0ff52a456fe92bd Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 23 Feb 2022 21:04:55 +0530 Subject: added second endpoint: GetMangaById --- manga/manga.go | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/manga/manga.go b/manga/manga.go index dd79db2..2bbc7d4 100644 --- a/manga/manga.go +++ b/manga/manga.go @@ -74,31 +74,28 @@ func (c Client) SearchManga(searchString string, limit, offset int, fields []str return searchResults, nil } -// // Each anime has its own ID on MAL -// func (c Client) GetAnimeById(animeId int, fields []string) (Anime, error) { -// var anime Anime -// -// // handle all the errors for the fields -// fields, err := e.FieldsErrHandler(fields) -// if err != nil { -// return anime, err -// } -// -// endpoint, _ := u.UrlGenerator( -// BASE_URL + "/" + strconv.Itoa(animeId), -// []string{"fields"}, -// /* it seems to still return all fields from the API. -// * this might be an issue with MAL itself -// * TODO: look into this */ -// [][]string{fields}, -// true, -// ) -// -// data := c.requestHandler(endpoint) -// json.Unmarshal([]byte(data), &anime) -// -// return anime, nil -// } +// Each manga has its own ID on MAL +func (c Client) GetMangaById(mangaId int, fields []string) (Manga, error) { + var manga Manga + + // handle all the errors for the fields + fields, err := e.FieldsErrHandler(fields) + if err != nil { + return manga, err + } + + endpoint, _ := u.UrlGenerator( + BASE_URL + "/" + strconv.Itoa(mangaId), + []string{"fields"}, + [][]string{fields}, + true, + ) + + data := c.requestHandler(endpoint) + json.Unmarshal([]byte(data), &manga) + + return manga, nil +} // // Ranking is a list of anime sorted by their rank // func (c Client) GetAnimeRanking(rankingType string, limit, offset int, fields []string) (AnimeRanking, error) { -- cgit v1.2.3