Skip to content

Commit 44656b1

Browse files
Merge pull request #12 from mist8kengas/develop
[✨] Add command flags to update command
2 parents 5588dbf + e9f5658 commit 44656b1

20 files changed

+148
-78
lines changed

cmd/cmd_add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func handleMediaAdd(cmd *cobra.Command, args []string) {
2424
err = viewmodel.HandleMediaUpdate(
2525
viewmodel.MediaUpdateParams{
2626
IsNewAddition: true,
27-
MediaId: mediaId,
28-
Status: mediaAddStatus,
27+
MediaId: mediaId,
28+
Status: mediaAddStatus,
2929
},
3030
)
3131
if err != nil {

cmd/cmd_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var mediaListCmd = &cobra.Command{
2222
Use: "list",
2323
Short: "List your current anime/manga list",
2424
Aliases: []string{"ls"},
25-
Run: handleLs,
25+
Run: handleLs,
2626
}
2727

2828
func init() {

cmd/cmd_media_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var mediaSearchCmd = &cobra.Command{
8686
Use: "search [query...]",
8787
Short: "Search for anime and manga",
8888
Args: cobra.MinimumNArgs(1),
89-
Run: handleMediaSearch,
89+
Run: handleMediaSearch,
9090
}
9191

9292
func init() {

cmd/cmd_update.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111

1212
// // TODO: Update progress relatively. For example "+2", "-10" etc.,
1313
var progress string
14+
var updateStatus string
15+
var notes string
16+
var scoreString string
1417

1518
// func handleUpdate(mediaId int) {
1619
// CheckIfTokenExists()
@@ -48,15 +51,32 @@ func handleUpdate(cmd *cobra.Command, args []string) {
4851
)
4952
}
5053

51-
err = viewmodel.HandleMediaUpdate(
52-
viewmodel.MediaUpdateParams{
53-
IsNewAddition: false,
54-
MediaId: id,
55-
Progress: progress,
56-
Status: "none",
57-
StartDate: "none",
58-
},
59-
)
54+
var scoreFloat *float64
55+
if scoreString != "" {
56+
rawScoreFloat, err := strconv.ParseFloat(scoreString, 32)
57+
if err != nil {
58+
fmt.Println(ui.ErrorText(err))
59+
return
60+
}
61+
scoreFloat = &rawScoreFloat
62+
}
63+
64+
params := viewmodel.MediaUpdateParams{
65+
IsNewAddition: false,
66+
MediaId: id,
67+
Progress: progress,
68+
Status: updateStatus,
69+
StartDate: "none",
70+
}
71+
// TODO: add a way to differentiate between an
72+
// empty notes value vs. an unset notes value
73+
if notes != "\n" {
74+
params.Notes = notes
75+
}
76+
if scoreFloat != nil {
77+
params.Score = float32(*scoreFloat)
78+
}
79+
err = viewmodel.HandleMediaUpdate(params)
6080

6181
if err != nil {
6282
fmt.Println(ui.ErrorText(err))
@@ -67,15 +87,28 @@ var mediaUpdateCmd = &cobra.Command{
6787
Use: "update [id]",
6888
Short: "Update a list entry",
6989
Args: cobra.MinimumNArgs(1),
70-
Run: handleUpdate,
90+
Run: handleUpdate,
7191
}
7292

7393
func init() {
7494
mediaUpdateCmd.Flags().StringVarP(
7595
&progress,
7696
"progress",
7797
"p",
78-
"0",
98+
"",
7999
"The number of episodes/chapter to update",
80100
)
101+
mediaUpdateCmd.Flags().StringVarP(
102+
&updateStatus, "status", "s", "none", "Status of the media. Can be 'watching/w or reading/r', 'planning/p', 'completed/c', 'dropped/d', 'paused/ps'",
103+
)
104+
mediaUpdateCmd.Flags().StringVarP(
105+
&notes,
106+
"notes",
107+
"n",
108+
"\n",
109+
"Text notes. Note: you can add multiple lines by typing \"\\n\" and wrapping the note in double quotes",
110+
)
111+
mediaUpdateCmd.Flags().StringVarP(
112+
&scoreString, "score", "r", "", "The score of the entry. If your score is in emoji, type 1 for 😞, 2 for 😐 and 3 for 😊",
113+
)
81114
}

internal/api/anilist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ func UpdateMediaEntry(params map[string]any) (*responses.MediaUpdateResponse, er
145145
}
146146

147147
return &responseStruct, nil
148-
}
148+
}

internal/api/mutations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ const mediaEntryUpdateMutation = `mutation(
3737
}
3838
}
3939
}
40-
}`
40+
}`

internal/api/responses/media_list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ type ListCollection struct {
1111
Title struct {
1212
UserPreferred string `json:"userPreferred"`
1313
} `json:"title"`
14-
Chapters *int `json:"chapters"`
15-
Volumes *int `json:"volumes"`
16-
Episodes *int `json:"episodes"`
14+
Chapters *int `json:"chapters"`
15+
Volumes *int `json:"volumes"`
16+
Episodes *int `json:"episodes"`
1717
MediaFormat string `json:"format"`
1818
} `json:"media"`
1919
} `json:"entries"`

internal/api/responses/media_search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ type MediaSearchList struct {
66
UserPreferred string `json:"userPreferred"`
77
} `json:"title"`
88
AverageScore *float64 `json:"averageScore"`
9-
MediaType string `json:"type"`
10-
MediaFormat string `json:"format"`
9+
MediaType string `json:"type"`
10+
MediaFormat string `json:"format"`
1111
}
1212

1313
type MediaSearch struct {

internal/api/responses/media_update_response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ type MediaUpdateResponse struct {
44
Data struct {
55
SaveMediaListEntry struct {
66
Media struct {
7-
Id int `json:"id"`
7+
Id int `json:"id"`
88
Title struct {
99
UserPreferred string `json:"userPreferred"`
1010
} `json:"title"`
1111
} `json:"media"`
1212
} `json:"SaveMediaListEntry"`
1313
} `json:"data"`
14-
}
14+
}

internal/constants.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ package internal
44

55
// Base URL is not gonna get changed for a while.
66
// So, keeping it as constant is not gonna hurt anyone.
7-
const(
8-
API_ENDPOINT = "https://graphql.anilist.co"
9-
AUTH_URL = "https://anilist.co/api/v2/oauth/authorize?client_id=4593&response_type=token"
7+
const (
8+
API_ENDPOINT = "https://graphql.anilist.co"
9+
AUTH_URL = "https://anilist.co/api/v2/oauth/authorize?client_id=4593&response_type=token"
1010
BOLT_BUCKET_NAME = "ChibiConfig"
11-
BOLT_DB_NAME = "chibi_config.db"
11+
BOLT_DB_NAME = "chibi_config.db"
1212
)
1313

14-
type MediaType string
14+
type MediaType string
1515

1616
const (
1717
ANIME MediaType = "ANIME"
1818
MANGA MediaType = "MANGA"
19-
)
19+
)

0 commit comments

Comments
 (0)