From 2c79256de81f06465092ad2a9b94da679e6ec95a Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 30 Jun 2022 17:51:53 +0530 Subject: added episode increment/decrement functionality --- mal/episodes.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'mal') diff --git a/mal/episodes.go b/mal/episodes.go index 255f8b0..c0ac116 100644 --- a/mal/episodes.go +++ b/mal/episodes.go @@ -22,26 +22,36 @@ import ( "fmt" "os" "strconv" + a "github.com/MikunoNaka/MAL2Go/v2/user/anime" + m "github.com/MikunoNaka/MAL2Go/v2/user/manga" ) -func SetEpisodes(animeId int, ep string) { - epValue, err := strconv.Atoi(ep) +func SetEpisodes(animeId, prevValue int, ep string) a.UpdateResponse { + epInt, err := strconv.Atoi(ep) if err != nil { fmt.Println("Error while parsing episode input", err) os.Exit(1) } - sign := ep[0:1] - if sign == "+" || sign == "-" { - fmt.Printf("Cannot increment/decrement watched episodes by %d\n. Currently that doesn't wokr", epValue) - os.Exit(2) + var epValue int + switch ep[0:1] { + case "+", "-": + // works both for increment and decrement + epValue = prevValue + epInt + default: + epValue = epInt } - userAnimeClient.SetWatchedEpisodes(animeId, epValue) + res, err := userAnimeClient.SetWatchedEpisodes(animeId, epValue) + if err != nil { + fmt.Println("MyAnimeList returned error while updating episodes:", err) + os.Exit(1) + } + return res } -func SetChapters(mangaId int, ch string) { +func SetChapters(mangaId, prevValue int, ch string) m.UpdateResponse { chValue, err := strconv.Atoi(ch) if err != nil { fmt.Println("Error while parsing chapter input", err) @@ -54,5 +64,10 @@ func SetChapters(mangaId int, ch string) { os.Exit(2) } - userMangaClient.SetChaptersRead(mangaId, chValue) + res, err := userMangaClient.SetChaptersRead(mangaId, chValue) + if err != nil { + fmt.Println("MyAnimeList returned error while updating chapters:", err) + os.Exit(1) + } + return res } -- cgit v1.2.3