Skip to content

Commit

Permalink
added the entities directory in order to improve the structure of the…
Browse files Browse the repository at this point in the history
… code
  • Loading branch information
ibilalkayy committed Apr 28, 2024
1 parent c07a3a7 commit 6fe3fad
Show file tree
Hide file tree
Showing 34 changed files with 153 additions and 147 deletions.
4 changes: 2 additions & 2 deletions cmd/budget/handler/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/ibilalkayy/flow/db/budget_db"
"github.com/ibilalkayy/flow/internal/common/functions"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/spf13/cobra"
)

Expand All @@ -18,7 +18,7 @@ var CreateCmd = &cobra.Command{
amount, _ := cmd.Flags().GetString("amount")
amountInt := functions.StringToInt(amount)

bv := structs.BudgetVariables{Category: category, Amount: amountInt}
bv := entities.BudgetVariables{Category: category, Amount: amountInt}
err := budget_db.CreateBudget(&bv, "db/migrations/")
if err != nil {
log.Fatal(err)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/budget/sub_handler/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

internal_alert "github.com/ibilalkayy/flow/internal/app/alert"
"github.com/ibilalkayy/flow/internal/common/functions"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/spf13/cobra"
)

Expand All @@ -28,7 +28,7 @@ var SetupCmd = &cobra.Command{
minuteInt := functions.StringToInt(minute)
secondInt := functions.StringToInt(second)

av := structs.AlertVariables{
av := entities.AlertVariables{
Category: category,
Method: method,
Frequency: frequency,
Expand Down
4 changes: 2 additions & 2 deletions cmd/budget/sub_handler/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/ibilalkayy/flow/db/alert_db"
"github.com/ibilalkayy/flow/internal/common/functions"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/spf13/cobra"
)

Expand All @@ -28,7 +28,7 @@ var UpdateCmd = &cobra.Command{
minuteInt := functions.StringToInt(minute)
secondInt := functions.StringToInt(second)

av := structs.AlertVariables{
av := entities.AlertVariables{
Category: category,
Method: method,
Frequency: frequency,
Expand Down
8 changes: 4 additions & 4 deletions cmd/init/init.go → cmd/init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ibilalkayy/flow/cmd"
"github.com/ibilalkayy/flow/db"
internal_init "github.com/ibilalkayy/flow/internal/app/init"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -38,13 +38,13 @@ func initApp(cmd *cobra.Command, args []string) {
postgresDBName, _ := cmd.Flags().GetString("dbname")
sslMode, _ := cmd.Flags().GetString("sslmode")

authParams := &structs.AuthVariables{
authParams := &entities.AuthVariables{
Username: username,
Gmail: gmail,
AppPassword: appPassword,
}

dbParams := &structs.DatabaseVariables{
dbParams := &entities.DatabaseVariables{
Host: dbHost,
Port: postgresPort,
User: postgresUser,
Expand All @@ -68,7 +68,7 @@ func initApp(cmd *cobra.Command, args []string) {
}
}

func initializeApplication(authParams *structs.AuthVariables, dbParams *structs.DatabaseVariables) error {
func initializeApplication(authParams *entities.AuthVariables, dbParams *entities.DatabaseVariables) error {
err := internal_init.WriteEnvFile(authParams, dbParams)
if err != nil {
return fmt.Errorf("error writing to .env file: %v", err)
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.91"
const version = "v0.1.92"

// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/total_amount/handler/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/ibilalkayy/flow/db/total_amount_db"
"github.com/ibilalkayy/flow/internal/common/functions"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +20,7 @@ var UpdateCmd = &cobra.Command{
label, _ := cmd.Flags().GetString("label")
totalAmount := functions.StringToInt(amount)

tv := structs.TotalAmountVariables{
tv := entities.TotalAmountVariables{
Included: old_category,
NewCategory: new_category,
TotalAmount: totalAmount,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/total_amount/sub_handler/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"

"github.com/ibilalkayy/flow/db/total_amount_db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/spf13/cobra"
)

Expand All @@ -28,7 +28,7 @@ var ActiveCmd = &cobra.Command{
if status == "active" {
fmt.Println(errors.New("the status is already active"))
} else {
updateStatus := structs.TotalAmountVariables{
updateStatus := entities.TotalAmountVariables{
Status: "Active",
}
total_amount_db.UpdateStatus(&updateStatus)
Expand Down
4 changes: 2 additions & 2 deletions cmd/total_amount/sub_handler/inactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"

"github.com/ibilalkayy/flow/db/total_amount_db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/spf13/cobra"
)

Expand All @@ -28,7 +28,7 @@ var InactiveCmd = &cobra.Command{
if status == "inactive" {
fmt.Println(errors.New("the status is already inactive"))
} else {
updateStatus := structs.TotalAmountVariables{
updateStatus := entities.TotalAmountVariables{
Status: "Inactive",
}
total_amount_db.UpdateStatus(&updateStatus)
Expand Down
8 changes: 4 additions & 4 deletions db/alert_db/alert_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"strings"

"github.com/ibilalkayy/flow/db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/jedib0t/go-pretty/v6/table"
)

func CreateAlert(av *structs.AlertVariables, basePath string) error {
func CreateAlert(av *entities.AlertVariables, basePath string) error {
data, err := db.Table(basePath, "002_create_alert_table.sql", 0)
if err != nil {
return err
Expand All @@ -37,7 +37,7 @@ func CreateAlert(av *structs.AlertVariables, basePath string) error {
}

func ViewAlert(category string) ([9]interface{}, error) {
av := new(structs.AlertVariables)
av := new(entities.AlertVariables)

db, err := db.Connection()
if err != nil {
Expand Down Expand Up @@ -131,7 +131,7 @@ func RemoveAlert(category string) error {
return nil
}

func UpdateAlert(av *structs.AlertVariables) error {
func UpdateAlert(av *entities.AlertVariables) error {
db, err := db.Connection()
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions db/budget_db/budget_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

"github.com/ibilalkayy/flow/db"
"github.com/ibilalkayy/flow/internal/common/functions"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/jedib0t/go-pretty/v6/table"
)

func CreateBudget(bv *structs.BudgetVariables, basePath string) error {
func CreateBudget(bv *entities.BudgetVariables, basePath string) error {
data, err := db.Table(basePath, "001_create_budget_table.sql", 0)
if err != nil {
return err
Expand Down Expand Up @@ -50,7 +50,7 @@ func CreateBudget(bv *structs.BudgetVariables, basePath string) error {

func ViewBudget(category string) ([5]interface{}, error) {
// Create a new instance of BudgetVariables to hold the retrieved data
bv := new(structs.BudgetVariables)
bv := new(entities.BudgetVariables)

// Connect to the database
db, err := db.Connection()
Expand Down Expand Up @@ -262,7 +262,7 @@ func AddBudgetExpenditure(spent int, category string) error {
}

func GetBudgetData(filepath, filename string) error {
bv := new(structs.BudgetVariables)
bv := new(entities.BudgetVariables)
db, err := db.Connection()
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions db/budget_db/history_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

"github.com/ibilalkayy/flow/db"
"github.com/ibilalkayy/flow/internal/common/functions"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/jedib0t/go-pretty/v6/table"
)

func InsertHistory(hv *structs.HistoryVariables, basePath string) error {
func InsertHistory(hv *entities.HistoryVariables, basePath string) error {
data, err := db.Table(basePath, "001_create_budget_table.sql", 1)
if err != nil {
return err
Expand Down Expand Up @@ -50,7 +50,7 @@ func InsertHistory(hv *structs.HistoryVariables, basePath string) error {
}

func ViewHistory(category string) ([2]interface{}, error) {
hv := new(structs.HistoryVariables)
hv := new(entities.HistoryVariables)

db, err := db.Connection()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions db/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"os"
"strings"

"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/ibilalkayy/flow/internal/middleware"
_ "github.com/lib/pq"
)

func Connection() (*sql.DB, error) {
var dv structs.DatabaseVariables
var dv entities.DatabaseVariables

if middleware.LoadEnvVariable("DB_HOST") != "" {
dv = structs.DatabaseVariables{
dv = entities.DatabaseVariables{
Host: middleware.LoadEnvVariable("DB_HOST"),
Port: middleware.LoadEnvVariable("DB_PORT"),
User: middleware.LoadEnvVariable("DB_USER"),
Expand Down
6 changes: 3 additions & 3 deletions db/total_amount_db/total_amount_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"errors"

"github.com/ibilalkayy/flow/db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/jedib0t/go-pretty/v6/table"
)

func InsertTotalAmountCategory(tv *structs.TotalAmountVariables, basepath string) error {
func InsertTotalAmountCategory(tv *entities.TotalAmountVariables, basepath string) error {
data, err := db.Table(basepath, "003_create_total_amount_table.sql", 1)
if err != nil {
return err
Expand All @@ -35,7 +35,7 @@ func InsertTotalAmountCategory(tv *structs.TotalAmountVariables, basepath string
}

func ViewTotalAmountCategory() (string, [][2]string, error) {
tv := new(structs.TotalAmountVariables)
tv := new(entities.TotalAmountVariables)
var values [][2]string

db, err := db.Connection()
Expand Down
10 changes: 5 additions & 5 deletions db/total_amount_db/total_amount_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"fmt"

"github.com/ibilalkayy/flow/db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/jedib0t/go-pretty/v6/table"
)

func InsertTotalAmount(tv *structs.TotalAmountVariables, basepath string) error {
func InsertTotalAmount(tv *entities.TotalAmountVariables, basepath string) error {
data, err := db.Table(basepath, "003_create_total_amount_table.sql", 0)
if err != nil {
return err
Expand All @@ -37,7 +37,7 @@ func InsertTotalAmount(tv *structs.TotalAmountVariables, basepath string) error
}

func ViewTotalAmount() ([5]interface{}, error) {
tv := new(structs.TotalAmountVariables)
tv := new(entities.TotalAmountVariables)

db, err := db.Connection()
if err != nil {
Expand Down Expand Up @@ -118,7 +118,7 @@ func RemoveTotalAmount(category string) error {
return nil
}

func UpdateTotalAmount(tv *structs.TotalAmountVariables) error {
func UpdateTotalAmount(tv *entities.TotalAmountVariables) error {
var query string
var params []interface{}

Expand Down Expand Up @@ -147,7 +147,7 @@ func UpdateTotalAmount(tv *structs.TotalAmountVariables) error {
return nil
}

func UpdateStatus(tv *structs.TotalAmountVariables) error {
func UpdateStatus(tv *entities.TotalAmountVariables) error {
db, err := db.Connection()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"text/template"

"github.com/ibilalkayy/flow/db/budget_db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
"github.com/ibilalkayy/flow/internal/middleware"
"gopkg.in/gomail.v2"
)
Expand Down Expand Up @@ -36,7 +36,7 @@ func SendAlertEmail(category string) error {
return errors.New("unable to convert category and amount to int and string")
}

emailVariables := structs.EmailVariables{
emailVariables := entities.EmailVariables{
Username: myUsername,
Category: categoryName,
CategoryAmount: categoryAmount,
Expand Down
4 changes: 2 additions & 2 deletions internal/app/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/ibilalkayy/flow/db/budget_db"
internal_budget "github.com/ibilalkayy/flow/internal/app/budget"
internal_spending "github.com/ibilalkayy/flow/internal/app/spend"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
)

func AlertSetup(av *structs.AlertVariables) error {
func AlertSetup(av *entities.AlertVariables) error {
if len(av.Category) != 0 && len(av.Frequency) != 0 && len(av.Method) != 0 {
validMethods := map[string]bool{"email": true, "cli": true}
validFrequencies := map[string]bool{"hourly": true, "daily": true, "weekly": true, "monthly": true}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/budget/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"errors"

"github.com/ibilalkayy/flow/db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
)

func CategoryAmount(category string) (int, error) {
bv := new(structs.BudgetVariables)
bv := new(entities.BudgetVariables)

db, err := db.Connection()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"os"

"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
)

func WriteEnvFile(av *structs.AuthVariables, dv *structs.DatabaseVariables) error {
func WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables) error {
f, err := os.Create(".env")
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions internal/app/spend/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"time"

"github.com/ibilalkayy/flow/db/budget_db"
"github.com/ibilalkayy/flow/internal/common/structs"
"github.com/ibilalkayy/flow/internal/entities"
)

func StoreHistory(category string, spending_amount int) error {
currentDate := time.Now().Format("2006-01-02")
currentTime := time.Now().Format("03:04:05 PM")

hv := structs.HistoryVariables{
hv := entities.HistoryVariables{
Date: currentDate,
Time: currentTime,
Category: category,
Expand Down
Loading

0 comments on commit 6fe3fad

Please sign in to comment.