From e3ed5bb2b981165a7cd533d4b9d531c24d632d24 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 19 Aug 2024 08:09:03 -0400 Subject: [PATCH] fixed simkl and anilist syncing bugs --- AniListFunctions.go | 2 +- SimklFunctions.go | 37 +++++- SimklTypes.go | 16 +-- .../AniList/Get Items/AniList Item.bru | 3 +- frontend/src/ChangeDataDialogue.svelte | 123 ++++++++++++------ .../GlobalVariablesAndHelperFunctions.svelte | 35 +++-- frontend/wailsjs/go/main/App.d.ts | 6 +- 7 files changed, 149 insertions(+), 73 deletions(-) diff --git a/AniListFunctions.go b/AniListFunctions.go index fc2468e..4c88520 100644 --- a/AniListFunctions.go +++ b/AniListFunctions.go @@ -138,7 +138,7 @@ func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime { Variables: neededVariables, } - returnedBody, _ := AniListQuery(body, false) + returnedBody, _ := AniListQuery(body, login) var post AniListGetSingleAnime err := json.Unmarshal(returnedBody, &post) diff --git a/SimklFunctions.go b/SimklFunctions.go index 082d33b..c57208f 100644 --- a/SimklFunctions.go +++ b/SimklFunctions.go @@ -83,7 +83,7 @@ func (a *App) SimklGetUserWatchlist() SimklWatchList { return watchlist } -func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) interface{} { +func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) SimklAnime { var episodes []Episode var url string @@ -124,10 +124,18 @@ func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) interface{} { log.Printf("Failed at unmarshal, %s\n", err) } - return success + for i, simklAnime := range WatchList.Anime { + if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl { + WatchList.Anime[i].WatchedEpisodesCount = progress + } + } + + anime.WatchedEpisodesCount = progress + + return anime } -func (a *App) SimklSyncRating(anime SimklAnime, rating int) interface{} { +func (a *App) SimklSyncRating(anime SimklAnime, rating int) SimklAnime { var url string var showWithRating = ShowWithRating{ Title: anime.Show.Title, @@ -171,10 +179,18 @@ func (a *App) SimklSyncRating(anime SimklAnime, rating int) interface{} { log.Printf("Failed at unmarshal, %s\n", err) } - return success + for i, simklAnime := range WatchList.Anime { + if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl { + WatchList.Anime[i].UserRating = rating + } + } + + anime.UserRating = rating + + return anime } -func (a *App) SimklSyncStatus(anime SimklAnime, status string) interface{} { +func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime { url := "https://api.simkl.com/sync/add-to-list" var show = SimklShowStatus{ Title: anime.Show.Title, @@ -203,11 +219,18 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) interface{} { log.Printf("Failed at unmarshal, %s\n", err) } - return success + for i, simklAnime := range WatchList.Anime { + if anime.Show.Ids.Simkl == simklAnime.Show.Ids.Simkl { + WatchList.Anime[i].Status = status + } + } + + anime.Status = status + + return anime } func (a *App) SimklSearch(aniId int) SimklAnime { - fmt.Println(aniId) var result SimklAnime if reflect.DeepEqual(WatchList, SimklWatchList{}) { diff --git a/SimklTypes.go b/SimklTypes.go index 4cb794e..93ee356 100644 --- a/SimklTypes.go +++ b/SimklTypes.go @@ -31,14 +31,14 @@ type SimklWatchList struct { } type SimklAnime struct { - LastWatchedAt string `json:"last_watched_at" ts_type:"last_watched_at"` - Status string `json:"status" ts_type:"status"` - UserRating float64 `json:"user_rating" ts_type:"user_rating"` - LastWatched string `json:"last_watched" ts_type:"last_watched"` - NextToWatch string `json:"next_to_watch" ts_type:"next_to_watch"` - WatchedEpisodesCount int `json:"watched_episodes_count" ts_type:"watched_episodes_count"` - TotalEpisodesCount int `json:"total_episodes_count" ts_type:"total_episodes_count"` - NotAiredEpisodesCount int `json:"not_aired_episodes_count" ts_type:"not_aired_episodes_count"` + LastWatchedAt string `json:"last_watched_at" ts_type:"last_watched_at"` + Status string `json:"status" ts_type:"status"` + UserRating int `json:"user_rating" ts_type:"user_rating"` + LastWatched string `json:"last_watched" ts_type:"last_watched"` + NextToWatch string `json:"next_to_watch" ts_type:"next_to_watch"` + WatchedEpisodesCount int `json:"watched_episodes_count" ts_type:"watched_episodes_count"` + TotalEpisodesCount int `json:"total_episodes_count" ts_type:"total_episodes_count"` + NotAiredEpisodesCount int `json:"not_aired_episodes_count" ts_type:"not_aired_episodes_count"` Show struct { Title string `json:"title" ts_type:"title"` Poster string `json:"poster" ts_type:"poster"` diff --git a/bruno/AniTrack/AniList/Get Items/AniList Item.bru b/bruno/AniTrack/AniList/Get Items/AniList Item.bru index 0d902dc..967138d 100644 --- a/bruno/AniTrack/AniList/Get Items/AniList Item.bru +++ b/bruno/AniTrack/AniList/Get Items/AniList Item.bru @@ -13,6 +13,7 @@ post { headers { Content-Type: "application/json" Accept: "application/json" + Authorization: Bearer {{ANILIST_ACCESS_TOKEN}} } body:graphql { @@ -92,7 +93,7 @@ body:graphql { body:graphql:vars { { "userId": 413504, - "mediaId": 157371, + "mediaId": 110, "listType": "ANIME" } } diff --git a/frontend/src/ChangeDataDialogue.svelte b/frontend/src/ChangeDataDialogue.svelte index 01915cb..0fbae60 100644 --- a/frontend/src/ChangeDataDialogue.svelte +++ b/frontend/src/ChangeDataDialogue.svelte @@ -1,21 +1,20 @@