diff --git a/cmd/budget/sub_handler/remove.go b/cmd/budget/sub_handler/remove.go index 9d1b088..d46707d 100644 --- a/cmd/budget/sub_handler/remove.go +++ b/cmd/budget/sub_handler/remove.go @@ -21,5 +21,5 @@ var RemoveCmd = &cobra.Command{ } func init() { - RemoveCmd.Flags().StringP("category", "c", "", "Write the category to remove the alert notification values") + RemoveCmd.Flags().StringP("category", "c", "", "Write the category name to remove its alert notification values") } diff --git a/cmd/root.go b/cmd/root.go index ae7079c..b9560c2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -const version = "v0.1.90" +const version = "v0.1.91" // rootCmd represents the base command when called without any subcommands var RootCmd = &cobra.Command{ diff --git a/db/alert_db/alert_db.go b/db/alert_db/alert_db.go index 93c16ff..238696c 100644 --- a/db/alert_db/alert_db.go +++ b/db/alert_db/alert_db.go @@ -83,24 +83,51 @@ func RemoveAlert(category string) error { if err != nil { return err } + defer db.Close() - query := "DELETE FROM Alert WHERE categories=$1" - remove, err := db.Prepare(query) + data, err := ViewAlert(category) if err != nil { return err } - defer remove.Close() + foundCategory, ok := data[1].(string) + if !ok { + return errors.New("unable to convert data to string") + } + + query := "DELETE FROM Alert" + var args []interface{} if len(category) != 0 { - _, err = remove.Exec(category) - if err != nil { - return err + if len(foundCategory) != 0 { + query += " WHERE categories=$1" + args = append(args, category) + } else { + return errors.New("category is not found") } + } + + remove, err := db.Prepare(query) + if err != nil { + return err + } + defer remove.Close() + + _, err = remove.Exec(args...) + if err != nil { + return err + } + + if len(category) != 0 { fmt.Printf("Alert values of '%s' category is successfully removed", category) } else { - return errors.New("category is not present") + if len(foundCategory) != 0 { + fmt.Printf("Alert data is successfully deleted!") + } else { + return errors.New("no data is found") + } } + return nil } diff --git a/db/budget_db/budget_db.go b/db/budget_db/budget_db.go index ba8c34c..8d752ee 100644 --- a/db/budget_db/budget_db.go +++ b/db/budget_db/budget_db.go @@ -149,7 +149,7 @@ func RemoveBudget(category string) error { if len(foundCategory) != 0 { fmt.Printf("Budget data is successfully deleted!") } else { - return errors.New("no data is present") + return errors.New("no data is found") } } diff --git a/db/budget_db/history_db.go b/db/budget_db/history_db.go index 09ec495..1d4c673 100644 --- a/db/budget_db/history_db.go +++ b/db/budget_db/history_db.go @@ -137,7 +137,7 @@ func RemoveHistory(category string) error { if len(foundCategory) != 0 { fmt.Printf("History data is successfully deleted!") } else { - return errors.New("no data is present") + return errors.New("no data is found") } }