Commit 0612f42bde

0612f42bded86421205243a441ce65749442450c

parent: a2df5aa351

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-22 16:51 UTC

Add: Add anime to watching list logic complete

Layout: unified · split

internal/curd.go +27 −1
@@ -4,6 +4,7 @@ import (
44 "encoding/json"
55 "fmt"
66 "os"
7 "path/filepath"
78 "runtime"
89 "strconv"
910 "strings"
@@ -99,7 +100,32 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
99100 ExitCurd()
100101 }
101102 if anilistSelectedOption.Label == "add_new" { // Todo: Add new anime
102 ExitCurd()
103 fmt.Println("Enter the anime name:")
104 var query string
105 fmt.Scanln(&query)
106 animeMap, err := SearchAnimeAnilist(query, user.Token)
107 if err != nil {
108 fmt.Println("Failed to search anime")
109 ExitCurd()
110 }
111 anilistSelectedOption, err = DynamicSelect(animeMap)
112 if err != nil {
113 fmt.Println("No anime available")
114 ExitCurd()
115 }
116 animeID, err := strconv.Atoi(anilistSelectedOption.Key)
117 if err != nil {
118 fmt.Println("Failed to convert anime ID to integer")
119 ExitCurd()
120 }
121 err = AddAnimeToWatchingList(animeID, user.Token)
122 if err != nil {
123 fmt.Println("Failed to add anime to watching list")
124 ExitCurd()
125 }
126 anilistUserData, err := GetUserData(user.Token, user.Id)
127 user.AnimeList = ParseAnimeList(anilistUserData)
128 // animeListMap := GetAnimeMap(user.AnimeList)
103129 }
104130 userQuery := anilistSelectedOption.Label
105131 anime.AnilistId, err = strconv.Atoi(anilistSelectedOption.Key)