Skip to content

Commit

Permalink
wrote a condition in the alert database to see if the data is present…
Browse files Browse the repository at this point in the history
… in the database
  • Loading branch information
ibilalkayy committed May 27, 2024
1 parent 3d3c8e6 commit 453fab6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
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.110"
const version = "v0.1.111"

// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand Down
31 changes: 21 additions & 10 deletions usecases/app/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,37 @@ func (h MyAlert) SendAlert(category string) error {
}

func (h MyAlert) SendNotification(category string) error {
details, err := h.Deps.ManageBudget.ViewBudget(category)
budgetDetails, err := h.Deps.ManageBudget.ViewBudget(category)
if err != nil {
return err
}

budgetAmount, ok1 := details[2].(int)
spentAmount, ok2 := details[3].(int)
alertDetails, err := h.Deps.AlertDB.ViewAlert(category)
if err != nil {
return err
}

if !ok1 || !ok2 {
return errors.New("unable to convert to int")
budgetCategory, ok1 := budgetDetails[1].(string)
budgetAmount, ok2 := budgetDetails[2].(int)
spentAmount, ok3 := budgetDetails[3].(int)
alertCategory, ok4 := alertDetails[1].(string)

if !ok1 || !ok2 || !ok3 || !ok4 {
return errors.New("unable to convert to int or string")
}

if len(category) != 0 {
if spentAmount > budgetAmount {
h.Deps.ManageAlerts.SendAlert(category)
if len(alertCategory) != 0 {
if len(category) != 0 && category == budgetCategory {
if spentAmount > budgetAmount {
h.Deps.ManageAlerts.SendAlert(category)
} else {
fmt.Printf("The '%s' category amount is not exceeded\n", category)
}
} else {
fmt.Printf("The '%s' category amount is not exceeded\n", category)
log.Fatal("Write the correct category. See 'flow budget alert msg -h'")
}
} else {
log.Fatal("Write the category. See 'flow budget alert msg -h'")
log.Fatal("Write the category in the alert. See 'flow budget alert -h'")
}
return nil
}

0 comments on commit 453fab6

Please sign in to comment.