From 46bb6df90f2fe17b2b3e97331ff2bd3671c154c4 Mon Sep 17 00:00:00 2001 From: Simon Headley Date: Sat, 21 Dec 2024 11:41:46 +0200 Subject: [PATCH] Refactoring repo layout --- cmd/accounts/app/account.go | 7 ------- cmd/accounts/app/accounts.go | 7 ++++--- {cmd/accounts/app => pkg/enums}/account_types.go | 2 +- pkg/models/account.go | 9 +++++++++ 4 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 cmd/accounts/app/account.go rename {cmd/accounts/app => pkg/enums}/account_types.go (86%) create mode 100644 pkg/models/account.go diff --git a/cmd/accounts/app/account.go b/cmd/accounts/app/account.go deleted file mode 100644 index 4a898ce..0000000 --- a/cmd/accounts/app/account.go +++ /dev/null @@ -1,7 +0,0 @@ -package app - -type account struct { - AccountID string `json:"accountId"` - AccountType AccountType `json:"accountType"` - Balance float64 `json:"balance"` -} diff --git a/cmd/accounts/app/accounts.go b/cmd/accounts/app/accounts.go index f97297e..e5d2a5b 100644 --- a/cmd/accounts/app/accounts.go +++ b/cmd/accounts/app/accounts.go @@ -2,6 +2,7 @@ package app import ( "encoding/json" + "github.com/KrylixZA/bank-with-dapr/pkg/models" "net/http" dapr "github.com/dapr/go-sdk/client" @@ -32,7 +33,7 @@ func GetAccountsForUser(c *gin.Context) { func CreateAccountForUser(c *gin.Context) { userId := c.Param("userId") - var account account + var account models.Account accounts, err := getAccountsForUser(userId, c) if err != nil { @@ -54,7 +55,7 @@ func CreateAccountForUser(c *gin.Context) { c.IndentedJSON(http.StatusCreated, nil) } -func getAccountsForUser(userId string, c *gin.Context) (accounts []account, err error) { +func getAccountsForUser(userId string, c *gin.Context) (accounts []models.Account, err error) { client, err := dapr.NewClient() if err != nil { return nil, err @@ -74,7 +75,7 @@ func getAccountsForUser(userId string, c *gin.Context) (accounts []account, err return accounts, nil } -func saveAccountsForUser(userId string, accounts []account, c *gin.Context) (err error) { +func saveAccountsForUser(userId string, accounts []models.Account, c *gin.Context) (err error) { client, err := dapr.NewClient() if err != nil { return err diff --git a/cmd/accounts/app/account_types.go b/pkg/enums/account_types.go similarity index 86% rename from cmd/accounts/app/account_types.go rename to pkg/enums/account_types.go index 4f28d0f..c4e9ef8 100644 --- a/cmd/accounts/app/account_types.go +++ b/pkg/enums/account_types.go @@ -1,4 +1,4 @@ -package app +package enums type AccountType int diff --git a/pkg/models/account.go b/pkg/models/account.go new file mode 100644 index 0000000..0c98d34 --- /dev/null +++ b/pkg/models/account.go @@ -0,0 +1,9 @@ +package models + +import "github.com/KrylixZA/bank-with-dapr/pkg/enums" + +type Account struct { + AccountID string `json:"accountId"` + AccountType enums.AccountType `json:"accountType"` + Balance float64 `json:"balance"` +}