diff --git a/README.md b/README.md index c69b999..540a03f 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/cmd/budget/handler/alert.go b/cmd/budget/handler/alert.go index 8616450..12af847 100644 --- a/cmd/budget/handler/alert.go +++ b/cmd/budget/handler/alert.go @@ -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, @@ -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") diff --git a/cmd/root.go b/cmd/root.go index a6d2d43..7f454ca 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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{ diff --git a/internal/app/budget/budget.go b/internal/app/budget/budget.go index c79f5fa..909db02 100644 --- a/internal/app/budget/budget.go +++ b/internal/app/budget/budget.go @@ -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") } diff --git a/internal/structs/common.go b/internal/structs/common.go index 72efbe7..af0c96a 100644 --- a/internal/structs/common.go +++ b/internal/structs/common.go @@ -1,6 +1,7 @@ package structs type AlertVariables struct { + Total string Category string Frequency string Method string