Skip to content

Commit

Permalink
improved the app structure and updated the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ibilalkayy committed Apr 18, 2024
1 parent 86f42fd commit c24420c
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 51 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.79"
const version = "v0.1.80"

// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}
5 changes: 3 additions & 2 deletions cmd/total_amount/handler/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
5 changes: 3 additions & 2 deletions cmd/total_amount/handler/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package total_amount_handler
package total_amount_subhandler

import (
"github.com/ibilalkayy/flow/db/total_amount_db"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package total_amount_handler
package total_amount_subhandler

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package total_amount_handler
package total_amount_subhandler

import (
"fmt"
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package total_amount_handler
package total_amount_subhandler

import (
"github.com/ibilalkayy/flow/db/total_amount_db"
Expand Down
2 changes: 1 addition & 1 deletion cmd/total_amount/total_amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion db/migrations/003_create_total_amount_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
37 changes: 18 additions & 19 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,45 +151,44 @@ 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
- `-i, --include string`: Specify a category to include in the total amount
- `-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**:
- `-a, --amount string`: Write the total amount that you want to update
- `-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]`
- **Usage**: `flow total-amount view [flags]`
- **Available Commands**:
- `amount`: View the total amount
- `categories`: View the categories in total amount
41 changes: 28 additions & 13 deletions docs/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,30 @@
│ │ └── 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
│ │ └── alert_db.go
│ ├── 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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions internal/app/total_amount/total_amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal_total_amount

import (
"errors"
"fmt"

"github.com/ibilalkayy/flow/db"
"github.com/ibilalkayy/flow/db/total_amount_db"
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit c24420c

Please sign in to comment.