Skip to content

Commit

Permalink
worked on the remove functionality of the alert
Browse files Browse the repository at this point in the history
  • Loading branch information
ibilalkayy committed Apr 25, 2024
1 parent 956458c commit c07a3a7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/budget/sub_handler/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
41 changes: 34 additions & 7 deletions db/alert_db/alert_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion db/budget_db/budget_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion db/budget_db/history_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down

0 comments on commit c07a3a7

Please sign in to comment.