Skip to content

Commit

Permalink
re-implemented the interface in a whole project to avoide import cycl…
Browse files Browse the repository at this point in the history
…e and renamed the files properly
  • Loading branch information
ibilalkayy committed May 26, 2024
1 parent db0565d commit e113db5
Show file tree
Hide file tree
Showing 67 changed files with 1,505 additions and 1,172 deletions.
2 changes: 1 addition & 1 deletion .github/funding.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github: ibilalkayy
github: ibilalkayy
buy_me_a_coffee: ibilalkayy
28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM golang:1.22.0-alpine3.19

RUN mkdir -p /app
WORKDIR /app

COPY go.mod /app
COPY go.sum /app

COPY . /app

RUN go mod download

RUN go build -o flow .

FROM golang:1.22.0-alpine3.19

RUN mkdir -p /app
WORKDIR /app

COPY go.mod /app
COPY go.sum /app

COPY . /app

RUN go mod download

RUN go build -o flow .

CMD ["sh", "-c", "./flow && while true; do echo 'App is running'; sleep 10; done"]
89 changes: 54 additions & 35 deletions cmd/budget/handler/create.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
package budget_handler

import (
"log"

conversion "github.com/ibilalkayy/flow/common"
"github.com/ibilalkayy/flow/entities"
"github.com/ibilalkayy/flow/framework_drivers/db/budget_db"
"github.com/spf13/cobra"
)

// createCmd represents the create command
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Create the budget of different categories",
Run: func(cmd *cobra.Command, args []string) {
var c conversion.MyConversion
var m budget_db.MyBudgetDatabase

category, _ := cmd.Flags().GetString("category")
amount, _ := cmd.Flags().GetString("amount")
amountInt := c.StringToInt(amount)

bv := entities.BudgetVariables{Category: category, Amount: amountInt}
err := m.CreateBudget(&bv)
if err != nil {
log.Fatal(err)
}
},
}

func init() {
CreateCmd.Flags().StringP("category", "c", "", "Write the category like groceries, utilities, etc")
CreateCmd.Flags().StringP("amount", "a", "", "Write the total amount for that category")
}
package budget_handler

import (
"log"

conversion "github.com/ibilalkayy/flow/common"
"github.com/ibilalkayy/flow/entities"
"github.com/ibilalkayy/flow/framework/db"
"github.com/ibilalkayy/flow/framework/db/budget_db"
"github.com/ibilalkayy/flow/framework/db/total_amount_db"
"github.com/ibilalkayy/flow/handler"
"github.com/ibilalkayy/flow/interfaces"
"github.com/spf13/cobra"
)

// createCmd represents the create command
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Create the budget of different categories",
Run: func(cmd *cobra.Command, args []string) {
category, _ := cmd.Flags().GetString("category")
amount, _ := cmd.Flags().GetString("amount")

myConnection := &db.MyConnection{}
myBudget := &budget_db.MyBudgetDB{}
myTotalDB := &total_amount_db.MyTotalAmountDB{}
myCommon := &conversion.MyCommon{}
deps := interfaces.Dependencies{
Connect: myConnection,
TotalAmount: myTotalDB,
TotalAmountCategory: myTotalDB,
ManageBudget: myBudget,
Common: myCommon,
}
handle := handler.NewHandler(deps)
myConnection.Handler = handle
myBudget.Handler = handle
myTotalDB.Handler = handle
myCommon.Handler = handle

amountInt := handle.Deps.Common.StringToInt(amount)
bv := entities.BudgetVariables{Category: category, Amount: amountInt}

err := handle.Deps.ManageBudget.CreateBudget(&bv)
if err != nil {
log.Fatal(err)
}
},
}

func init() {
CreateCmd.Flags().StringP("category", "c", "", "Write the category like groceries, utilities, etc")
CreateCmd.Flags().StringP("amount", "a", "", "Write the total amount for that category")
}
73 changes: 45 additions & 28 deletions cmd/budget/handler/get.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
package budget_handler

import (
"log"

"github.com/ibilalkayy/flow/framework_drivers/db/budget_db"
"github.com/spf13/cobra"
)

// GetCmd represents the get command
var GetCmd = &cobra.Command{
Use: "get",
Short: "Get the budget data in CSV",
Run: func(cmd *cobra.Command, args []string) {
filepath, _ := cmd.Flags().GetString("filepath")
filename, _ := cmd.Flags().GetString("filename")
var m budget_db.MyBudgetDatabase
err := m.GetBudgetData(filepath, filename)
if err != nil {
log.Fatal(err)
}
},
}

func init() {
GetCmd.Flags().StringP("filepath", "p", "", "Give the file path to store the data")
GetCmd.Flags().StringP("filename", "n", "", "Give the CSV file name to store the data")
}
package budget_handler

import (
"log"

conversion "github.com/ibilalkayy/flow/common"
"github.com/ibilalkayy/flow/framework/db"
"github.com/ibilalkayy/flow/framework/db/budget_db"
"github.com/ibilalkayy/flow/handler"
"github.com/ibilalkayy/flow/interfaces"
"github.com/spf13/cobra"
)

// GetCmd represents the get command
var GetCmd = &cobra.Command{
Use: "get",
Short: "Get the budget data in CSV",
Run: func(cmd *cobra.Command, args []string) {
filepath, _ := cmd.Flags().GetString("filepath")
filename, _ := cmd.Flags().GetString("filename")

myConnection := &db.MyConnection{}
myBudget := &budget_db.MyBudgetDB{}
myCommon := &conversion.MyCommon{}
deps := interfaces.Dependencies{
Connect: myConnection,
ManageBudget: myBudget,
Common: myCommon,
}
handle := handler.NewHandler(deps)
myConnection.Handler = handle
myBudget.Handler = handle
myCommon.Handler = handle

err := handle.Deps.ManageBudget.GetBudgetData(filepath, filename)
if err != nil {
log.Fatal(err)
}
},
}

func init() {
GetCmd.Flags().StringP("filepath", "p", "", "Give the file path to store the data")
GetCmd.Flags().StringP("filename", "n", "", "Give the CSV file name to store the data")
}
66 changes: 39 additions & 27 deletions cmd/budget/handler/remove.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
package budget_handler

import (
"log"

"github.com/ibilalkayy/flow/framework_drivers/db/budget_db"
"github.com/spf13/cobra"
)

// RemoveCmd represents the remove command
var RemoveCmd = &cobra.Command{
Use: "remove",
Short: "Remove the budget details",
Run: func(cmd *cobra.Command, args []string) {
var m budget_db.MyBudgetDatabase

category, _ := cmd.Flags().GetString("category")
err := m.RemoveBudget(category)
if err != nil {
log.Fatal(err)
}
},
}

func init() {
RemoveCmd.Flags().StringP("category", "c", "", "Write the category name to remove")
}
package budget_handler

import (
"log"

"github.com/ibilalkayy/flow/framework/db"
"github.com/ibilalkayy/flow/framework/db/budget_db"
"github.com/ibilalkayy/flow/handler"
"github.com/ibilalkayy/flow/interfaces"
"github.com/spf13/cobra"
)

// RemoveCmd represents the remove command
var RemoveCmd = &cobra.Command{
Use: "remove",
Short: "Remove the budget details",
Run: func(cmd *cobra.Command, args []string) {
category, _ := cmd.Flags().GetString("category")

myConnection := &db.MyConnection{}
myBudget := &budget_db.MyBudgetDB{}
deps := interfaces.Dependencies{
Connect: myConnection,
ManageBudget: myBudget,
}
handle := handler.NewHandler(deps)
myConnection.Handler = handle
myBudget.Handler = handle

err := handle.Deps.ManageBudget.RemoveBudget(category)
if err != nil {
log.Fatal(err)
}
},
}

func init() {
RemoveCmd.Flags().StringP("category", "c", "", "Write the category name to remove")
}
38 changes: 28 additions & 10 deletions cmd/budget/handler/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import (
"log"

conversion "github.com/ibilalkayy/flow/common"
"github.com/ibilalkayy/flow/framework_drivers/db/budget_db"
"github.com/ibilalkayy/flow/framework/db"
"github.com/ibilalkayy/flow/framework/db/budget_db"
"github.com/ibilalkayy/flow/framework/db/total_amount_db"
"github.com/ibilalkayy/flow/handler"
"github.com/ibilalkayy/flow/interfaces"
"github.com/spf13/cobra"
)

Expand All @@ -14,15 +18,29 @@ var UpdateCmd = &cobra.Command{
Use: "update",
Short: "Update the budget details",
Run: func(cmd *cobra.Command, args []string) {
var c conversion.MyConversion
var m budget_db.MyBudgetDatabase

oldCategory, _ := cmd.Flags().GetString("oldcategory")
newCategory, _ := cmd.Flags().GetString("newcategory")
oldCategory, _ := cmd.Flags().GetString("old-category")
newCategory, _ := cmd.Flags().GetString("new-category")
amount, _ := cmd.Flags().GetString("amount")
newAmount := c.StringToInt(amount)

err := m.UpdateBudget(oldCategory, newCategory, newAmount)
myConnection := &db.MyConnection{}
myCommon := &conversion.MyCommon{}
myBudget := &budget_db.MyBudgetDB{}
myTotalDB := &total_amount_db.MyTotalAmountDB{}
deps := interfaces.Dependencies{
Connect: myConnection,
TotalAmount: myTotalDB,
TotalAmountCategory: myTotalDB,
ManageBudget: myBudget,
Common: myCommon,
}
handle := handler.NewHandler(deps)
myConnection.Handler = handle
myBudget.Handler = handle
myTotalDB.Handler = handle
myCommon.Handler = handle

newAmount := handle.Deps.Common.StringToInt(amount)
err := handle.Deps.ManageBudget.UpdateBudget(oldCategory, newCategory, newAmount)
if err != nil {
log.Fatal(err)
}
Expand All @@ -31,7 +49,7 @@ var UpdateCmd = &cobra.Command{
}

func init() {
UpdateCmd.Flags().StringP("oldcategory", "o", "", "Write the old category name to update")
UpdateCmd.Flags().StringP("newcategory", "n", "", "Write the new category name to allocate")
UpdateCmd.Flags().StringP("old-category", "o", "", "Write the old category name to update")
UpdateCmd.Flags().StringP("new-category", "n", "", "Write the new category name to allocate")
UpdateCmd.Flags().StringP("amount", "a", "", "Write the new amount of the category to update")
}
70 changes: 41 additions & 29 deletions cmd/budget/handler/view.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
package budget_handler

import (
"fmt"
"log"

"github.com/ibilalkayy/flow/framework_drivers/db/budget_db"
"github.com/spf13/cobra"
)

// ViewCmd represents the view command
var ViewCmd = &cobra.Command{
Use: "view",
Short: "View the budget details",
Run: func(cmd *cobra.Command, args []string) {
var m budget_db.MyBudgetDatabase

category, _ := cmd.Flags().GetString("category")
details, err := m.ViewBudget(category)
if err != nil {
log.Fatal(err)
}
fmt.Println(details[0])
},
}

func init() {
ViewCmd.Flags().StringP("category", "c", "", "Write the category name to show the specific details")
}
package budget_handler

import (
"fmt"
"log"

"github.com/ibilalkayy/flow/framework/db"
"github.com/ibilalkayy/flow/framework/db/budget_db"
"github.com/ibilalkayy/flow/handler"
"github.com/ibilalkayy/flow/interfaces"
"github.com/spf13/cobra"
)

// ViewCmd represents the view command
var ViewCmd = &cobra.Command{
Use: "view",
Short: "View the budget details",
Run: func(cmd *cobra.Command, args []string) {
category, _ := cmd.Flags().GetString("category")

myConnection := &db.MyConnection{}
myBudget := &budget_db.MyBudgetDB{}
deps := interfaces.Dependencies{
Connect: myConnection,
ManageBudget: myBudget,
}
handle := handler.NewHandler(deps)
myConnection.Handler = handle
myBudget.Handler = handle

details, err := handle.Deps.ManageBudget.ViewBudget(category)
if err != nil {
log.Fatal(err)
}
fmt.Println(details[0])
},
}

func init() {
ViewCmd.Flags().StringP("category", "c", "", "Write the category name to show the specific details")
}
Loading

0 comments on commit e113db5

Please sign in to comment.