diff --git a/SimklFunctions.go b/SimklFunctions.go index c2fa5d1..75d6ec9 100644 --- a/SimklFunctions.go +++ b/SimklFunctions.go @@ -113,3 +113,50 @@ func (a *App) SimklSyncEpisodes(anime Anime, progress int) interface{} { return success } + +func (a *App) SimklSyncRating(anime Anime, rating int) interface{} { + var url string + var showWithRating = ShowWithRating{ + Title: anime.Show.Title, + Ids: Ids{ + Simkl: anime.Show.Ids.Simkl, + Mal: anime.Show.Ids.Mal, + Anilist: anime.Show.Ids.AniList, + }, + Rating: rating, + } + + var showWithoutRating = ShowWithoutRating{ + Title: anime.Show.Title, + Ids: Ids{ + Simkl: anime.Show.Ids.Simkl, + Mal: anime.Show.Ids.Mal, + Anilist: anime.Show.Ids.AniList, + }, + } + + var shows []interface{} + + if rating > 0 { + shows = append(shows, showWithRating) + url = "https://api.simkl.com/sync/ratings" + } else { + shows = append(shows, showWithoutRating) + url = "https://api.simkl.com/sync/ratings/remove" + } + + simklSync := struct { + Shows []interface{} `json:"shows" ts_type:"shows"` + }{shows} + + respBody := SimklPostHelper(url, simklSync) + + var success interface{} + + err := json.Unmarshal(respBody, &success) + if err != nil { + log.Printf("Failed at unmarshal, %s\n", err) + } + + return success +} diff --git a/SimklTypes.go b/SimklTypes.go index e9dcf3c..c5ab0a5 100644 --- a/SimklTypes.go +++ b/SimklTypes.go @@ -88,3 +88,14 @@ type Ids struct { Mal string `json:"mal" ts_type:"mal"` Anilist string `json:"anilist" ts_type:"anilist"` } + +type ShowWithRating struct { + Title string `json:"title" ts_type:"title"` + Ids `json:"ids" ts_type:"ids"` + Rating int `json:"rating" ts_type:"rating"` +} + +type ShowWithoutRating struct { + Title string `json:"title" ts_type:"title"` + Ids `json:"ids" ts_type:"ids"` +} diff --git a/frontend/src/ChangeDataDialogue.svelte b/frontend/src/ChangeDataDialogue.svelte index f66dc97..e2d9aee 100644 --- a/frontend/src/ChangeDataDialogue.svelte +++ b/frontend/src/ChangeDataDialogue.svelte @@ -14,7 +14,7 @@ import { writable } from 'svelte/store'; import type {SimklAnime} from "./simkl/types/simklTypes"; import { get } from 'svelte/store'; - import {AniListUpdateEntry, SimklSyncEpisodes} from "../wailsjs/go/main/App"; + import {AniListUpdateEntry, SimklSyncEpisodes, SimklSyncRating} from "../wailsjs/go/main/App"; const simklWatch = get(simklWatchList); let isAniListLoggedIn: boolean @@ -211,12 +211,22 @@ console.log(value) }) - if (simklLoggedIn && simklAnime.watched_episodes_count !== values.progress) { - await SimklSyncEpisodes(simklAnime, values.progress).then(value => { - console.log(value) - simklAnime.watched_episodes_count = values.progress - simklWatch.anime[simklAnimeIndex].watched_episodes_count = values.progress - }) + if (simklLoggedIn) { + if (simklAnime.watched_episodes_count !== values.progress) { + await SimklSyncEpisodes(simklAnime, values.progress).then(value => { + console.log(value) + simklAnime.watched_episodes_count = values.progress + simklWatch.anime[simklAnimeIndex].watched_episodes_count = values.progress + }) + } + + if (simklAnime.user_rating !== values.score) { + await SimklSyncRating(simklAnime, values.score).then(value => { + console.log(value) + simklAnime.user_rating = values.score + simklWatch.anime[simklAnimeIndex].user_rating = values.score + }) + } } } diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index f1f3bf2..a20be4f 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -25,3 +25,5 @@ export function SimklGetUserWatchlist():Promise; export function SimklLogin():Promise; export function SimklSyncEpisodes(arg1:main.Anime,arg2:number):Promise; + +export function SimklSyncRating(arg1:main.Anime,arg2:number):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index 6a05b5e..7aed297 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -49,3 +49,7 @@ export function SimklLogin() { export function SimklSyncEpisodes(arg1, arg2) { return window['go']['main']['App']['SimklSyncEpisodes'](arg1, arg2); } + +export function SimklSyncRating(arg1, arg2) { + return window['go']['main']['App']['SimklSyncRating'](arg1, arg2); +}