From c24420cf8c3b1d099ff5857905e4e163dc633431 Mon Sep 17 00:00:00 2001 From: Bilal Khan Date: Thu, 18 Apr 2024 13:48:46 +0500 Subject: [PATCH] improved the app structure and updated the documentation --- cmd/root.go | 2 +- cmd/total_amount/handler/{set.go => add.go} | 14 +++---- cmd/total_amount/handler/status.go | 5 ++- cmd/total_amount/handler/view.go | 5 ++- .../{handler => sub_handler}/active.go | 2 +- .../{handler => sub_handler}/amount.go | 2 +- .../{handler => sub_handler}/categories.go | 4 +- .../{handler => sub_handler}/inactive.go | 2 +- cmd/total_amount/total_amount.go | 2 +- .../003_create_total_amount_table.sql | 3 +- docs/commands.md | 37 ++++++++--------- docs/structure.md | 41 +++++++++++++------ internal/app/total_amount/total_amount.go | 3 ++ 13 files changed, 71 insertions(+), 51 deletions(-) rename cmd/total_amount/handler/{set.go => add.go} (67%) rename cmd/total_amount/{handler => sub_handler}/active.go (93%) rename cmd/total_amount/{handler => sub_handler}/amount.go (92%) rename cmd/total_amount/{handler => sub_handler}/categories.go (81%) rename cmd/total_amount/{handler => sub_handler}/inactive.go (93%) diff --git a/cmd/root.go b/cmd/root.go index be31808..f8d31a7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -const version = "v0.1.79" +const version = "v0.1.80" // rootCmd represents the base command when called without any subcommands var RootCmd = &cobra.Command{ diff --git a/cmd/total_amount/handler/set.go b/cmd/total_amount/handler/add.go similarity index 67% rename from cmd/total_amount/handler/set.go rename to cmd/total_amount/handler/add.go index 3c6e048..0ce6381 100644 --- a/cmd/total_amount/handler/set.go +++ b/cmd/total_amount/handler/add.go @@ -8,10 +8,10 @@ import ( "github.com/spf13/cobra" ) -// SetCmd represents the set command -var SetCmd = &cobra.Command{ - Use: "set", - Short: "Set the total amount data", +// AddCmd represents the set command +var AddCmd = &cobra.Command{ + Use: "add", + Short: "Add the total amount data", Run: func(cmd *cobra.Command, args []string) { amount, _ := cmd.Flags().GetString("amount") include_category, _ := cmd.Flags().GetString("include") @@ -26,7 +26,7 @@ var SetCmd = &cobra.Command{ } func init() { - SetCmd.Flags().StringP("amount", "a", "", "Write the total amount that you want to set") - SetCmd.Flags().StringP("include", "i", "", "Specify a category to include in the total amount") - SetCmd.Flags().StringP("label", "l", "", "Provide a label for setting up your total amount. Write label b/w commas") + AddCmd.Flags().StringP("amount", "a", "", "Write the total amount that you want to add") + AddCmd.Flags().StringP("include", "i", "", "Specify a category to include in the total amount") + AddCmd.Flags().StringP("label", "l", "", "Provide a label for setting up your total amount. Write label b/w commas") } diff --git a/cmd/total_amount/handler/status.go b/cmd/total_amount/handler/status.go index c5a4dfd..ab457b9 100644 --- a/cmd/total_amount/handler/status.go +++ b/cmd/total_amount/handler/status.go @@ -3,6 +3,7 @@ package total_amount_handler import ( "fmt" + total_amount_subhandler "github.com/ibilalkayy/flow/cmd/total_amount/sub_handler" "github.com/spf13/cobra" ) @@ -16,6 +17,6 @@ var StatusCmd = &cobra.Command{ } func init() { - StatusCmd.AddCommand(ActiveCmd) - StatusCmd.AddCommand(InactiveCmd) + StatusCmd.AddCommand(total_amount_subhandler.ActiveCmd) + StatusCmd.AddCommand(total_amount_subhandler.InactiveCmd) } diff --git a/cmd/total_amount/handler/view.go b/cmd/total_amount/handler/view.go index 33512da..520997e 100644 --- a/cmd/total_amount/handler/view.go +++ b/cmd/total_amount/handler/view.go @@ -3,6 +3,7 @@ package total_amount_handler import ( "fmt" + total_amount_subhandler "github.com/ibilalkayy/flow/cmd/total_amount/sub_handler" "github.com/spf13/cobra" ) @@ -16,6 +17,6 @@ var ViewCmd = &cobra.Command{ } func init() { - ViewCmd.AddCommand(AmountCmd) - ViewCmd.AddCommand(CategoriesCmd) + ViewCmd.AddCommand(total_amount_subhandler.AmountCmd) + ViewCmd.AddCommand(total_amount_subhandler.CategoriesCmd) } diff --git a/cmd/total_amount/handler/active.go b/cmd/total_amount/sub_handler/active.go similarity index 93% rename from cmd/total_amount/handler/active.go rename to cmd/total_amount/sub_handler/active.go index 2e2a84e..cb733d8 100644 --- a/cmd/total_amount/handler/active.go +++ b/cmd/total_amount/sub_handler/active.go @@ -1,4 +1,4 @@ -package total_amount_handler +package total_amount_subhandler import ( "github.com/ibilalkayy/flow/db/total_amount_db" diff --git a/cmd/total_amount/handler/amount.go b/cmd/total_amount/sub_handler/amount.go similarity index 92% rename from cmd/total_amount/handler/amount.go rename to cmd/total_amount/sub_handler/amount.go index 009ea57..d615b9c 100644 --- a/cmd/total_amount/handler/amount.go +++ b/cmd/total_amount/sub_handler/amount.go @@ -1,4 +1,4 @@ -package total_amount_handler +package total_amount_subhandler import ( "fmt" diff --git a/cmd/total_amount/handler/categories.go b/cmd/total_amount/sub_handler/categories.go similarity index 81% rename from cmd/total_amount/handler/categories.go rename to cmd/total_amount/sub_handler/categories.go index 229c193..5ca514e 100644 --- a/cmd/total_amount/handler/categories.go +++ b/cmd/total_amount/sub_handler/categories.go @@ -1,4 +1,4 @@ -package total_amount_handler +package total_amount_subhandler import ( "fmt" @@ -11,7 +11,7 @@ import ( // CategoriesCmd represents the category command var CategoriesCmd = &cobra.Command{ Use: "categories", - Short: "View the categories included in the total amount", + Short: "View the categories in the total amount", Run: func(cmd *cobra.Command, args []string) { categories, _, err := total_amount_db.ViewTotalAmountCategory() if err != nil { diff --git a/cmd/total_amount/handler/inactive.go b/cmd/total_amount/sub_handler/inactive.go similarity index 93% rename from cmd/total_amount/handler/inactive.go rename to cmd/total_amount/sub_handler/inactive.go index fbda2e6..0c3e03b 100644 --- a/cmd/total_amount/handler/inactive.go +++ b/cmd/total_amount/sub_handler/inactive.go @@ -1,4 +1,4 @@ -package total_amount_handler +package total_amount_subhandler import ( "github.com/ibilalkayy/flow/db/total_amount_db" diff --git a/cmd/total_amount/total_amount.go b/cmd/total_amount/total_amount.go index 494f440..e18b84d 100644 --- a/cmd/total_amount/total_amount.go +++ b/cmd/total_amount/total_amount.go @@ -22,7 +22,7 @@ doing category selection, excluding categories, etc`, func init() { cmd.RootCmd.AddCommand(TotalAmountCmd) // Subcommands - TotalAmountCmd.AddCommand(total_amount_handler.SetCmd) + TotalAmountCmd.AddCommand(total_amount_handler.AddCmd) TotalAmountCmd.AddCommand(total_amount_handler.UpdateCmd) TotalAmountCmd.AddCommand(total_amount_handler.ViewCmd) TotalAmountCmd.AddCommand(total_amount_handler.RemoveCmd) diff --git a/db/migrations/003_create_total_amount_table.sql b/db/migrations/003_create_total_amount_table.sql index f196699..81d4442 100644 --- a/db/migrations/003_create_total_amount_table.sql +++ b/db/migrations/003_create_total_amount_table.sql @@ -8,5 +8,6 @@ CREATE TABLE IF NOT EXISTS TotalAmount ( CREATE TABLE IF NOT EXISTS TotalAmountCategory ( id BIGSERIAL PRIMARY KEY, included_categories VARCHAR(255) NOT NULL, - labels VARCHAR(255) NOT NULL + labels VARCHAR(255) NOT NULL, + UNIQUE(included_categories) ); \ No newline at end of file diff --git a/docs/commands.md b/docs/commands.md index 2a8e74a..0d649de 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -151,26 +151,22 @@ Sure, let's break down each command along with its structure for better understa - **Description**: Manage your total amount. - **Usage**: `flow total-amount [flags]` - **Available Commands**: - - `set`: Set the total amount data + - `add`: Add the total amount data - `remove`: Remove the total amount data + - `status`: Get teh status of the total amount - `update`: Update the total amount data - `view`: View the total amount data -- **Flags**: - - `-a, --active string`: Make the total amount active - - `-h, --help`: help for total-amount - - `-i, --inactive string`: Make the total amount inactive - -### 16. `flow total-amount active` -- **Description**: Make the total amount active. -- **Usage**: `flow total-amount active [flags]` -### 17. `flow total-amount inactive` -- **Description**: Make the total amount inactive. -- **Usage**: `flow total-amount inactive [flags]` +### 16. `flow total-amount status` +- **Description**: Handle the total amount status. +- **Usage**: `flow total-amount status [flags]` +- **Available Commands**: + - `active`: Make the total amount active + - `inactive`: Make the total amount inactive -### 18. `flow total-amount set` -- **Description**: Set the total amount data. -- **Usage**: `flow total-amount set [flags]` +### 17. `flow total-amount add` +- **Description**: Add the total amount data. +- **Usage**: `flow total-amount add [flags]` - **Flags**: - `-a, --amount string`: Write the total amount that you want to set - `-e, --exclude string`: Specify a category to exclude from the total amount @@ -178,7 +174,7 @@ Sure, let's break down each command along with its structure for better understa - `-l, --label string`: Provide a label for setting up your total amount - `-h, --help`: help for set -### 19. `flow total-amount update` +### 18. `flow total-amount update` - **Description**: Update the total amount data. - **Usage**: `flow total-amount update [flags]` - **Flags**: @@ -186,10 +182,13 @@ Sure, let's break down each command along with its structure for better understa - `-l, --label string`: Write the label that you want to update - `-h, --help`: help for set -### 20. `flow total-amount remove` +### 19. `flow total-amount remove` - **Description**: Remove the total amount data. - **Usage**: `flow total-amount remove [flags]` -### 21. `flow total-amount view` +### 20. `flow total-amount view` - **Description**: View the total amount data. -- **Usage**: `flow total-amount view [flags]` \ No newline at end of file +- **Usage**: `flow total-amount view [flags]` +- **Available Commands**: + - `amount`: View the total amount + - `categories`: View the categories in total amount \ No newline at end of file diff --git a/docs/structure.md b/docs/structure.md index 4e1295b..2ff675a 100644 --- a/docs/structure.md +++ b/docs/structure.md @@ -23,13 +23,17 @@ │ │ └── spend.go │ ├── total_amount │ │ ├── total_amount.go - │ │ └── handler + │ │ ├── handler + │ │ │ ├── add.go + │ │ │ ├── remove.go + │ │ │ ├── status.go + │ │ │ ├── update.go + │ │ │ └── view.go + │ │ └── sub_handler │ │ ├── active.go │ │ ├── inactive.go - │ │ ├── remove.go - │ │ ├── set.go - │ │ ├── update.go - │ │ └── view.go + │ │ ├── categories.go + │ │ └── amount.go │ └── root.go ├── db │ ├── alert_db @@ -37,10 +41,12 @@ │ ├── budget_db │ │ └── budget_db.go │ ├── total_amount_db - │ │ └── total_amount_db.go + │ │ ├── total_amount_db.go + │ │ └── total_amount_category.go │ ├── migrations │ │ ├── 001_create_budget_table.sql - │ │ └── 002_create_alert_table.sql + │ │ ├── 002_create_alert_table.sql + │ │ └── 003_create_total_amount_table.sql │ └── connection.go ├── docs │ ├── commands.md @@ -57,9 +63,11 @@ │ │ │ └── budget.go │ │ ├── init │ │ │ └── init.go - │ │ └── spend - │ │ ├── notification.go - │ │ └── spend.go + │ │ ├── spend + │ │ │ ├── notification.go + │ │ │ └── spend.go + │ │ └── total_amount + │ │ └── total_amount.go │ ├── middleware │ │ └── env.go │ └── common @@ -108,13 +116,19 @@ ### Total amount command files - **cmd/total_amount/total_amount.go:** The management of the total amount to set the target. -- **cmd/total_amount/handler/active.go:** Handler for making the total amount status active. -- **cmd/total_amount/handler/inactive.go:** Handler for making the total amount status inactive. +- **cmd/total_amount/handler/add.go:** Handler for adding the total amount. - **cmd/total_amount/handler/remove.go:** Handler for removing the total amount data. -- **cmd/total_amount/handler/set.go:** Handler for setting up the total amount. +- **cmd/total_amount/handler/status.go:** Handler for handling the total amount's status. - **cmd/total_amount/handler/update.go:** Handler for updating the total amount data. - **cmd/total_amount/handler/view.go:** Handler for viewing the total amount data. +### Total amount subcommand files + +- **cmd/total_amount/sub_handler/active.go:** Handler for making the total amount status active. +- **cmd/total_amount/sub_handler/inactive.go:** Handler for making the total amount status inactive. +- **cmd/total_amount/sub_handler/categories.go:** Handler for making the total amount status active. +- **cmd/total_amount/sub_handler/amount.go:** Handler for making the total amount status inactive. + ### Other command files - **cmd/init/init.go:** Flow initialization functionality. @@ -146,6 +160,7 @@ - **internal/app/init/init.go:** Logic for init functionality. - **internal/app/spend/spend.go:** Logic for transaction functionality. - **internal/app/spend/notification.go:** Functions for setting the hourly, daily and more notifications. +- **internal/app/total_amount/total_amount.go:** Logic for handling the total amount data. - **internal/common/functions/functions.go:** Contains functions that are not directly attached to a file structure. - **internal/common/structs/structs.go:** Contains type structures for various functions. - **internal/middleware/env.go:** Environment middleware for handling environment variables. diff --git a/internal/app/total_amount/total_amount.go b/internal/app/total_amount/total_amount.go index 0b90370..45235a6 100644 --- a/internal/app/total_amount/total_amount.go +++ b/internal/app/total_amount/total_amount.go @@ -2,6 +2,7 @@ package internal_total_amount import ( "errors" + "fmt" "github.com/ibilalkayy/flow/db" "github.com/ibilalkayy/flow/db/total_amount_db" @@ -80,6 +81,8 @@ func handleExistingTables(totalAmount int, tav, tacv structs.TotalAmountVariable if err != nil { return err } + fmt.Println("Category and label is successfully included!") + break } } }