Commit b22716db90

b22716db90ca4fd2de009577595a814de05c6114

parent: 533a5bfb3a

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-20 12:29 UTC

Remove: Struct defination removed

Layout: unified · split

internal/anilist.go +10 −49
@@ -11,55 +11,6 @@ import (
1111 "strings"
1212)
1313
14// AniListAnime is the struct for the API response
15type AniListAnime struct {
16 ID int `json:"id"`
17 Title struct {
18 Romaji string `json:"romaji"`
19 English string `json:"english"`
20 Native string `json:"native"`
21 } `json:"title"`
22}
23
24// Page represents the page in AniList response
25type Page struct {
26 Media []AniListAnime `json:"media"`
27}
28
29// ResponseData represents the full response structure
30type ResponseData struct {
31 Page Page `json:"Page"`
32}
33
34// AnimeTitle represents the title in different languages
35type AnimeTitle struct {
36 Romaji string
37 English string
38 Japanese string
39}
40
41type Media struct {
42 Duration int `json:"duration"`
43 Episodes int `json:"episodes"`
44 ID int `json:"id"`
45 Title AnimeTitle `json:"title"`
46}
47
48type Entry struct {
49 Media Media `json:"media"`
50 Progress int `json:"progress"`
51 Score float64 `json:"score"`
52 Status string `json:"status"`
53}
54
55type AnimeList struct {
56 Watching []Entry `json:"watching"`
57 Completed []Entry `json:"completed"`
58 Paused []Entry `json:"paused"`
59 Dropped []Entry `json:"dropped"`
60 Planning []Entry `json:"planning"`
61}
62
6314// FindKeyByValue searches for a key associated with a given value in a map[string]string
6415func FindKeyByValue(m map[string]string, value string) (string, error) {
6516 for key, val := range m {
@@ -571,3 +522,13 @@ func FindAnimeByAnilistID(list AnimeList, idStr string) (*Entry, error) {
571522
572523 return nil, fmt.Errorf("anime with ID %d not found", id) // Return an error if not found
573524}
525
526// FindAnimeByAnilistIDInAnimes searches for an anime by its AniList ID in a slice of Anime
527func FindAnimeByAnilistIDInAnimes(animes []Anime, anilistID int) (*Anime, error) {
528 for i := range animes {
529 if animes[i].AnilistId == anilistID {
530 return &animes[i], nil
531 }
532 }
533 return nil, fmt.Errorf("anime with ID %d not found", anilistID)
534}
\ No newline at end of file