From 9f8014ff00ed67719ee5d19327610afe4d5ac59b Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 15 Sep 2024 07:59:19 -0400 Subject: [PATCH] made SimklWatchList variable more clear as to which watchlist it is --- SimklFunctions.go | 30 +++++++++++++++--------------- SimklTypes.go | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/SimklFunctions.go b/SimklFunctions.go index 9c611ff..69b14fc 100644 --- a/SimklFunctions.go +++ b/SimklFunctions.go @@ -11,7 +11,7 @@ import ( "strconv" ) -var WatchList SimklWatchList +var SimklWatchList SimklWatchListType func SimklHelper(method string, url string, body interface{}) json.RawMessage { reader, _ := json.Marshal(body) @@ -49,7 +49,7 @@ func SimklHelper(method string, url string, body interface{}) json.RawMessage { } -func (a *App) SimklGetUserWatchlist() SimklWatchList { +func (a *App) SimklGetUserWatchlist() SimklWatchListType { method := "GET" url := "https://api.simkl.com/sync/all-items/anime/watching" @@ -68,17 +68,17 @@ func (a *App) SimklGetUserWatchlist() SimklWatchList { if errCheck.Error != "" { a.LogoutSimkl() - return SimklWatchList{} + return SimklWatchListType{} } - var watchlist SimklWatchList + var watchlist SimklWatchListType err = json.Unmarshal(respBody, &watchlist) if err != nil { log.Printf("Failed at unmarshal, %s\n", err) } - WatchList = watchlist + SimklWatchList = watchlist return watchlist } @@ -124,9 +124,9 @@ func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime { log.Printf("Failed at unmarshal, %s\n", err) } - for i, simklAnime := range WatchList.Anime { + for i, simklAnime := range SimklWatchList.Anime { if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl { - WatchList.Anime[i].WatchedEpisodesCount = progress + SimklWatchList.Anime[i].WatchedEpisodesCount = progress } } @@ -179,9 +179,9 @@ func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime { log.Printf("Failed at unmarshal, %s\n", err) } - for i, simklAnime := range WatchList.Anime { + for i, simklAnime := range SimklWatchList.Anime { if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl { - WatchList.Anime[i].UserRating = rating + SimklWatchList.Anime[i].UserRating = rating } } @@ -219,9 +219,9 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime { log.Printf("Failed at unmarshal, %s\n", err) } - for i, simklAnime := range WatchList.Anime { + for i, simklAnime := range SimklWatchList.Anime { if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl { - WatchList.Anime[i].Status = status + SimklWatchList.Anime[i].Status = status } } @@ -233,12 +233,12 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime { func (a *App) SimklSearch(aniListAnime MediaList) SimklAnime { var result SimklAnime - if reflect.DeepEqual(WatchList, SimklWatchList{}) { + if reflect.DeepEqual(SimklWatchList, SimklWatchListType{}) { fmt.Println("Watchlist empty. Calling...") - WatchList = a.SimklGetUserWatchlist() + SimklWatchList = a.SimklGetUserWatchlist() } - for _, anime := range WatchList.Anime { + for _, anime := range SimklWatchList.Anime { id, err := strconv.Atoi(anime.Show.Ids.AniList) if err != nil { fmt.Println("AniList ID does not exist on " + anime.Show.Title) @@ -268,7 +268,7 @@ func (a *App) SimklSearch(aniListAnime MediaList) SimklAnime { log.Printf("Failed at unmarshal, %s\n", err) } - for _, watchListAnime := range WatchList.Anime { + for _, watchListAnime := range SimklWatchList.Anime { id := watchListAnime.Show.Ids.Simkl if id == anime[0].Ids.Simkl { result = watchListAnime diff --git a/SimklTypes.go b/SimklTypes.go index 93ee356..0834f6c 100644 --- a/SimklTypes.go +++ b/SimklTypes.go @@ -26,7 +26,7 @@ type SimklUser struct { } `json:"connections" ts_type:"connections"` } -type SimklWatchList struct { +type SimklWatchListType struct { Anime []SimklAnime `json:"anime" ts_type:"anime"` }