expanded go structs to give more info for watch and single anime

This commit is contained in:
John O'Keefe 2024-07-25 09:19:27 -04:00
parent 55c73a84a3
commit 2be45caa21
2 changed files with 257 additions and 84 deletions

View File

@ -35,9 +35,11 @@ func AniListQuery(body interface{}, login bool) (json.RawMessage, string) {
return returnedBody, ""
}
func (a *App) GetAniListItem(aniId int) any {
func (a *App) GetAniListItem(aniId int) AniListGetSingleAnime {
var user = a.GetAniListLoggedInUserId()
type Variables struct {
ID int `json:"id"`
UserId int `json:"userId"`
MediaId int `json:"mediaId"`
ListType string `json:"listType"`
}
body := struct {
@ -45,43 +47,78 @@ func (a *App) GetAniListItem(aniId int) any {
Variables Variables `json:"variables"`
}{
Query: `
query ($id: Int!, $listType: MediaType) {
Media (id: $id, type: $listType) {
query($userId: Int, $mediaId: Int, $listType: MediaType) {
MediaList(mediaId: $mediaId, userId: $userId, type: $listType) {
id
idMal
title {
mediaId
userId
media {
id
idMal
title {
romaji
english
}
description
coverImage {
medium
native
}
description
coverImage {
large
extraLarge
color
}
season
seasonYear
status
episodes
nextAiringEpisode {
airingAt
timeUntilAiring
episode
}
}
tags {
id
name
description
category
rank
isGeneralSpoiler
isMediaSpoiler
isAdult
status
startedAt{
year
month
day
}
completedAt{
year
month
day
}
notes
progress
score
repeat
user {
id
name
avatar {
large
medium
}
statistics {
anime {
count
statuses {
status
count
}
}
}
}
}
}
}
`,
Variables: Variables{
ID: aniId,
MediaId: aniId,
UserId: user.Data.Viewer.ID,
ListType: "ANIME",
},
}
returnedBody, _ := AniListQuery(body, false)
var post interface{}
var post AniListGetSingleAnime
err := json.Unmarshal(returnedBody, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
@ -110,18 +147,28 @@ func (a *App) AniListSearch(query string) any {
perPage
}
media (search: $search, type: $listType) {
id
idMal
title {
romaji
english
}
coverImage {
extraLarge
color
}
id
idMal
title {
romaji
english
native
}
description
coverImage {
large
}
season
seasonYear
status
episodes
nextAiringEpisode{
airingAt
timeUntilAiring
episode
}
}
}
}
}
`,
Variables: Variables{
@ -198,6 +245,16 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
}
}
status
startedAt {
year
month
day
}
completedAt {
year
month
day
}
notes
progress
score
@ -257,3 +314,111 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
return post
}
func (a *App) AniListUpdateEntry(
mediaId int,
progress string,
status string,
score float64,
repeat int,
notes string,
startYear int,
startMonth int,
startDay int,
completeYear int,
completeMonth int,
completeDay int,
) interface{} {
type StartedAt struct {
Year int `json:"year"`
Month int `json:"month"`
Day int `json:"day"`
}
type CompletedAt struct {
Year int `json:"year"`
Month int `json:"month"`
Day int `json:"day"`
}
type Variables struct {
MediaId int `json:"mediaId"`
Progress string `json:"progress"`
Status string `json:"status"`
Score float64 `json:"score"`
Repeat int `json:"repeat"`
Notes string `json:"notes"`
StartedAt StartedAt `json:"startedAt"`
CompletedAt CompletedAt `json:"completedAt"`
}
body := struct {
Mutation string `json:"mutation"`
Variables Variables `json:"variables"`
}{
Mutation: `
mutation(
$mediaId:Int,
$progress:Int,
$status:MediaListStatus,
$score:Float,
$repeat:Int,
$notes:String,
$startedAt:FuzzyDateInput,
$completedAt:FuzzyDateInput,
){
SaveMediaListEntry(
mediaId:$mediaId,
progress:$progress,
status:$status,
score:$score,
repeat:$repeat,
notes:$notes,
startedAt:$startedAt
completedAt:$completedAt
){
mediaId
progress
status
score
repeat
notes
startedAt{
year
month
day
}
completedAt{
year
month
day
}
}
}
`,
Variables: Variables{
MediaId: mediaId,
Progress: progress,
Status: status,
Score: score,
Repeat: repeat,
Notes: notes,
StartedAt: StartedAt{
Year: startYear,
Month: startMonth,
Day: startDay,
},
CompletedAt: CompletedAt{
Year: completeYear,
Month: completeMonth,
Day: completeDay,
},
}}
returnedBody, _ := AniListQuery(body, true)
var post interface{}
err := json.Unmarshal(returnedBody, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
return post
}

View File

@ -26,59 +26,67 @@ type AniListCurrentUserWatchList struct {
LastPage int `json:"lastPage"`
HasNextPage bool `json:"hasNextPage"`
} `json:"pageInfo"`
MediaList []struct {
ID int `json:"id"`
MediaID int `json:"mediaId"`
UserID int `json:"userId"`
Media struct {
ID int `json:"id"`
IDMal int `json:"idMal"`
Title struct {
Romaji string `json:"romaji"`
English string `json:"english"`
Native string `json:"native"`
} `json:"title"`
Description string `json:"description"`
CoverImage struct {
Large string `json:"large"`
} `json:"coverImage"`
Season string `json:"season"`
SeasonYear int `json:"seasonYear"`
Status string `json:"status"`
Episodes int `json:"episodes"`
NextAiringEpisode struct {
AiringAt int `json:"airingAt"`
TimeUntilAiring int `json:"timeUntilAiring"`
Episode int `json:"episode"`
} `json:"nextAiringEpisode"`
} `json:"media"`
Status string `json:"status"`
Notes string `json:"notes"`
Progress int `json:"progress"`
Score int `json:"score"`
Repeat int `json:"repeat"`
User struct {
ID int `json:"id"`
Name string `json:"name"`
Avatar struct {
Large string `json:"large"`
Medium string `json:"medium"`
} `json:"avatar"`
Statistics struct {
Anime struct {
Count int `json:"count"`
Statuses []struct {
Status string `json:"status"`
Count int `json:"count"`
} `json:"statuses"`
} `json:"anime"`
} `json:"statistics"`
} `json:"user"`
} `json:"mediaList"`
MediaList []MediaList `json:"mediaList"`
} `json:"Page"`
} `json:"data"`
}
type AniListGetSingleAnime struct {
Data struct {
MediaList MediaList `json:"MediaList"`
} `json:"data"`
}
type MediaList struct {
ID int `json:"id"`
MediaID int `json:"mediaId"`
UserID int `json:"userId"`
Media struct {
ID int `json:"id"`
IDMal int `json:"idMal"`
Title struct {
Romaji string `json:"romaji"`
English string `json:"english"`
Native string `json:"native"`
} `json:"title"`
Description string `json:"description"`
CoverImage struct {
Large string `json:"large"`
} `json:"coverImage"`
Season string `json:"season"`
SeasonYear int `json:"seasonYear"`
Status string `json:"status"`
Episodes int `json:"episodes"`
NextAiringEpisode struct {
AiringAt int `json:"airingAt"`
TimeUntilAiring int `json:"timeUntilAiring"`
Episode int `json:"episode"`
} `json:"nextAiringEpisode"`
} `json:"media"`
Status string `json:"status"`
Notes string `json:"notes"`
Progress int `json:"progress"`
Score int `json:"score"`
Repeat int `json:"repeat"`
User struct {
ID int `json:"id"`
Name string `json:"name"`
Avatar struct {
Large string `json:"large"`
Medium string `json:"medium"`
} `json:"avatar"`
Statistics struct {
Anime struct {
Count int `json:"count"`
Statuses []struct {
Status string `json:"status"`
Count int `json:"count"`
} `json:"statuses"`
} `json:"anime"`
} `json:"statistics"`
} `json:"user"`
}
var MediaListSort = struct {
MediaId string
MediaIdDesc string