diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-16 13:43:19 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-06-16 13:43:19 +0530 |
commit | e93a197b6f47ed45e5f2dbe10762d6344a3e32c7 (patch) | |
tree | 7aadb4659b288fa3293360a6804f57c6c2e6c050 | |
parent | 0c4f89f08f4fc557323922db238f73dd05d8f3d1 (diff) |
added delete functionality
-rw-r--r-- | cmd/search.go | 10 | ||||
-rw-r--r-- | mal/delete.go | 40 | ||||
-rw-r--r-- | ui/actions.go | 17 |
3 files changed, 51 insertions, 16 deletions
diff --git a/cmd/search.go b/cmd/search.go index 453f13d..5f97861 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -46,26 +46,20 @@ var searchCmd = &cobra.Command { } func searchManga(searchInput string) { - mangaIsAdded := false if searchInput == "" { searchInput = ui.TextInput("Search Manga: ", "Search can't be blank.") } manga := ui.MangaSearch("Select Manga:", searchInput) - if manga.MyListStatus.Status != "" { - mangaIsAdded = true - } + mangaIsAdded := manga.MyListStatus.Status != "" ui.MangaActionMenu(mangaIsAdded)(manga) } func searchAnime(searchInput string) { - animeIsAdded := false if searchInput == "" { searchInput = ui.TextInput("Search Anime: ", "Search can't be blank.") } anime := ui.AnimeSearch("Select Anime:", searchInput) - if anime.MyListStatus.Status != "" { - animeIsAdded = true - } + animeIsAdded := anime.MyListStatus.Status != "" ui.AnimeActionMenu(animeIsAdded)(anime) } diff --git a/mal/delete.go b/mal/delete.go new file mode 100644 index 0000000..27ffbe6 --- /dev/null +++ b/mal/delete.go @@ -0,0 +1,40 @@ +/* +macli - Unofficial CLI-Based MyAnimeList Client +Copyright © 2022 Vidhu Kant Sharma <vidhukant@vidhukant.xyz> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package mal + +import ( + "fmt" + // "os" + a "github.com/MikunoNaka/MAL2Go/anime" + m "github.com/MikunoNaka/MAL2Go/manga" +) + +func DeleteAnime(anime a.Anime) { + res := userAnimeClient.DeleteAnime(anime.Id) + if res != "200" { + fmt.Println("Error: MyAnimeList Returned " + res + " while deleting " + anime.Title) + } +} + +func DeleteManga(manga m.Manga) { + res := userMangaClient.DeleteManga(manga.Id) + if res != "200" { + fmt.Println("Error: MyAnimeList Returned " + res + " while deleting " + manga.Title) + } +} diff --git a/ui/actions.go b/ui/actions.go index cc9e391..2d2b0f3 100644 --- a/ui/actions.go +++ b/ui/actions.go @@ -25,6 +25,7 @@ import ( p "github.com/manifoldco/promptui" a "github.com/MikunoNaka/MAL2Go/anime" m "github.com/MikunoNaka/MAL2Go/manga" + "github.com/MikunoNaka/macli/mal" ) type AnimeAction struct { @@ -48,16 +49,16 @@ func AnimeActionMenu(animeIsAdded bool) func(a.Anime) { {"Set Episodes", "Set number of episodes watched", EpisodeInput}, // these only temporarily run AnimeStatusMenu // because that functionality doesnt exist yet - {"Set Score", "Set score", AnimeStatusMenu}, - {"Set Re-watching", "Set if re-watching", AnimeStatusMenu}, - {"Set Times Re-watched", "Set number of times re-watched", AnimeStatusMenu}, + // {"Set Score", "Set score", AnimeStatusMenu}, + // {"Set Re-watching", "Set if re-watching", AnimeStatusMenu}, + // {"Set Times Re-watched", "Set number of times re-watched", AnimeStatusMenu}, } // if anime not in list if animeIsAdded { options = append( options, - AnimeAction{"Delete Anime", "Delete Anime From Your MyAnimeList List.", AnimeStatusMenu}, + AnimeAction{"Delete Anime", "Delete Anime From Your MyAnimeList List.", mal.DeleteAnime}, ) } @@ -105,16 +106,16 @@ func MangaActionMenu(mangaIsAdded bool) func(m.Manga) { {"Set Chapters", "Set number of chapters read", ChapterInput}, // these only temporarily run MangaStatusMenu // because that functionality doesnt exist yet - {"Set Score", "Set score", MangaStatusMenu}, - {"Set Re-reading", "Set if re-reading", MangaStatusMenu}, - {"Set Times Re-read", "Set number of times re-read", MangaStatusMenu}, + // {"Set Score", "Set score", MangaStatusMenu}, + // {"Set Re-reading", "Set if re-reading", MangaStatusMenu}, + // {"Set Times Re-read", "Set number of times re-read", MangaStatusMenu}, } // if manga not in list if mangaIsAdded { options = append( options, - MangaAction{"Delete Manga", "Delete Manga From Your MyAnimeList List.", MangaStatusMenu}, + MangaAction{"Delete Manga", "Delete Manga From Your MyAnimeList List.", mal.DeleteManga}, ) } |