aboutsummaryrefslogtreecommitdiff
path: root/manga
diff options
context:
space:
mode:
Diffstat (limited to 'manga')
-rw-r--r--manga/manga.go48
-rw-r--r--manga/manga.structs.go2
-rw-r--r--manga/ranking.structs.go8
-rw-r--r--manga/search.structs.go8
4 files changed, 13 insertions, 53 deletions
diff --git a/manga/manga.go b/manga/manga.go
index 9105f56..eecf734 100644
--- a/manga/manga.go
+++ b/manga/manga.go
@@ -17,23 +17,20 @@
package manga
import (
- "encoding/json"
- "strconv"
+ "encoding/json"
+ "strconv"
e "github.com/MikunoNaka/MAL2Go/errhandlers"
u "github.com/MikunoNaka/MAL2Go/util"
)
const BASE_URL string = "https://api.myanimelist.net/v2/manga"
-// MAL Might change this
-const maxMangaLimit int = 500
-
// in MAL documentation this is named Get Manga List
-func (c Client) SearchManga(searchString string, limit, offset int, fields []string) (MangaSearch, error) {
- var searchResults MangaSearch
+func (c Client) SearchManga(searchString string, limit, offset int, fields []string) ([]Manga, error) {
+ var searchResults []Manga
// error handling for limit
- limitErr := e.LimitErrHandler(limit, maxMangaLimit)
+ limitErr := e.LimitErrHandler(limit, 100)
if limitErr != nil {
return searchResults, limitErr
}
@@ -57,18 +54,10 @@ func (c Client) SearchManga(searchString string, limit, offset int, fields []str
data := c.requestHandler(endpoint)
json.Unmarshal([]byte(data), &mangaSearchData)
- // Adding all the mangas to another list to get formatted results later
- var mangas []Manga
- for _, element := range mangaSearchData.Data {
- mangas = append(mangas, element.Manga)
+ for _, element := range mangaSearchData.Data {
+ searchResults = append(searchResults, element.Manga)
}
- // finally generate AnimeList
- searchResults = MangaSearch {
- Mangas: mangas,
- Paging: mangaSearchData.Paging,
- }
-
return searchResults, nil
}
@@ -96,11 +85,11 @@ func (c Client) GetMangaById(mangaId int, fields []string) (Manga, error) {
}
// Ranking is a list of manga sorted by their rank
-func (c Client) GetMangaRanking(rankingType string, limit, offset int, fields []string) (MangaRanking, error) {
- var mangaRanking MangaRanking
+func (c Client) GetMangaRanking(rankingType string, limit, offset int, fields []string) ([]rManga, error) {
+ var mangaRanking []rManga
// error handling for limit
- limitErr := e.LimitErrHandler(limit, maxMangaLimit)
+ limitErr := e.LimitErrHandler(limit, 500)
if limitErr != nil {
return mangaRanking, limitErr
}
@@ -129,24 +118,13 @@ func (c Client) GetMangaRanking(rankingType string, limit, offset int, fields []
json.Unmarshal([]byte(data), &rankingData)
// Adding all the mangas in ranking list to a slice
- var mangas []rManga
-
for _, manga := range rankingData.Data {
// set RankNum for manga
- newManga := manga.Manga
- newManga.RankNum = manga.Ranking.Rank
+ m := manga.Manga
+ m.RankNum = manga.Ranking.Rank
// add newManga to list
- mangas = append(mangas, newManga)
- }
-
- // Finally, create the AnimeRanking object
- mangaRanking = MangaRanking {
- Mangas: mangas,
- Paging: ListPaging {
- NextPage: rankingData.Paging.NextPage,
- PrevPage: rankingData.Paging.PrevPage,
- },
+ mangaRanking = append(mangaRanking, m)
}
return mangaRanking, nil
diff --git a/manga/manga.structs.go b/manga/manga.structs.go
index 6c5d570..ed94111 100644
--- a/manga/manga.structs.go
+++ b/manga/manga.structs.go
@@ -20,8 +20,6 @@ import (
"github.com/MikunoNaka/MAL2Go/util"
)
-type ListPaging util.ListPaging
-
type Author struct {
// TODO: add stuff
}
diff --git a/manga/ranking.structs.go b/manga/ranking.structs.go
index 698b68a..c681eaa 100644
--- a/manga/ranking.structs.go
+++ b/manga/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 MangaRanking struct {
- Mangas []rManga
- Paging ListPaging
}
diff --git a/manga/search.structs.go b/manga/search.structs.go
index d2da279..5affc1d 100644
--- a/manga/search.structs.go
+++ b/manga/search.structs.go
@@ -21,12 +21,4 @@ type MangaSearchRaw struct {
Data []struct {
Manga Manga `json:"node"`
} `json:"data"`
-
- Paging ListPaging `json:"paging"`
-}
-
-// this is how mal2go returns data
-type MangaSearch struct {
- Mangas []Manga
- Paging ListPaging
}