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 (
4 "encoding/json" 4 "encoding/json"
5 "fmt" 5 "fmt"
6 "os" 6 "os"
7 "path/filepath"
7 "runtime" 8 "runtime"
8 "strconv" 9 "strconv"
9 "strings" 10 "strings"
@@ -99,7 +100,32 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
99 ExitCurd() 100 ExitCurd()
100 } 101 }
101 if anilistSelectedOption.Label == "add_new" { // Todo: Add new anime 102 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)
103 } 129 }
104 userQuery := anilistSelectedOption.Label 130 userQuery := anilistSelectedOption.Label
105 anime.AnilistId, err = strconv.Atoi(anilistSelectedOption.Key) 131 anime.AnilistId, err = strconv.Atoi(anilistSelectedOption.Key)