aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-24 22:17:51 +0530
committerVidhu Kant Sharma <vidhukant@protonmail.ch>2022-02-24 22:17:51 +0530
commit017df270608e286c8ce85683629d5c2dcf400988 (patch)
treed2fd14f1b186a4a03250e3a10f9660a8e8b7d2ef
parent10499ad3cf8db85a5c5ebd8112415d17a727c2ec (diff)
fixed mutliple bugs in GetMangaList
-rw-r--r--manga/manga.structs.go5
-rw-r--r--user/manga/mangalist.go29
2 files changed, 29 insertions, 5 deletions
diff --git a/manga/manga.structs.go b/manga/manga.structs.go
index 2fb5b29..e863d00 100644
--- a/manga/manga.structs.go
+++ b/manga/manga.structs.go
@@ -62,7 +62,10 @@ type Manga struct {
UpdatedAt string `json:"updated_at"`
MediaType string `json:"media_type"`
Status string `json:"status"`
- ListStatus ListStatus `json:"my_list_status"`
+ /* MyListStatus refers to the authenticated user's info
+ * while ListStatus can be used for other users */
+ MyListStatus ListStatus `json:"my_list_status"`
+ ListStatus ListStatus `json:"list_status"`
NumVolumes int `json:"num_volumes"`
NumChapters int `json:"num_chapters"`
Authors []Author `json:"authors"`
diff --git a/user/manga/mangalist.go b/user/manga/mangalist.go
index 392e844..009a65c 100644
--- a/user/manga/mangalist.go
+++ b/user/manga/mangalist.go
@@ -22,6 +22,7 @@ import (
"fmt"
"errors"
e "github.com/MikunoNaka/MAL2Go/errhandlers"
+ u "github.com/MikunoNaka/MAL2Go/util"
)
const BASE_URL string = "https://api.myanimelist.net/v2"
@@ -36,7 +37,7 @@ func (c Client)DeleteManga(id int) string {
}
// Get authenticated user's manga list
-func (c Client) GetMangaList(user, status, sort string, limit, offset int) (MangaList, error){
+func (c Client) GetMangaList(user, status, sort string, limit, offset int, fields []string) (MangaList, error){
var userMangaList MangaList
// error handling for limit
limitErr := e.LimitErrHandler(limit, maxListLimit)
@@ -44,6 +45,15 @@ func (c Client) GetMangaList(user, status, sort string, limit, offset int) (Mang
return userMangaList, limitErr
}
+ // handle all the errors for the fields
+ fields, err := e.FieldsErrHandler(fields)
+ if err != nil {
+ return userMangaList, err
+ }
+
+ // append "list_status" field only used by this func.
+ fields = append(fields, "list_status")
+
// checks if valid sort is specified
if !e.IsValidMangaListSort(sort) {
return userMangaList, errors.New(fmt.Sprintf("GetMangaList: Invalid sort specified: \"%s\"", sort))
@@ -59,12 +69,23 @@ func (c Client) GetMangaList(user, status, sort string, limit, offset int) (Mang
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 + "/mangalist?sort=" + sort + "&limit=" + strconv.Itoa(limit) + "&offset=" + strconv.Itoa(offset)
+ endpoint, _ = u.UrlGenerator(
+ BASE_URL + "/users/" + user + "/mangalist",
+ []string{"sort", "limit", "offset", "fields"},
+ [][]string{{sort}, {strconv.Itoa(limit)}, {strconv.Itoa(offset)}, fields},
+ true,
+ )
} else {
- endpoint = BASE_URL + "/users/" + user + "/mangalist?status=" + status + "&sort=" + sort + "&limit=" + strconv.Itoa(limit) + "&offset=" + strconv.Itoa(offset)
+ // status gets included if specified
+ endpoint, _ = u.UrlGenerator(
+ BASE_URL + "/users/" + user + "/mangalist",
+ []string{"status", "sort", "limit", "offset", "fields"},
+ [][]string{{status}, {sort}, {strconv.Itoa(limit)}, {strconv.Itoa(offset)}, fields},
+ true,
+ )
}
// get data from API