Skip to content

Commit

Permalink
made the alert setup for total amount and the category specific amount
Browse files Browse the repository at this point in the history
  • Loading branch information
ibilalkayy committed Mar 19, 2024
1 parent 244dd3d commit 469f490
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ With a user-friendly CLI. It manages the finances and achieve greater financial

## Documentation

To get to know about the application in detail, you can visit the [docs](https://github.com/ibilalkayy/flow/tree/main/docs) to understand the application in a better way.
To know about the application in detail, you can visit the [docs](https://github.com/ibilalkayy/flow/tree/main/docs) to understand the application in a better way.

## What You Need?

Expand Down
3 changes: 3 additions & 0 deletions cmd/budget/handler/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ var AlertCmd = &cobra.Command{
Use: "alert",
Short: "Get notification once you pass the budget",
Run: func(cmd *cobra.Command, args []string) {
total, _ := cmd.Flags().GetString("total")
category, _ := cmd.Flags().GetString("category")
frequency, _ := cmd.Flags().GetString("frequency")
method, _ := cmd.Flags().GetString("method")

av := structs.AlertVariables{
Total: total,
Category: category,
Frequency: frequency,
Method: method,
Expand All @@ -32,6 +34,7 @@ var AlertCmd = &cobra.Command{

func init() {
AlertCmd.AddCommand(MsgCmd)
AlertCmd.Flags().StringP("total", "t", "", "Write the 'amount' flag value to take the total budget amount")
AlertCmd.Flags().StringP("category", "c", "", "Write the category name to take its budget amount")
AlertCmd.Flags().StringP("frequency", "f", "", "Write the frequency of notifications (e.g., hourly, daily, weekly, monthly)")
AlertCmd.Flags().StringP("method", "m", "", "Write the preferred method of notification [email or CLI] message")
Expand Down
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.30"
const version = "v0.1.31"

// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand Down
43 changes: 33 additions & 10 deletions internal/app/budget/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,26 +317,49 @@ func Method(value string) (string, error) {
}

func AlertSetup(av structs.AlertVariables) error {
if len(av.Category) != 0 && len(av.Frequency) != 0 && len(av.Method) != 0 {
amount, err := CategoryAmount(av.Category)
if err != nil {
return err
if len(av.Frequency) != 0 && len(av.Method) != 0 {
if len(av.Total) != 0 {
budgetAmount, err := TotalBudgetAmount()
if err != nil {
return err
}
totalAmount := strconv.Itoa(budgetAmount)

if len(totalAmount) != 0 && av.Total == "amount" {
fmt.Println("Alert is setup for the total amount")
} else {
return errors.New("total amount is not present or the flag value is not given properly")
}
} else if len(av.Category) != 0 {
categoryAmount, err := CategoryAmount(av.Category)
if err != nil {
return err
}

if len(categoryAmount) != 0 {
fmt.Println("Alert is setup for a specific category")
} else {
return errors.New("category amount is not present")
}
} else {
return errors.New("select a category")
}

frequencyMsg, err := Frequency(av.Frequency)
var err error

_, err = Frequency(av.Frequency)
if err != nil {
return err
}

method, err := Method(av.Method)
_, err = Method(av.Method)
if err != nil {
return err
}

fmt.Println(amount)
fmt.Println(frequencyMsg)
fmt.Println(method)
fmt.Println("Your alart message is setup")
// fmt.Println(frequencyMsg)
// fmt.Println(method)
// fmt.Println("Your alart message is setup")
} else {
return errors.New("enter all the alert values")
}
Expand Down
1 change: 1 addition & 0 deletions internal/structs/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package structs

type AlertVariables struct {
Total string
Category string
Frequency string
Method string
Expand Down

0 comments on commit 469f490

Please sign in to comment.