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, "" return returnedBody, ""
} }
func (a *App) GetAniListItem(aniId int) any { func (a *App) GetAniListItem(aniId int) AniListGetSingleAnime {
var user = a.GetAniListLoggedInUserId()
type Variables struct { type Variables struct {
ID int `json:"id"` UserId int `json:"userId"`
MediaId int `json:"mediaId"`
ListType string `json:"listType"` ListType string `json:"listType"`
} }
body := struct { body := struct {
@ -45,43 +47,78 @@ func (a *App) GetAniListItem(aniId int) any {
Variables Variables `json:"variables"` Variables Variables `json:"variables"`
}{ }{
Query: ` Query: `
query ($id: Int!, $listType: MediaType) { query($userId: Int, $mediaId: Int, $listType: MediaType) {
Media (id: $id, type: $listType) { MediaList(mediaId: $mediaId, userId: $userId, type: $listType) {
id
mediaId
userId
media {
id id
idMal idMal
title { title {
romaji romaji
english english
native
} }
description description
coverImage { coverImage {
medium
large large
extraLarge
color
} }
tags { season
seasonYear
status
episodes
nextAiringEpisode {
airingAt
timeUntilAiring
episode
}
}
status
startedAt{
year
month
day
}
completedAt{
year
month
day
}
notes
progress
score
repeat
user {
id id
name name
description avatar {
category large
rank medium
isGeneralSpoiler }
isMediaSpoiler statistics {
isAdult anime {
count
statuses {
status
count
}
}
}
} }
} }
} }
`, `,
Variables: Variables{ Variables: Variables{
ID: aniId, MediaId: aniId,
UserId: user.Data.Viewer.ID,
ListType: "ANIME", ListType: "ANIME",
}, },
} }
returnedBody, _ := AniListQuery(body, false) returnedBody, _ := AniListQuery(body, false)
var post interface{} var post AniListGetSingleAnime
err := json.Unmarshal(returnedBody, &post) err := json.Unmarshal(returnedBody, &post)
if err != nil { if err != nil {
log.Printf("Failed at unmarshal, %s\n", err) log.Printf("Failed at unmarshal, %s\n", err)
@ -115,10 +152,20 @@ func (a *App) AniListSearch(query string) any {
title { title {
romaji romaji
english english
native
} }
description
coverImage { coverImage {
extraLarge large
color }
season
seasonYear
status
episodes
nextAiringEpisode{
airingAt
timeUntilAiring
episode
} }
} }
} }
@ -198,6 +245,16 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
} }
} }
status status
startedAt {
year
month
day
}
completedAt {
year
month
day
}
notes notes
progress progress
score score
@ -257,3 +314,111 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
return post 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,7 +26,18 @@ type AniListCurrentUserWatchList struct {
LastPage int `json:"lastPage"` LastPage int `json:"lastPage"`
HasNextPage bool `json:"hasNextPage"` HasNextPage bool `json:"hasNextPage"`
} `json:"pageInfo"` } `json:"pageInfo"`
MediaList []struct { 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"` ID int `json:"id"`
MediaID int `json:"mediaId"` MediaID int `json:"mediaId"`
UserID int `json:"userId"` UserID int `json:"userId"`
@ -74,9 +85,6 @@ type AniListCurrentUserWatchList struct {
} `json:"anime"` } `json:"anime"`
} `json:"statistics"` } `json:"statistics"`
} `json:"user"` } `json:"user"`
} `json:"mediaList"`
} `json:"Page"`
} `json:"data"`
} }
var MediaListSort = struct { var MediaListSort = struct {