From d4edacf9c537da8bf17699eefac77b10ca0f4752 Mon Sep 17 00:00:00 2001 From: "HOANGTV\\duchi" Date: Thu, 25 Jan 2024 09:31:05 +0700 Subject: [PATCH] [sprint-1][EA-3] category: get total product --- api/base.go | 2 +- api/controllers/auth.go | 6 +- api/controllers/budget.go | 2 +- api/controllers/cashbook.go | 2 +- api/controllers/cashbook_category.go | 2 +- api/controllers/category.go | 2 +- api/controllers/category_product.go | 75 +++++++++++++++++ api/controllers/customer.go | 2 +- api/controllers/employee_management.go | 2 +- api/controllers/module.go | 2 +- api/controllers/order.go | 4 +- api/controllers/product.go | 2 +- api/controllers/promote.go | 2 +- api/controllers/store.go | 2 +- api/controllers/wallet.go | 2 +- {dto => api/dto}/auth/jwt.go | 0 {dto => api/dto}/auth/login.go | 0 {dto => api/dto}/auth/register.go | 0 {dto => api/dto}/erp/category.go | 0 {dto => api/dto}/erp/category_product.go | 6 +- {dto => api/dto}/erp/customer.go | 0 {dto => api/dto}/erp/employee_management.go | 0 {dto => api/dto}/erp/order.go | 0 {dto => api/dto}/erp/product.go | 0 {dto => api/dto}/erp/promote.go | 0 {dto => api/dto}/erp/store.go | 0 {dto => api/dto}/finance/budget.go | 4 +- {dto => api/dto}/finance/cashbook.go | 0 {dto => api/dto}/finance/cashbook_category.go | 0 {dto => api/dto}/finance/wallet.go | 0 api/middlewares/auth.go | 16 ++-- {models => domain}/base.go | 2 +- {models => domain}/budget.go | 2 +- {models => domain}/category.go | 9 +-- {models => domain}/category_product.go | 2 +- {models => domain}/customer.go | 2 +- {models => domain}/debt.go | 2 +- {models => domain}/order.go | 2 +- {models => domain}/order_item.go | 2 +- {models => domain}/permission.go | 2 +- {models => domain}/product.go | 2 +- {models => domain}/promote.go | 2 +- {models => domain}/role.go | 2 +- {models => domain}/store.go | 2 +- {models => domain}/transaction.go | 2 +- {models => domain}/transaction_category.go | 2 +- {models => domain}/user.go | 2 +- {models => domain}/user_role.go | 2 +- {models => domain}/wallet.go | 2 +- infrastructure/db.go | 14 ++-- repository/budget.go | 26 +++--- repository/cashbook.go | 48 +++++------ repository/cashbook_category.go | 26 +++--- repository/erp_cat_pro.go | 4 +- repository/erp_category.go | 12 ++- repository/erp_customer.go | 26 +++--- repository/erp_permission.go | 10 +-- repository/erp_product.go | 4 +- repository/erp_role.go | 52 ++++++------ repository/erp_store.go | 28 +++---- repository/order.go | 38 ++++----- repository/order_item.go | 12 +-- repository/promote.go | 28 +++---- repository/user.go | 4 +- repository/wallet.go | 34 ++++---- route/route.go | 31 ++++--- service/auth.go | 20 ++--- service/budget.go | 22 ++--- service/cashbook.go | 30 +++---- service/category.go | 4 +- service/category_product.go | 10 +-- service/customer.go | 26 +++--- service/employee_management.go | 8 +- service/jwt.go | 4 +- service/order.go | 80 +++++++++---------- service/order_item.go | 14 ++-- service/product.go | 4 +- service/promote.go | 22 ++--- service/store.go | 22 ++--- service/transaction_category.go | 22 ++--- service/user.go | 2 +- service/wallet.go | 24 +++--- test/permission_test.go | 6 +- {api_errors => utils/api_errors}/errors.go | 0 utils/http.go | 2 +- 85 files changed, 491 insertions(+), 406 deletions(-) create mode 100644 api/controllers/category_product.go rename {dto => api/dto}/auth/jwt.go (100%) rename {dto => api/dto}/auth/login.go (100%) rename {dto => api/dto}/auth/register.go (100%) rename {dto => api/dto}/erp/category.go (100%) rename {dto => api/dto}/erp/category_product.go (75%) rename {dto => api/dto}/erp/customer.go (100%) rename {dto => api/dto}/erp/employee_management.go (100%) rename {dto => api/dto}/erp/order.go (100%) rename {dto => api/dto}/erp/product.go (100%) rename {dto => api/dto}/erp/promote.go (100%) rename {dto => api/dto}/erp/store.go (100%) rename {dto => api/dto}/finance/budget.go (97%) rename {dto => api/dto}/finance/cashbook.go (100%) rename {dto => api/dto}/finance/cashbook_category.go (100%) rename {dto => api/dto}/finance/wallet.go (100%) rename {models => domain}/base.go (98%) rename {models => domain}/budget.go (97%) rename {models => domain}/category.go (59%) rename {models => domain}/category_product.go (96%) rename {models => domain}/customer.go (98%) rename {models => domain}/debt.go (95%) rename {models => domain}/order.go (98%) rename {models => domain}/order_item.go (95%) rename {models => domain}/permission.go (96%) rename {models => domain}/product.go (98%) rename {models => domain}/promote.go (98%) rename {models => domain}/role.go (96%) rename {models => domain}/store.go (97%) rename {models => domain}/transaction.go (98%) rename {models => domain}/transaction_category.go (95%) rename {models => domain}/user.go (97%) rename {models => domain}/user_role.go (98%) rename {models => domain}/wallet.go (95%) rename {api_errors => utils/api_errors}/errors.go (100%) diff --git a/api/base.go b/api/base.go index 693079c..0317110 100644 --- a/api/base.go +++ b/api/base.go @@ -3,8 +3,8 @@ package api import ( "erp/api/request" "erp/api/response" - "erp/api_errors" "erp/utils" + "erp/utils/api_errors" "net/http" "github.com/pkg/errors" diff --git a/api/controllers/auth.go b/api/controllers/auth.go index b8db106..f94f668 100644 --- a/api/controllers/auth.go +++ b/api/controllers/auth.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - dto "erp/dto/auth" + dto2 "erp/api/dto/auth" service "erp/service" "net/http" @@ -25,7 +25,7 @@ func NewAuthController(authService service.AuthService, logger *zap.Logger) *Aut } func (b *AuthController) Register(c *gin.Context) { - var req dto.RegisterRequest + var req dto2.RegisterRequest if err := c.ShouldBindJSON(&req); err != nil { b.ResponseValidationError(c, err) @@ -42,7 +42,7 @@ func (b *AuthController) Register(c *gin.Context) { } func (b *AuthController) Login(c *gin.Context) { - var req dto.LoginRequest + var req dto2.LoginRequest if err := c.ShouldBindJSON(&req); err != nil { b.ResponseValidationError(c, err) diff --git a/api/controllers/budget.go b/api/controllers/budget.go index 02a757a..fa956cc 100644 --- a/api/controllers/budget.go +++ b/api/controllers/budget.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" erpservice "erp/service" "erp/utils" "net/http" diff --git a/api/controllers/cashbook.go b/api/controllers/cashbook.go index 9b8513a..593bb98 100644 --- a/api/controllers/cashbook.go +++ b/api/controllers/cashbook.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" erpservice "erp/service" "erp/utils" "net/http" diff --git a/api/controllers/cashbook_category.go b/api/controllers/cashbook_category.go index 492863c..edea9ea 100644 --- a/api/controllers/cashbook_category.go +++ b/api/controllers/cashbook_category.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" erpservice "erp/service" "erp/utils" "net/http" diff --git a/api/controllers/category.go b/api/controllers/category.go index 64aa6bd..ee360e8 100644 --- a/api/controllers/category.go +++ b/api/controllers/category.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - "erp/dto/erp" + "erp/api/dto/erp" "erp/service" "erp/utils" "github.com/gin-gonic/gin" diff --git a/api/controllers/category_product.go b/api/controllers/category_product.go new file mode 100644 index 0000000..c8d9fd6 --- /dev/null +++ b/api/controllers/category_product.go @@ -0,0 +1,75 @@ +package controller + +import ( + "erp/api" + "erp/api/dto/erp" + "erp/service" + "erp/utils" + "github.com/gin-gonic/gin" + "net/http" +) + +type CategoryProductController struct { + categoryProductService service.CategoryProductService + api.BaseController +} + +func NewCategoryProductController(categoryProductService service.CategoryProductService) *CategoryProductController { + return &CategoryProductController{ + categoryProductService: categoryProductService, + } +} + +func (b *CategoryProductController) Create(c *gin.Context) { + var req erpdto.CategoryProductRequest + if err := c.ShouldBindJSON(&req); err != nil { + b.ResponseValidationError(c, err) + return + } + + res, err := b.categoryProductService.Create(c, req) + if err != nil { + b.ResponseError(c, err) + return + } + b.Response(c, http.StatusOK, "success", res) +} + +func (b *CategoryProductController) Update(c *gin.Context) { + var req erpdto.CategoryProductRequest + + if err := c.ShouldBindJSON(&req); err != nil { + b.ResponseValidationError(c, err) + return + } + res, err := b.categoryProductService.Update(c, req) + if err != nil { + b.ResponseError(c, err) + return + } + b.Response(c, http.StatusOK, "success", res) +} + +func (b *CategoryProductController) Delete(c *gin.Context) { + id := utils.ParseStringIDFromUri(c) + if err := b.categoryProductService.Delete(c, id); err != nil { + b.ResponseError(c, err) + return + } + b.Response(c, http.StatusOK, "success", nil) +} + +func (b *CategoryProductController) GetList(c *gin.Context) { + var req erpdto.GetListCatProRequest + + if err := c.ShouldBindQuery(&req); err != nil { + b.ResponseValidationError(c, err) + return + } + res, total, err := b.categoryProductService.GetList(c, req) + if err != nil { + b.ResponseError(c, err) + return + } + b.ResponseList(c, "success", total, res) +} diff --git a/api/controllers/customer.go b/api/controllers/customer.go index b727f13..0ef9c56 100644 --- a/api/controllers/customer.go +++ b/api/controllers/customer.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/erp" + "erp/api/dto/erp" erpservice "erp/service" "erp/utils" "github.com/gin-gonic/gin" diff --git a/api/controllers/employee_management.go b/api/controllers/employee_management.go index 053207d..41d35c6 100644 --- a/api/controllers/employee_management.go +++ b/api/controllers/employee_management.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/erp" + "erp/api/dto/erp" "erp/lib" erpservice "erp/service" "net/http" diff --git a/api/controllers/module.go b/api/controllers/module.go index 1186679..70d5e4d 100644 --- a/api/controllers/module.go +++ b/api/controllers/module.go @@ -10,5 +10,5 @@ var Module = fx.Options( NewERPCategoryController, NewERPCustomerController, NewERPEmployeeManagementController, NewERPProductController, NewERPStoreController, NewOrderController, NewPromoteController, NewCashbookController, NewTransactionCategoryController, NewWalletController, - NewBudgetController, + NewBudgetController, NewCategoryProductController, )) diff --git a/api/controllers/order.go b/api/controllers/order.go index e723239..d860ee7 100644 --- a/api/controllers/order.go +++ b/api/controllers/order.go @@ -2,10 +2,10 @@ package controller import ( "erp/api" - "erp/api_errors" - erpdto "erp/dto/erp" + "erp/api/dto/erp" erpservice "erp/service" "erp/utils" + "erp/utils/api_errors" "errors" "github.com/gin-gonic/gin" diff --git a/api/controllers/product.go b/api/controllers/product.go index 3cf15e8..57e40b7 100644 --- a/api/controllers/product.go +++ b/api/controllers/product.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/erp" + "erp/api/dto/erp" "erp/service" "erp/utils" "github.com/gin-gonic/gin" diff --git a/api/controllers/promote.go b/api/controllers/promote.go index 996305e..714f7a1 100644 --- a/api/controllers/promote.go +++ b/api/controllers/promote.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/erp" + "erp/api/dto/erp" "erp/service" "erp/utils" "github.com/gin-gonic/gin" diff --git a/api/controllers/store.go b/api/controllers/store.go index dada23c..5e3fb25 100644 --- a/api/controllers/store.go +++ b/api/controllers/store.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/erp" + "erp/api/dto/erp" erpservice "erp/service" "erp/utils" "net/http" diff --git a/api/controllers/wallet.go b/api/controllers/wallet.go index 73324e2..604318c 100644 --- a/api/controllers/wallet.go +++ b/api/controllers/wallet.go @@ -2,7 +2,7 @@ package controller import ( "erp/api" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" erpservice "erp/service" "erp/utils" "net/http" diff --git a/dto/auth/jwt.go b/api/dto/auth/jwt.go similarity index 100% rename from dto/auth/jwt.go rename to api/dto/auth/jwt.go diff --git a/dto/auth/login.go b/api/dto/auth/login.go similarity index 100% rename from dto/auth/login.go rename to api/dto/auth/login.go diff --git a/dto/auth/register.go b/api/dto/auth/register.go similarity index 100% rename from dto/auth/register.go rename to api/dto/auth/register.go diff --git a/dto/erp/category.go b/api/dto/erp/category.go similarity index 100% rename from dto/erp/category.go rename to api/dto/erp/category.go diff --git a/dto/erp/category_product.go b/api/dto/erp/category_product.go similarity index 75% rename from dto/erp/category_product.go rename to api/dto/erp/category_product.go index 1d0a10a..349c813 100644 --- a/dto/erp/category_product.go +++ b/api/dto/erp/category_product.go @@ -6,7 +6,7 @@ import ( ) type CategoryProductRequest struct { - UserId string `json:"user_id" binding:"required"` + //UserId string `json:"user_id" binding:"required"` CategoryId string `json:"category_id" binding:"required"` ProductId string `json:"product_id" binding:"required"` } @@ -21,6 +21,6 @@ type CatProductResponse struct { } type DeleteCatagoryProductRequest struct { - UserId string `json:"user_id" binding:"required"` - ID string `json:"id" binding:"required"` + //UserId string `json:"user_id" binding:"required"` + ID string `json:"id" binding:"required"` } diff --git a/dto/erp/customer.go b/api/dto/erp/customer.go similarity index 100% rename from dto/erp/customer.go rename to api/dto/erp/customer.go diff --git a/dto/erp/employee_management.go b/api/dto/erp/employee_management.go similarity index 100% rename from dto/erp/employee_management.go rename to api/dto/erp/employee_management.go diff --git a/dto/erp/order.go b/api/dto/erp/order.go similarity index 100% rename from dto/erp/order.go rename to api/dto/erp/order.go diff --git a/dto/erp/product.go b/api/dto/erp/product.go similarity index 100% rename from dto/erp/product.go rename to api/dto/erp/product.go diff --git a/dto/erp/promote.go b/api/dto/erp/promote.go similarity index 100% rename from dto/erp/promote.go rename to api/dto/erp/promote.go diff --git a/dto/erp/store.go b/api/dto/erp/store.go similarity index 100% rename from dto/erp/store.go rename to api/dto/erp/store.go diff --git a/dto/finance/budget.go b/api/dto/finance/budget.go similarity index 97% rename from dto/finance/budget.go rename to api/dto/finance/budget.go index e713526..84adb68 100644 --- a/dto/finance/budget.go +++ b/api/dto/finance/budget.go @@ -2,7 +2,7 @@ package finance import ( "erp/api/request" - "erp/models" + "erp/domain" uuid "github.com/satori/go.uuid" "time" ) @@ -31,6 +31,6 @@ type ListBudgetRequest struct { } type BudgetResponse struct { - models.Budget + domain.Budget Spent float64 `json:"spent"` } diff --git a/dto/finance/cashbook.go b/api/dto/finance/cashbook.go similarity index 100% rename from dto/finance/cashbook.go rename to api/dto/finance/cashbook.go diff --git a/dto/finance/cashbook_category.go b/api/dto/finance/cashbook_category.go similarity index 100% rename from dto/finance/cashbook_category.go rename to api/dto/finance/cashbook_category.go diff --git a/dto/finance/wallet.go b/api/dto/finance/wallet.go similarity index 100% rename from dto/finance/wallet.go rename to api/dto/finance/wallet.go diff --git a/api/middlewares/auth.go b/api/middlewares/auth.go index ada2226..ee14984 100644 --- a/api/middlewares/auth.go +++ b/api/middlewares/auth.go @@ -2,9 +2,9 @@ package middlewares import ( "context" + "erp/api/dto/auth" "erp/api/response" - "erp/api_errors" - dto "erp/dto/auth" + "erp/utils/api_errors" "net/http" "strings" @@ -71,8 +71,8 @@ func (e *GinMiddleware) Auth(authorization bool) gin.HandlerFunc { //} //c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), "x-store-id", storeID)) - //ur := new(models.UserRole) - //if err = e.db.Model(models.UserRole{}).Where("user_id = ? AND store_id = ?", claims.Subject, storeID).First(ur).Error; err != nil { + //ur := new(domain.UserRole) + //if err = e.db.Model(domain.UserRole{}).Where("user_id = ? AND store_id = ?", claims.Subject, storeID).First(ur).Error; err != nil { // c.Errors = append(c.Errors, &gin.Error{ // Err: errors.Wrap(err, "cannot find user role"), // }) @@ -90,8 +90,8 @@ func (e *GinMiddleware) Auth(authorization bool) gin.HandlerFunc { // return //} - //role := new(models.Role) - //if err = e.db.Model(models.Role{}).Where("id = ?", ur.RoleID).First(role).Error; err != nil { + //role := new(domain.Role) + //if err = e.db.Model(domain.Role{}).Where("id = ?", ur.RoleID).First(role).Error; err != nil { // c.Errors = append(c.Errors, &gin.Error{ // Err: errors.Wrap(err, "cannot find role"), // }) @@ -104,8 +104,8 @@ func (e *GinMiddleware) Auth(authorization bool) gin.HandlerFunc { // }) // return //} - //up := new(models.Permission) - //if err = e.db.Model(models.Permission{}).Where("role_id = ? AND route_path = ?", ur.RoleID, c.Request.URL.Path).First(up).Error; err != nil { + //up := new(domain.Permission) + //if err = e.db.Model(domain.Permission{}).Where("role_id = ? AND route_path = ?", ur.RoleID, c.Request.URL.Path).First(up).Error; err != nil { // c.Errors = append(c.Errors, &gin.Error{ // Err: errors.Wrap(err, "cannot find permission"), // }) diff --git a/models/base.go b/domain/base.go similarity index 98% rename from models/base.go rename to domain/base.go index 2f1685c..d0a1b8d 100644 --- a/models/base.go +++ b/domain/base.go @@ -1,4 +1,4 @@ -package models +package domain import ( "gorm.io/gorm" diff --git a/models/budget.go b/domain/budget.go similarity index 97% rename from models/budget.go rename to domain/budget.go index 07bc1e2..18338c0 100644 --- a/models/budget.go +++ b/domain/budget.go @@ -1,4 +1,4 @@ -package models +package domain import ( uuid "github.com/satori/go.uuid" diff --git a/models/category.go b/domain/category.go similarity index 59% rename from models/category.go rename to domain/category.go index 06480c5..ea878c5 100644 --- a/models/category.go +++ b/domain/category.go @@ -1,13 +1,12 @@ -package models +package domain import uuid "github.com/satori/go.uuid" type Category struct { BaseModel - StoreId uuid.UUID `json:"store_id" gorm:"type:uuid;default:uuid_generate_v4();index"` - Name string `json:"name" gorm:"column:name;type:varchar(50);not null"` - Image string `json:"image" gorm:"column:image;type:varchar(250);null"` - TotalProduct int `json:"total_product" gorm:"column:total_product;type:int;default:0;"` + StoreId uuid.UUID `json:"store_id" gorm:"type:uuid;default:uuid_generate_v4();index"` + Name string `json:"name" gorm:"column:name;type:varchar(50);not null"` + Image string `json:"image" gorm:"column:image;type:varchar(250);null"` } type CategoryResult struct { diff --git a/models/category_product.go b/domain/category_product.go similarity index 96% rename from models/category_product.go rename to domain/category_product.go index 7bc1bdf..f0aadef 100644 --- a/models/category_product.go +++ b/domain/category_product.go @@ -1,4 +1,4 @@ -package models +package domain import uuid "github.com/satori/go.uuid" diff --git a/models/customer.go b/domain/customer.go similarity index 98% rename from models/customer.go rename to domain/customer.go index 7d25df5..9e1f2b4 100644 --- a/models/customer.go +++ b/domain/customer.go @@ -1,4 +1,4 @@ -package models +package domain type Customer struct { BaseModel diff --git a/models/debt.go b/domain/debt.go similarity index 95% rename from models/debt.go rename to domain/debt.go index 4b29ade..c39c8f1 100644 --- a/models/debt.go +++ b/domain/debt.go @@ -1,4 +1,4 @@ -package models +package domain import ( "time" diff --git a/models/order.go b/domain/order.go similarity index 98% rename from models/order.go rename to domain/order.go index 6ca3f1e..0a080d4 100644 --- a/models/order.go +++ b/domain/order.go @@ -1,4 +1,4 @@ -package models +package domain import uuid "github.com/satori/go.uuid" diff --git a/models/order_item.go b/domain/order_item.go similarity index 95% rename from models/order_item.go rename to domain/order_item.go index 2e3dc99..aa8dd6a 100644 --- a/models/order_item.go +++ b/domain/order_item.go @@ -1,4 +1,4 @@ -package models +package domain import uuid "github.com/satori/go.uuid" diff --git a/models/permission.go b/domain/permission.go similarity index 96% rename from models/permission.go rename to domain/permission.go index 3f0b420..c84880f 100644 --- a/models/permission.go +++ b/domain/permission.go @@ -1,4 +1,4 @@ -package models +package domain import uuid "github.com/satori/go.uuid" diff --git a/models/product.go b/domain/product.go similarity index 98% rename from models/product.go rename to domain/product.go index 8139d62..8585573 100644 --- a/models/product.go +++ b/domain/product.go @@ -1,4 +1,4 @@ -package models +package domain import ( uuid "github.com/satori/go.uuid" diff --git a/models/promote.go b/domain/promote.go similarity index 98% rename from models/promote.go rename to domain/promote.go index 89ff75e..e9d2607 100644 --- a/models/promote.go +++ b/domain/promote.go @@ -1,4 +1,4 @@ -package models +package domain import ( uuid "github.com/satori/go.uuid" diff --git a/models/role.go b/domain/role.go similarity index 96% rename from models/role.go rename to domain/role.go index 4f283e7..7dcb8be 100644 --- a/models/role.go +++ b/domain/role.go @@ -1,4 +1,4 @@ -package models +package domain import ( uuid "github.com/satori/go.uuid" diff --git a/models/store.go b/domain/store.go similarity index 97% rename from models/store.go rename to domain/store.go index bde1f20..08414f3 100644 --- a/models/store.go +++ b/domain/store.go @@ -1,4 +1,4 @@ -package models +package domain type Store struct { BaseModel diff --git a/models/transaction.go b/domain/transaction.go similarity index 98% rename from models/transaction.go rename to domain/transaction.go index 6eb7f90..02e6c28 100644 --- a/models/transaction.go +++ b/domain/transaction.go @@ -1,4 +1,4 @@ -package models +package domain import ( "github.com/lib/pq" diff --git a/models/transaction_category.go b/domain/transaction_category.go similarity index 95% rename from models/transaction_category.go rename to domain/transaction_category.go index 41aa1b4..0d3b6c4 100644 --- a/models/transaction_category.go +++ b/domain/transaction_category.go @@ -1,4 +1,4 @@ -package models +package domain type CashbookCategory struct { BaseModel diff --git a/models/user.go b/domain/user.go similarity index 97% rename from models/user.go rename to domain/user.go index e21c4a2..6302659 100644 --- a/models/user.go +++ b/domain/user.go @@ -1,4 +1,4 @@ -package models +package domain import uuid "github.com/satori/go.uuid" diff --git a/models/user_role.go b/domain/user_role.go similarity index 98% rename from models/user_role.go rename to domain/user_role.go index 0d1b9f3..a9023c5 100644 --- a/models/user_role.go +++ b/domain/user_role.go @@ -1,4 +1,4 @@ -package models +package domain import ( "time" diff --git a/models/wallet.go b/domain/wallet.go similarity index 95% rename from models/wallet.go rename to domain/wallet.go index 0b24915..7db893f 100644 --- a/models/wallet.go +++ b/domain/wallet.go @@ -1,4 +1,4 @@ -package models +package domain type Wallet struct { BaseModel diff --git a/infrastructure/db.go b/infrastructure/db.go index 77d6d72..45ba22f 100644 --- a/infrastructure/db.go +++ b/infrastructure/db.go @@ -3,7 +3,7 @@ package infrastructure import ( "database/sql" config "erp/config" - "erp/models" + "erp/domain" "fmt" "go.uber.org/zap" "gorm.io/driver/mysql" @@ -91,12 +91,12 @@ func getDatabaseInstance(config *config.Config) (db *gorm.DB, err error) { func (d Database) RegisterTables() { err := d.DB.AutoMigrate( - models.User{}, models.Role{}, models.Permission{}, - models.Store{}, models.UserRole{}, models.Category{}, - models.Product{}, models.CategoryProduct{}, models.Customer{}, - models.Cashbook{}, models.Order{}, - models.OrderItem{}, models.Promote{}, models.PromoteUse{}, - models.Wallet{}, models.CashbookCategory{}, models.Budget{}, + domain.User{}, domain.Role{}, domain.Permission{}, + domain.Store{}, domain.UserRole{}, domain.Category{}, + domain.Product{}, domain.CategoryProduct{}, domain.Customer{}, + domain.Cashbook{}, domain.Order{}, + domain.OrderItem{}, domain.Promote{}, domain.PromoteUse{}, + domain.Wallet{}, domain.CashbookCategory{}, domain.Budget{}, ) if err != nil { diff --git a/repository/budget.go b/repository/budget.go index 3be0401..73fcf02 100644 --- a/repository/budget.go +++ b/repository/budget.go @@ -2,20 +2,20 @@ package repository import ( "context" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" "github.com/pkg/errors" "go.uber.org/zap" ) type BudgetRepository interface { - Create(tx *TX, ctx context.Context, input *models.Budget) error - Update(tx *TX, ctx context.Context, input *models.Budget) error + Create(tx *TX, ctx context.Context, input *domain.Budget) error + Update(tx *TX, ctx context.Context, input *domain.Budget) error Delete(tx *TX, ctx context.Context, id string) error - GetOneById(ctx context.Context, id string) (*models.Budget, error) - GetList(ctx context.Context, req erpdto.ListBudgetRequest) (res []*models.Budget, total int64, err error) + GetOneById(ctx context.Context, id string) (*domain.Budget, error) + GetList(ctx context.Context, req erpdto.ListBudgetRequest) (res []*domain.Budget, total int64, err error) } type budgetRepo struct { @@ -30,13 +30,13 @@ func NewBudgetRepository(db *infrastructure.Database, logger *zap.Logger) Budget } } -func (r *budgetRepo) Create(tx *TX, ctx context.Context, input *models.Budget) error { +func (r *budgetRepo) Create(tx *TX, ctx context.Context, input *domain.Budget) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Create(input).Error } -func (r *budgetRepo) GetOneById(ctx context.Context, id string) (*models.Budget, error) { - output := &models.Budget{} +func (r *budgetRepo) GetOneById(ctx context.Context, id string) (*domain.Budget, error) { + output := &domain.Budget{} err := r.db.WithContext(ctx). Select("budgets.*, sum(cashbooks.amount) as spent"). Joins(`left join cashbooks on cashbooks.cashbook_category_id = budgets.cashbook_category_id @@ -48,8 +48,8 @@ func (r *budgetRepo) GetOneById(ctx context.Context, id string) (*models.Budget, return output, err } -func (r *budgetRepo) GetList(ctx context.Context, req erpdto.ListBudgetRequest) (res []*models.Budget, total int64, err error) { - query := r.db.Model(&models.Budget{}).Debug(). +func (r *budgetRepo) GetList(ctx context.Context, req erpdto.ListBudgetRequest) (res []*domain.Budget, total int64, err error) { + query := r.db.Model(&domain.Budget{}).Debug(). Select("budgets.*, sum(cashbooks.amount) as spent"). Joins(`left join cashbooks on cashbooks.cashbook_category_id = budgets.cashbook_category_id AND (cashbooks.date_time BETWEEN budgets.start_time AND budgets.end_time OR budgets.start_time IS NULL OR budgets.end_time IS NULL)`) @@ -71,12 +71,12 @@ func (r *budgetRepo) GetList(ctx context.Context, req erpdto.ListBudgetRequest) return res, total, err } -func (r *budgetRepo) Update(tx *TX, ctx context.Context, input *models.Budget) error { +func (r *budgetRepo) Update(tx *TX, ctx context.Context, input *domain.Budget) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Where("id = ?", input.ID).Save(input).Error } func (r *budgetRepo) Delete(tx *TX, ctx context.Context, id string) error { tx = GetTX(tx, *r.db) - return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&models.Budget{}).Error + return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&domain.Budget{}).Error } diff --git a/repository/cashbook.go b/repository/cashbook.go index 6ee11ad..0d9071b 100644 --- a/repository/cashbook.go +++ b/repository/cashbook.go @@ -2,9 +2,9 @@ package repository import ( "context" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" "github.com/pkg/errors" uuid "github.com/satori/go.uuid" @@ -13,14 +13,14 @@ import ( ) type CashbookRepository interface { - Create(tx *TX, ctx context.Context, input *models.Cashbook) error - Update(tx *TX, ctx context.Context, input *models.Cashbook) error + Create(tx *TX, ctx context.Context, input *domain.Cashbook) error + Update(tx *TX, ctx context.Context, input *domain.Cashbook) error Delete(tx *TX, ctx context.Context, id string) error - GetOneById(ctx context.Context, id string) (*models.Cashbook, error) - GetCashbookByOrderId(tx *TX, ctx context.Context, orderId string) (*models.Cashbook, error) - GetDebtByOrderId(tx *TX, ctx context.Context, orderId string) (*models.Cashbook, error) - GetList(ctx context.Context, req erpdto.ListCashbookRequest) (res []*models.Cashbook, total int64, err error) - GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) (res []*models.Cashbook, total int64, err error) + GetOneById(ctx context.Context, id string) (*domain.Cashbook, error) + GetCashbookByOrderId(tx *TX, ctx context.Context, orderId string) (*domain.Cashbook, error) + GetDebtByOrderId(tx *TX, ctx context.Context, orderId string) (*domain.Cashbook, error) + GetList(ctx context.Context, req erpdto.ListCashbookRequest) (res []*domain.Cashbook, total int64, err error) + GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) (res []*domain.Cashbook, total int64, err error) GetTotalTransactionByCategoryIdAndTime(ctx context.Context, categoryId uuid.UUID, startTime, endTime *time.Time) (total float64, err error) GetListTotalTransactionByCategoryIdAndTime(ctx context.Context, categoryId uuid.UUID, startTime, endTime *time.Time) (output []*erpdto.TotalTransactionByCategoryResponse, err error) GetTotalDebtByCustomerID(ctx context.Context, customerId uuid.UUID) (total float64, err error) @@ -38,22 +38,22 @@ func NewTransactionRepository(db *infrastructure.Database, logger *zap.Logger) C } } -func (r *transactionRepo) Create(tx *TX, ctx context.Context, input *models.Cashbook) error { +func (r *transactionRepo) Create(tx *TX, ctx context.Context, input *domain.Cashbook) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Create(input).Error } -func (r *transactionRepo) GetOneById(ctx context.Context, id string) (*models.Cashbook, error) { - input := &models.Cashbook{} +func (r *transactionRepo) GetOneById(ctx context.Context, id string) (*domain.Cashbook, error) { + input := &domain.Cashbook{} err := r.db.WithContext(ctx).Where("id = ?", id). Preload("CashbookCategory"). First(input).Error return input, err } -func (r *transactionRepo) GetCashbookByOrderId(tx *TX, ctx context.Context, orderId string) (*models.Cashbook, error) { +func (r *transactionRepo) GetCashbookByOrderId(tx *TX, ctx context.Context, orderId string) (*domain.Cashbook, error) { tx = GetTX(tx, *r.db) - input := &models.Cashbook{} + input := &domain.Cashbook{} err := tx.db.WithContext(ctx).Where("order_id = ?", orderId). Joins("left join cashbook_categories on cashbook_categories.id = cashbooks.cashbook_category_id"). Where("cashbook_categories.type not in (?)", []string{"debt", "loan"}). @@ -61,9 +61,9 @@ func (r *transactionRepo) GetCashbookByOrderId(tx *TX, ctx context.Context, orde return input, err } -func (r *transactionRepo) GetDebtByOrderId(tx *TX, ctx context.Context, orderId string) (*models.Cashbook, error) { +func (r *transactionRepo) GetDebtByOrderId(tx *TX, ctx context.Context, orderId string) (*domain.Cashbook, error) { tx = GetTX(tx, *r.db) - input := &models.Cashbook{} + input := &domain.Cashbook{} err := tx.db.WithContext(ctx).Where("order_id = ?", orderId). Joins("left join cashbook_categories on cashbook_categories.id = cashbooks.cashbook_category_id"). Where("cashbook_categories.type in (?)", []string{"debt", "loan"}). @@ -71,8 +71,8 @@ func (r *transactionRepo) GetDebtByOrderId(tx *TX, ctx context.Context, orderId return input, err } -func (r *transactionRepo) GetList(ctx context.Context, req erpdto.ListCashbookRequest) (res []*models.Cashbook, total int64, err error) { - query := r.db.Model(&models.Cashbook{}) +func (r *transactionRepo) GetList(ctx context.Context, req erpdto.ListCashbookRequest) (res []*domain.Cashbook, total int64, err error) { + query := r.db.Model(&domain.Cashbook{}) if req.Search != "" { query = query.Where("name ilike ?", "%"+req.Search+"%") } @@ -92,8 +92,8 @@ func (r *transactionRepo) GetList(ctx context.Context, req erpdto.ListCashbookRe return res, total, err } -func (r *transactionRepo) GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) (res []*models.Cashbook, total int64, err error) { - query := r.db.Model(&models.Cashbook{}).Debug(). +func (r *transactionRepo) GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) (res []*domain.Cashbook, total int64, err error) { + query := r.db.Model(&domain.Cashbook{}).Debug(). Joins("left join cashbook_categories on cashbook_categories.id = cashbooks.cashbook_category_id"). Where("cashbook_categories.type in (?)", []string{"debt", "loan"}) if req.Search != "" { @@ -115,18 +115,18 @@ func (r *transactionRepo) GetListDebt(ctx context.Context, req erpdto.ListCashbo return res, total, err } -func (r *transactionRepo) Update(tx *TX, ctx context.Context, input *models.Cashbook) error { +func (r *transactionRepo) Update(tx *TX, ctx context.Context, input *domain.Cashbook) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Where("id = ?", input.ID).Save(input).Error } func (r *transactionRepo) Delete(tx *TX, ctx context.Context, id string) error { tx = GetTX(tx, *r.db) - return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&models.Cashbook{}).Error + return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&domain.Cashbook{}).Error } func (r *transactionRepo) GetTotalTransactionByCategoryIdAndTime(ctx context.Context, categoryId uuid.UUID, startTime, endTime *time.Time) (total float64, err error) { - query := r.db.Model(&models.Cashbook{}).Where("cashbook_category_id = ?", categoryId) + query := r.db.Model(&domain.Cashbook{}).Where("cashbook_category_id = ?", categoryId) if startTime != nil { query = query.Where("created_at >= ?", startTime) } @@ -153,7 +153,7 @@ func (r *transactionRepo) GetListTotalTransactionByCategoryIdAndTime(ctx context func (r *transactionRepo) GetTotalDebtByCustomerID(ctx context.Context, customerId uuid.UUID) (total float64, err error) { total = float64(0) - query := r.db.Model(&models.Cashbook{}).Where("customer_id = ? and is_pay = false", customerId) + query := r.db.Model(&domain.Cashbook{}).Where("customer_id = ? and is_pay = false", customerId) err = query.Pluck("coalesce(sum(amount),0)", &total).Error return total, err } diff --git a/repository/cashbook_category.go b/repository/cashbook_category.go index 2cf87ad..9f614ae 100644 --- a/repository/cashbook_category.go +++ b/repository/cashbook_category.go @@ -2,20 +2,20 @@ package repository import ( "context" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" "github.com/pkg/errors" "go.uber.org/zap" ) type TransactionCategoryRepository interface { - Create(tx *TX, ctx context.Context, trans *models.CashbookCategory) error - Update(tx *TX, ctx context.Context, trans *models.CashbookCategory) error + Create(tx *TX, ctx context.Context, trans *domain.CashbookCategory) error + Update(tx *TX, ctx context.Context, trans *domain.CashbookCategory) error Delete(tx *TX, ctx context.Context, id string) error - GetOneById(ctx context.Context, id string) (*models.CashbookCategory, error) - GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) (res []*models.CashbookCategory, total int64, err error) + GetOneById(ctx context.Context, id string) (*domain.CashbookCategory, error) + GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) (res []*domain.CashbookCategory, total int64, err error) } type transactionCategoryRepo struct { @@ -30,19 +30,19 @@ func NewTransactionCategoryRepository(db *infrastructure.Database, logger *zap.L } } -func (r *transactionCategoryRepo) Create(tx *TX, ctx context.Context, trans *models.CashbookCategory) error { +func (r *transactionCategoryRepo) Create(tx *TX, ctx context.Context, trans *domain.CashbookCategory) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Create(trans).Error } -func (r *transactionCategoryRepo) GetOneById(ctx context.Context, id string) (*models.CashbookCategory, error) { - trans := &models.CashbookCategory{} +func (r *transactionCategoryRepo) GetOneById(ctx context.Context, id string) (*domain.CashbookCategory, error) { + trans := &domain.CashbookCategory{} err := r.db.WithContext(ctx).Where("id = ?", id).First(trans).Error return trans, err } -func (r *transactionCategoryRepo) GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) (res []*models.CashbookCategory, total int64, err error) { - query := r.db.Model(&models.CashbookCategory{}) +func (r *transactionCategoryRepo) GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) (res []*domain.CashbookCategory, total int64, err error) { + query := r.db.Model(&domain.CashbookCategory{}) if req.Search != "" { query = query.Where("name ilike ?", "%"+req.Search+"%") } @@ -59,12 +59,12 @@ func (r *transactionCategoryRepo) GetList(ctx context.Context, req erpdto.ListTr return res, total, err } -func (r *transactionCategoryRepo) Update(tx *TX, ctx context.Context, trans *models.CashbookCategory) error { +func (r *transactionCategoryRepo) Update(tx *TX, ctx context.Context, trans *domain.CashbookCategory) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Where("id = ?", trans.ID).Save(trans).Error } func (r *transactionCategoryRepo) Delete(tx *TX, ctx context.Context, id string) error { tx = GetTX(tx, *r.db) - return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&models.CashbookCategory{}).Error + return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&domain.CashbookCategory{}).Error } diff --git a/repository/erp_cat_pro.go b/repository/erp_cat_pro.go index 467f34d..4d75a1c 100644 --- a/repository/erp_cat_pro.go +++ b/repository/erp_cat_pro.go @@ -2,9 +2,9 @@ package repository import ( "context" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + models "erp/domain" "erp/infrastructure" - models "erp/models" "erp/utils" "github.com/pkg/errors" ) diff --git a/repository/erp_category.go b/repository/erp_category.go index 9d9a659..8b27045 100644 --- a/repository/erp_category.go +++ b/repository/erp_category.go @@ -2,9 +2,9 @@ package repository import ( "context" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + models "erp/domain" "erp/infrastructure" - models "erp/models" "erp/utils" "github.com/pkg/errors" ) @@ -61,12 +61,16 @@ func (u *categoryRepo) GetOneByID(ctx context.Context, id string) (res *models.C func (u *categoryRepo) GetList(ctx context.Context, req erpdto.GetListCategoryRequest) (res []*models.CategoryResult, total int64, err error) { var output []*models.CategoryResult - query := u.db.Table("categories").Debug() + query := u.db. + Select("categories.*, count(category_id) as total_product"). + Table("categories"). + Joins("left join categories_products cp on categories.id = cp.category_id") + if req.Search != "" { query = query.Where("unaccent(name) ilike ?", "%"+req.Search+"%") } - query.Count(&total) + query.Group("categories.id").Count(&total) switch req.Sort { default: diff --git a/repository/erp_customer.go b/repository/erp_customer.go index 164d5ba..f4cf75a 100644 --- a/repository/erp_customer.go +++ b/repository/erp_customer.go @@ -2,9 +2,9 @@ package repository import ( "context" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" "fmt" "github.com/pkg/errors" @@ -12,10 +12,10 @@ import ( ) type ERPCustomerRepository interface { - List(ctx context.Context, request erpdto.ListCustomerRequest) ([]*models.Customer, *int64, error) - FindOneByID(ctx context.Context, customerId string) (res *models.Customer, err error) - Create(ctx context.Context, customer *models.Customer) (*models.Customer, error) - Update(ctx context.Context, customer *models.Customer) (*models.Customer, error) + List(ctx context.Context, request erpdto.ListCustomerRequest) ([]*domain.Customer, *int64, error) + FindOneByID(ctx context.Context, customerId string) (res *domain.Customer, err error) + Create(ctx context.Context, customer *domain.Customer) (*domain.Customer, error) + Update(ctx context.Context, customer *domain.Customer) (*domain.Customer, error) Delete(ctx context.Context, customerId string) error } @@ -28,10 +28,10 @@ func NewERPCustomerRepository(db *infrastructure.Database) ERPCustomerRepository return &erpCustomerRepository{db} } -func (p *erpCustomerRepository) List(ctx context.Context, req erpdto.ListCustomerRequest) ([]*models.Customer, *int64, error) { - var customer []*models.Customer +func (p *erpCustomerRepository) List(ctx context.Context, req erpdto.ListCustomerRequest) ([]*domain.Customer, *int64, error) { + var customer []*domain.Customer var total int64 = 0 - query := p.db.Model(&models.Customer{}) + query := p.db.Model(&domain.Customer{}) if req.Search != "" { query = query.Where("full_name ILIKE ?", "%"+req.Search+"%") @@ -49,7 +49,7 @@ func (p *erpCustomerRepository) List(ctx context.Context, req erpdto.ListCustome return customer, &total, nil } -func (p *erpCustomerRepository) FindOneByID(ctx context.Context, customerId string) (res *models.Customer, err error) { +func (p *erpCustomerRepository) FindOneByID(ctx context.Context, customerId string) (res *domain.Customer, err error) { db := p.db.WithContext(ctx) if res := db.Where("id = ?", customerId).First(&res); res.Error != nil { return nil, errors.Wrap(err, "Get customer by id failed") @@ -58,7 +58,7 @@ func (p *erpCustomerRepository) FindOneByID(ctx context.Context, customerId stri return res, nil } -func (p *erpCustomerRepository) Create(ctx context.Context, customer *models.Customer) (*models.Customer, error) { +func (p *erpCustomerRepository) Create(ctx context.Context, customer *domain.Customer) (*domain.Customer, error) { if err := p.db.WithContext(ctx).Create(customer).Error; err != nil { return nil, errors.Wrap(err, "CreateFlow customer failed") } @@ -66,7 +66,7 @@ func (p *erpCustomerRepository) Create(ctx context.Context, customer *models.Cus return customer, nil } -func (p *erpCustomerRepository) Update(ctx context.Context, customer *models.Customer) (*models.Customer, error) { +func (p *erpCustomerRepository) Update(ctx context.Context, customer *domain.Customer) (*domain.Customer, error) { customer.UpdatedAt = time.Now() if err := p.db.WithContext(ctx).Save(&customer).Error; err != nil { @@ -78,7 +78,7 @@ func (p *erpCustomerRepository) Update(ctx context.Context, customer *models.Cus } func (p *erpCustomerRepository) Delete(ctx context.Context, customerId string) error { - if err := p.db.WithContext(ctx).Where("id = ?", customerId).Delete(&models.Customer{}).Error; err != nil { + if err := p.db.WithContext(ctx).Where("id = ?", customerId).Delete(&domain.Customer{}).Error; err != nil { return errors.Wrap(err, "Delete customer failed") } diff --git a/repository/erp_permission.go b/repository/erp_permission.go index e5a0bf7..12b5532 100644 --- a/repository/erp_permission.go +++ b/repository/erp_permission.go @@ -2,8 +2,8 @@ package repository import ( "erp/api/request" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" "github.com/pkg/errors" @@ -11,7 +11,7 @@ import ( ) type ErpPermissionRepo interface { - List() ([]*models.Permission, *int64, error) + List() ([]*domain.Permission, *int64, error) } type erpPermissionRepo struct { @@ -23,10 +23,10 @@ func NewErpPermissionRepo(db *infrastructure.Database, logger *zap.Logger) ErpPe return &erpPermissionRepo{db, logger} } -func (e *erpPermissionRepo) List() ([]*models.Permission, *int64, error) { +func (e *erpPermissionRepo) List() ([]*domain.Permission, *int64, error) { var total int64 = 0 - var res []*models.Permission - query := e.db.Model(&models.Permission{}) + var res []*domain.Permission + query := e.db.Model(&domain.Permission{}) err := utils.QueryPagination(query, request.PageOptions{ Limit: 1000, Page: 1, diff --git a/repository/erp_product.go b/repository/erp_product.go index fc54db8..63b9d6d 100644 --- a/repository/erp_product.go +++ b/repository/erp_product.go @@ -2,9 +2,9 @@ package repository import ( "context" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + models "erp/domain" "erp/infrastructure" - models "erp/models" "erp/utils" "github.com/pkg/errors" ) diff --git a/repository/erp_role.go b/repository/erp_role.go index 1b8735f..f7eee5e 100644 --- a/repository/erp_role.go +++ b/repository/erp_role.go @@ -2,8 +2,8 @@ package repository import ( "context" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" "github.com/pkg/errors" @@ -13,21 +13,21 @@ import ( type ERPRoleRepository interface { UpdateRolePermission(tx *TX, ctx context.Context, roleID string, permissionIDs []string) error - CreateRole(tx *TX, ctx context.Context, name string, extends []string, storeID string) (*models.Cashbook, error) + CreateRole(tx *TX, ctx context.Context, name string, extends []string, storeID string) (*domain.Cashbook, error) AssignRevenueToUser(tx *TX, ctx context.Context, userID string, roleID string, storeID string, isStoreOwner bool) error - FindRevenueByIDs(ids []string) ([]models.Cashbook, error) - GetRevenueByRevenueID(ctx context.Context, id string) (*models.Cashbook, error) - FindRoleByIDs(ids []string) ([]models.Role, error) + FindRevenueByIDs(ids []string) ([]domain.Cashbook, error) + GetRevenueByRevenueID(ctx context.Context, id string) (*domain.Cashbook, error) + FindRoleByIDs(ids []string) ([]domain.Role, error) AssignRoleToUser(tx *TX, ctx context.Context, userID string, roleID string, storeID string, isStoreOwner bool) error - FindRoleByID(ctx context.Context, id string) (*models.Role, error) - FindUserRoleByStoreIDAndUserID(ctx context.Context, storeID string, userID string) (*models.UserRole, error) + FindRoleByID(ctx context.Context, id string) (*domain.Role, error) + FindUserRoleByStoreIDAndUserID(ctx context.Context, storeID string, userID string) (*domain.UserRole, error) } type erpRoleRepository struct { db *infrastructure.Database } -func (e *erpRoleRepository) CreateRole(tx *TX, ctx context.Context, name string, extends []string, storeID string) (*models.Cashbook, error) { +func (e *erpRoleRepository) CreateRole(tx *TX, ctx context.Context, name string, extends []string, storeID string) (*domain.Cashbook, error) { //TODO implement me panic("implement me") } @@ -37,12 +37,12 @@ func (e *erpRoleRepository) AssignRevenueToUser(tx *TX, ctx context.Context, use panic("implement me") } -func (e *erpRoleRepository) FindRevenueByIDs(ids []string) ([]models.Cashbook, error) { +func (e *erpRoleRepository) FindRevenueByIDs(ids []string) ([]domain.Cashbook, error) { //TODO implement me panic("implement me") } -func (e *erpRoleRepository) GetRevenueByRevenueID(ctx context.Context, id string) (*models.Cashbook, error) { +func (e *erpRoleRepository) GetRevenueByRevenueID(ctx context.Context, id string) (*domain.Cashbook, error) { //TODO implement me panic("implement me") } @@ -54,21 +54,21 @@ func NewErpRoleRepo(db *infrastructure.Database) ERPRoleRepository { } // -//func (e *erpRoleRepository) CreateRole(tx *TX, ctx context.Context, name string, extends []string, storeID string) (*models.Role, error) { +//func (e *erpRoleRepository) CreateRole(tx *TX, ctx context.Context, name string, extends []string, storeID string) (*domain.Role, error) { // tx = GetTX(tx, *e.db) // // sid, _ := uuid.FromString(storeID) // -// extendsRole := make([]models.Role, 0) +// extendsRole := make([]domain.Role, 0) // for _, id := range extends { -// extendsRole = append(extendsRole, models.Role{ -// BaseModel: models.BaseModel{ +// extendsRole = append(extendsRole, domain.Role{ +// BaseModel: domain.BaseModel{ // ID: uuid.FromStringOrNil(id), // }, // }) // } // -// role := &models.Role{ +// role := &domain.Role{ // Name: name, // StoreID: sid, // } @@ -92,23 +92,23 @@ func (e *erpRoleRepository) UpdateRolePermission(tx *TX, ctx context.Context, ro return errors.Wrap(err, "delete role permission failed") } - var permissions []models.Permission + var permissions []domain.Permission for _, id := range permissionIDs { - permission := models.Permission{ + permission := domain.Permission{ ID: uuid.FromStringOrNil(id), } permissions = append(permissions, permission) } - return tx.db.Model(&models.Role{ - BaseModel: models.BaseModel{ + return tx.db.Model(&domain.Role{ + BaseModel: domain.BaseModel{ ID: uuid.FromStringOrNil(roleID), }, }).Omit("Permissions.*").Association("Permissions").Append(permissions) } -func (e *erpRoleRepository) FindRoleByIDs(ids []string) ([]models.Role, error) { - var roles []models.Role +func (e *erpRoleRepository) FindRoleByIDs(ids []string) ([]domain.Role, error) { + var roles []domain.Role if err := e.db.Where("id IN (?)", ids).Find(&roles).Error; err != nil { return nil, errors.Wrap(err, "find role by ids failed") } @@ -124,7 +124,7 @@ func (e *erpRoleRepository) AssignRoleToUser(tx *TX, ctx context.Context, userID DoUpdates: clause.Assignments(map[string]interface{}{ "role_id": roleID, }), - }).Create(&models.UserRole{ + }).Create(&domain.UserRole{ IsStoreOwner: isStoreOwner, UserID: uuid.FromStringOrNil(userID), RoleID: uuid.FromStringOrNil(roleID), @@ -138,8 +138,8 @@ func (e *erpRoleRepository) AssignRoleToUser(tx *TX, ctx context.Context, userID return nil } -func (e *erpRoleRepository) FindRoleByID(ctx context.Context, id string) (*models.Role, error) { - var role models.Role +func (e *erpRoleRepository) FindRoleByID(ctx context.Context, id string) (*domain.Role, error) { + var role domain.Role err := e.db.WithContext(ctx).Where("id = ?", id).First(&role).Error if err != nil { if utils.ErrNoRows(err) { @@ -151,8 +151,8 @@ func (e *erpRoleRepository) FindRoleByID(ctx context.Context, id string) (*model return &role, nil } -func (e *erpRoleRepository) FindUserRoleByStoreIDAndUserID(ctx context.Context, storeID string, userID string) (*models.UserRole, error) { - var userRole models.UserRole +func (e *erpRoleRepository) FindUserRoleByStoreIDAndUserID(ctx context.Context, storeID string, userID string) (*domain.UserRole, error) { + var userRole domain.UserRole err := e.db.WithContext(ctx).Where("store_id = ? AND user_id = ?", storeID, userID).First(&userRole).Error if err != nil { if utils.ErrNoRows(err) { diff --git a/repository/erp_store.go b/repository/erp_store.go index f0c6c30..ffc8e40 100644 --- a/repository/erp_store.go +++ b/repository/erp_store.go @@ -3,20 +3,20 @@ package repository import ( "context" "erp/api/request" - "erp/api_errors" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" + "erp/utils/api_errors" "github.com/pkg/errors" "go.uber.org/zap" ) type ERPStoreRepository interface { - Create(tx *TX, ctx context.Context, store *models.Store) (*models.Store, error) - Update(tx *TX, ctx context.Context, store *models.Store) (*models.Store, error) - FindByID(ctx context.Context, id string) (*models.Store, error) - List(ctx context.Context, search string, o request.PageOptions, userID string) ([]*models.Store, *int64, error) + Create(tx *TX, ctx context.Context, store *domain.Store) (*domain.Store, error) + Update(tx *TX, ctx context.Context, store *domain.Store) (*domain.Store, error) + FindByID(ctx context.Context, id string) (*domain.Store, error) + List(ctx context.Context, search string, o request.PageOptions, userID string) ([]*domain.Store, *int64, error) DeleteByID(tx *TX, ctx context.Context, id string) error } @@ -32,7 +32,7 @@ func NewERPStoreRepository(db *infrastructure.Database, logger *zap.Logger) ERPS } } -func (p *erpStoreRepository) Create(tx *TX, ctx context.Context, store *models.Store) (*models.Store, error) { +func (p *erpStoreRepository) Create(tx *TX, ctx context.Context, store *domain.Store) (*domain.Store, error) { tx = GetTX(tx, *p.db) if err := tx.db.WithContext(ctx).Create(store).Error; err != nil { @@ -42,7 +42,7 @@ func (p *erpStoreRepository) Create(tx *TX, ctx context.Context, store *models.S return store, nil } -func (p *erpStoreRepository) Update(tx *TX, ctx context.Context, store *models.Store) (*models.Store, error) { +func (p *erpStoreRepository) Update(tx *TX, ctx context.Context, store *domain.Store) (*domain.Store, error) { tx = GetTX(tx, *p.db) if err := tx.db.WithContext(ctx).Save(store).Error; err != nil { @@ -52,8 +52,8 @@ func (p *erpStoreRepository) Update(tx *TX, ctx context.Context, store *models.S return store, nil } -func (p *erpStoreRepository) FindByID(ctx context.Context, id string) (*models.Store, error) { - var store models.Store +func (p *erpStoreRepository) FindByID(ctx context.Context, id string) (*domain.Store, error) { + var store domain.Store if err := p.db.WithContext(ctx).Where("id = ?", id).First(&store).Error; err != nil { if utils.ErrNoRows(err) { return nil, errors.New(api_errors.ErrStoreNotFound) @@ -64,11 +64,11 @@ func (p *erpStoreRepository) FindByID(ctx context.Context, id string) (*models.S return &store, nil } -func (p *erpStoreRepository) List(ctx context.Context, search string, o request.PageOptions, userID string) ([]*models.Store, *int64, error) { - var stores []*models.Store +func (p *erpStoreRepository) List(ctx context.Context, search string, o request.PageOptions, userID string) ([]*domain.Store, *int64, error) { + var stores []*domain.Store var total int64 = 0 - q := p.db.WithContext(ctx).Model(&models.Store{}) + q := p.db.WithContext(ctx).Model(&domain.Store{}) if search != "" { q = q.Where("name LIKE ?", "%"+search+"%") @@ -86,7 +86,7 @@ func (p *erpStoreRepository) List(ctx context.Context, search string, o request. func (p *erpStoreRepository) DeleteByID(tx *TX, ctx context.Context, id string) error { tx = GetTX(tx, *p.db) - if err := tx.db.WithContext(ctx).Where("id = ?", id).Delete(&models.Store{}).Error; err != nil { + if err := tx.db.WithContext(ctx).Where("id = ?", id).Delete(&domain.Store{}).Error; err != nil { return errors.Wrap(err, "Delete store failed") } diff --git a/repository/order.go b/repository/order.go index 552629b..927f253 100644 --- a/repository/order.go +++ b/repository/order.go @@ -2,24 +2,24 @@ package repository import ( "context" - "erp/api_errors" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" + "erp/utils/api_errors" "go.uber.org/zap" "github.com/pkg/errors" ) type OrderRepo interface { - Create(tx *TX, ctx context.Context, order *models.Order) error - Update(tx *TX, ctx context.Context, order *models.Order) error - GetOneById(ctx context.Context, id string) (*models.Order, error) - GetList(ctx context.Context, req erpdto.GetListOrderRequest) (res []*models.Order, total int64, err error) - GetOverview(ctx context.Context, req erpdto.GetListOrderRequest) (res []*models.OrderOverview, err error) - GetBestSeller(ctx context.Context, req erpdto.GetListOrderRequest) (res []*models.ProductBestSellerResponse, err error) - GetDetailCustomer(ctx context.Context, customerId string) (res *models.CustomerDetail, err error) + Create(tx *TX, ctx context.Context, order *domain.Order) error + Update(tx *TX, ctx context.Context, order *domain.Order) error + GetOneById(ctx context.Context, id string) (*domain.Order, error) + GetList(ctx context.Context, req erpdto.GetListOrderRequest) (res []*domain.Order, total int64, err error) + GetOverview(ctx context.Context, req erpdto.GetListOrderRequest) (res []*domain.OrderOverview, err error) + GetBestSeller(ctx context.Context, req erpdto.GetListOrderRequest) (res []*domain.ProductBestSellerResponse, err error) + GetDetailCustomer(ctx context.Context, customerId string) (res *domain.CustomerDetail, err error) } type orderRepo struct { @@ -34,16 +34,16 @@ func NewOrderRepository(db *infrastructure.Database, logger *zap.Logger) OrderRe } } -func (r *orderRepo) Create(tx *TX, ctx context.Context, order *models.Order) error { +func (r *orderRepo) Create(tx *TX, ctx context.Context, order *domain.Order) error { return tx.db.WithContext(ctx).Create(order).Error } -func (r *orderRepo) Update(tx *TX, ctx context.Context, order *models.Order) error { +func (r *orderRepo) Update(tx *TX, ctx context.Context, order *domain.Order) error { return tx.db.WithContext(ctx).Save(order).Error } -func (r *orderRepo) GetOneById(ctx context.Context, id string) (*models.Order, error) { - var res models.Order +func (r *orderRepo) GetOneById(ctx context.Context, id string) (*domain.Order, error) { + var res domain.Order if err := r.db.WithContext(ctx).Where("id = ?", id). Preload("OrderItems"). Preload("Customers"). @@ -57,8 +57,8 @@ func (r *orderRepo) GetOneById(ctx context.Context, id string) (*models.Order, e return &res, nil } -func (r *orderRepo) GetList(ctx context.Context, req erpdto.GetListOrderRequest) (res []*models.Order, total int64, err error) { - query := r.db.Model(&models.Order{}) +func (r *orderRepo) GetList(ctx context.Context, req erpdto.GetListOrderRequest) (res []*domain.Order, total int64, err error) { + query := r.db.Model(&domain.Order{}) if req.Search != "" { query = query.Where("note ilike ?", "%"+req.Search+"%") } @@ -81,7 +81,7 @@ func (r *orderRepo) GetList(ctx context.Context, req erpdto.GetListOrderRequest) return res, total, err } -func (r *orderRepo) GetOverview(ctx context.Context, req erpdto.GetListOrderRequest) (res []*models.OrderOverview, err error) { +func (r *orderRepo) GetOverview(ctx context.Context, req erpdto.GetListOrderRequest) (res []*domain.OrderOverview, err error) { queryString := `SELECT count(confirm) as confirm, count(delivery) as delivery, count(complete) as complete, count(cancel) as cancel, sum(revenue) as revenue, sum(income) as income FROM ( select CASE WHEN status = 'confirm' then 1 else null end as confirm, @@ -102,7 +102,7 @@ func (r *orderRepo) GetOverview(ctx context.Context, req erpdto.GetListOrderRequ return res, err } -func (r *orderRepo) GetBestSeller(ctx context.Context, req erpdto.GetListOrderRequest) (res []*models.ProductBestSellerResponse, err error) { +func (r *orderRepo) GetBestSeller(ctx context.Context, req erpdto.GetListOrderRequest) (res []*domain.ProductBestSellerResponse, err error) { err = r.db.Table("order_items").Select("products.*, sum(order_items.quantity) as quantity_sold"). Joins("inner join products on order_items.product_id = products.id").Order("quantity_sold desc"). Where("order_items.status != 'cancel'"). @@ -110,7 +110,7 @@ func (r *orderRepo) GetBestSeller(ctx context.Context, req erpdto.GetListOrderRe return res, err } -func (r *orderRepo) GetDetailCustomer(ctx context.Context, customerId string) (res *models.CustomerDetail, err error) { +func (r *orderRepo) GetDetailCustomer(ctx context.Context, customerId string) (res *domain.CustomerDetail, err error) { queryString := `SELECT count(id) as total_order, coalesce(sum(payment), 0) as total_paid FROM orders WHERE customer_id = ?` diff --git a/repository/order_item.go b/repository/order_item.go index 9276343..7c0143f 100644 --- a/repository/order_item.go +++ b/repository/order_item.go @@ -2,14 +2,14 @@ package repository import ( "context" + "erp/domain" "erp/infrastructure" - "erp/models" "go.uber.org/zap" ) type OrderItemRepo interface { - CreateMultiple(tx *TX, ctx context.Context, orderItems []*models.OrderItem) error - GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*models.OrderItem, error) + CreateMultiple(tx *TX, ctx context.Context, orderItems []*domain.OrderItem) error + GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*domain.OrderItem, error) } type orderItemRepo struct { @@ -24,15 +24,15 @@ func NewOrderItemRepo(db *infrastructure.Database, logger *zap.Logger) OrderItem } } -func (p *orderItemRepo) CreateMultiple(tx *TX, ctx context.Context, orderItems []*models.OrderItem) error { +func (p *orderItemRepo) CreateMultiple(tx *TX, ctx context.Context, orderItems []*domain.OrderItem) error { if err := tx.db.Create(orderItems).Error; err != nil { return err } return nil } -func (r *orderItemRepo) GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*models.OrderItem, error) { - var res []*models.OrderItem +func (r *orderItemRepo) GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*domain.OrderItem, error) { + var res []*domain.OrderItem if err := r.db.Where("order_id = ?", orderId).Find(&res).Error; err != nil { return nil, err } diff --git a/repository/promote.go b/repository/promote.go index 0922a1f..2375ae9 100644 --- a/repository/promote.go +++ b/repository/promote.go @@ -2,21 +2,21 @@ package repository import ( "context" - "erp/api_errors" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" + "erp/utils/api_errors" "github.com/pkg/errors" uuid "github.com/satori/go.uuid" ) type IPromoteRepo interface { - Create(ctx context.Context, promote *models.Promote) error - GetPromoteById(ctx context.Context, id string) (*models.Promote, error) + Create(ctx context.Context, promote *domain.Promote) error + GetPromoteById(ctx context.Context, id string) (*domain.Promote, error) CountCustomerUsePromote(ctx context.Context, customerId *uuid.UUID, code string) (int64, error) UpdateQuantityUse(ctx context.Context, code string, quantityUse int) error - CreatePromoteUse(ctx context.Context, promoteUse *models.PromoteUse) error - GetPromoteByCode(ctx context.Context, code string) (*models.Promote, error) + CreatePromoteUse(ctx context.Context, promoteUse *domain.PromoteUse) error + GetPromoteByCode(ctx context.Context, code string) (*domain.Promote, error) } type promoteRep struct { @@ -29,12 +29,12 @@ func NewPromoteRepo(db *infrastructure.Database) IPromoteRepo { } } -func (r *promoteRep) Create(ctx context.Context, promote *models.Promote) error { +func (r *promoteRep) Create(ctx context.Context, promote *domain.Promote) error { return r.db.WithContext(ctx).Create(promote).Error } -func (r *promoteRep) GetPromoteById(ctx context.Context, id string) (*models.Promote, error) { - var promote models.Promote +func (r *promoteRep) GetPromoteById(ctx context.Context, id string) (*domain.Promote, error) { + var promote domain.Promote if err := r.db.WithContext(ctx).Where("id = ?", id).First(&promote).Error; err != nil { if utils.ErrNoRows(err) { return nil, errors.New(api_errors.ErrNotFound) @@ -45,8 +45,8 @@ func (r *promoteRep) GetPromoteById(ctx context.Context, id string) (*models.Pro return &promote, nil } -func (r *promoteRep) GetPromoteByCode(ctx context.Context, code string) (*models.Promote, error) { - var promote models.Promote +func (r *promoteRep) GetPromoteByCode(ctx context.Context, code string) (*domain.Promote, error) { + var promote domain.Promote if err := r.db.WithContext(ctx).Where("code = ?", code).First(&promote).Error; err != nil { return nil, err } @@ -56,7 +56,7 @@ func (r *promoteRep) GetPromoteByCode(ctx context.Context, code string) (*models func (r *promoteRep) CountCustomerUsePromote(ctx context.Context, customerId *uuid.UUID, code string) (int64, error) { var total int64 = 0 - if err := r.db.WithContext(ctx).Model(models.PromoteUse{}). + if err := r.db.WithContext(ctx).Model(domain.PromoteUse{}). Where("customer_id = ? and promote_code = ?", customerId, code). Count(&total).Error; err != nil { return 0, err @@ -69,9 +69,9 @@ type UpdateData struct { } func (r *promoteRep) UpdateQuantityUse(ctx context.Context, code string, quantityUse int) error { - return r.db.Model(&models.Promote{}).Where("code = ?", code).Update("quantity_use", quantityUse).Error + return r.db.Model(&domain.Promote{}).Where("code = ?", code).Update("quantity_use", quantityUse).Error } -func (r *promoteRep) CreatePromoteUse(ctx context.Context, promoteUse *models.PromoteUse) error { +func (r *promoteRep) CreatePromoteUse(ctx context.Context, promoteUse *domain.PromoteUse) error { return r.db.Create(promoteUse).Error } diff --git a/repository/user.go b/repository/user.go index b394eca..7bed7f2 100644 --- a/repository/user.go +++ b/repository/user.go @@ -2,10 +2,10 @@ package repository import ( "context" - api_errors "erp/api_errors" + models "erp/domain" "erp/infrastructure" - models "erp/models" "erp/utils" + "erp/utils/api_errors" "github.com/pkg/errors" "go.uber.org/zap" diff --git a/repository/wallet.go b/repository/wallet.go index 1b53d14..bb33dad 100644 --- a/repository/wallet.go +++ b/repository/wallet.go @@ -2,21 +2,21 @@ package repository import ( "context" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/utils" "github.com/pkg/errors" "go.uber.org/zap" ) type WalletRepository interface { - Create(tx *TX, ctx context.Context, trans *models.Wallet) error - Update(tx *TX, ctx context.Context, trans *models.Wallet) error + Create(tx *TX, ctx context.Context, trans *domain.Wallet) error + Update(tx *TX, ctx context.Context, trans *domain.Wallet) error Delete(tx *TX, ctx context.Context, id string) error - GetOneById(ctx context.Context, id string) (*models.Wallet, error) - GetOneByName(ctx context.Context, name string) (*models.Wallet, error) - GetList(ctx context.Context, req erpdto.ListWalletRequest) (res []*models.Wallet, total int64, err error) + GetOneById(ctx context.Context, id string) (*domain.Wallet, error) + GetOneByName(ctx context.Context, name string) (*domain.Wallet, error) + GetList(ctx context.Context, req erpdto.ListWalletRequest) (res []*domain.Wallet, total int64, err error) SetAllWalletToFalse(ctx context.Context) error } @@ -32,25 +32,25 @@ func NewWalletRepository(db *infrastructure.Database, logger *zap.Logger) Wallet } } -func (r *walletRepo) Create(tx *TX, ctx context.Context, trans *models.Wallet) error { +func (r *walletRepo) Create(tx *TX, ctx context.Context, trans *domain.Wallet) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Create(trans).Error } -func (r *walletRepo) GetOneById(ctx context.Context, id string) (*models.Wallet, error) { - trans := &models.Wallet{} +func (r *walletRepo) GetOneById(ctx context.Context, id string) (*domain.Wallet, error) { + trans := &domain.Wallet{} err := r.db.WithContext(ctx).Where("id = ?", id).First(trans).Error return trans, err } -func (r *walletRepo) GetOneByName(ctx context.Context, name string) (*models.Wallet, error) { - trans := &models.Wallet{} +func (r *walletRepo) GetOneByName(ctx context.Context, name string) (*domain.Wallet, error) { + trans := &domain.Wallet{} err := r.db.WithContext(ctx).Where("name = ?", name).First(trans).Error return trans, err } -func (r *walletRepo) GetList(ctx context.Context, req erpdto.ListWalletRequest) (res []*models.Wallet, total int64, err error) { - query := r.db.Model(&models.Wallet{}) +func (r *walletRepo) GetList(ctx context.Context, req erpdto.ListWalletRequest) (res []*domain.Wallet, total int64, err error) { + query := r.db.Model(&domain.Wallet{}) if req.Search != "" { query = query.Where("name ilike ?", "%"+req.Search+"%") } @@ -67,17 +67,17 @@ func (r *walletRepo) GetList(ctx context.Context, req erpdto.ListWalletRequest) return res, total, err } -func (r *walletRepo) Update(tx *TX, ctx context.Context, trans *models.Wallet) error { +func (r *walletRepo) Update(tx *TX, ctx context.Context, trans *domain.Wallet) error { tx = GetTX(tx, *r.db) return tx.db.WithContext(ctx).Where("id = ?", trans.ID).Save(trans).Error } func (r *walletRepo) Delete(tx *TX, ctx context.Context, id string) error { tx = GetTX(tx, *r.db) - return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&models.Wallet{}).Error + return tx.db.WithContext(ctx).Where("id = ?", id).Delete(&domain.Wallet{}).Error } func (r *walletRepo) SetAllWalletToFalse(ctx context.Context) error { userId := ctx.Value("x-user-id").(string) - return r.db.WithContext(ctx).Model(&models.Wallet{}).Where("updater_id = ?", userId).Update("is_default", false).Error + return r.db.WithContext(ctx).Model(&domain.Wallet{}).Where("updater_id = ?", userId).Update("is_default", false).Error } diff --git a/route/route.go b/route/route.go index d93b435..59926ee 100644 --- a/route/route.go +++ b/route/route.go @@ -12,23 +12,25 @@ var Module = fx.Options(fx.Invoke( )) type Route struct { - handler *lib.Handler - categoryController *controller.ERPCategoryController - customerController *controller.CustomerController - authController *controller.AuthController - employeeController *controller.ERPEmployeeManagementController - orderController *controller.OrderController - productController *controller.ERPProductController - promoteController *controller.PromoteController - storeController *controller.ERPStoreController - healthController *controller.HealthController - middleware *middlewares.GinMiddleware - transactionController *controller.CashbookController + handler *lib.Handler + categoryController *controller.ERPCategoryController + customerController *controller.CustomerController + authController *controller.AuthController + employeeController *controller.ERPEmployeeManagementController + orderController *controller.OrderController + productController *controller.ERPProductController + promoteController *controller.PromoteController + storeController *controller.ERPStoreController + healthController *controller.HealthController + middleware *middlewares.GinMiddleware + transactionController *controller.CashbookController + categoryProductController *controller.CategoryProductController } func NewRoute( handler *lib.Handler, categoryController *controller.ERPCategoryController, + categoryProductController *controller.CategoryProductController, customerController *controller.CustomerController, authController *controller.AuthController, employeeController *controller.ERPEmployeeManagementController, @@ -60,6 +62,11 @@ func NewRoute( v1.GET("/category/:id", middleware.Auth(false), categoryController.GetOne) v1.DELETE("/category/:id", middleware.Auth(true), categoryController.Delete) + v1.POST("/category_product/", middleware.Auth(true), categoryProductController.Create) + v1.PUT("/category_product/", middleware.Auth(true), categoryProductController.Update) + v1.GET("/category_product/", middleware.Auth(false), categoryProductController.GetList) + v1.DELETE("/category_product/:id", middleware.Auth(true), categoryProductController.Delete) + v1.GET("/customer/", middleware.Auth(false), customerController.GetList) v1.GET("/customer/:id", middleware.Auth(false), customerController.GetOne) v1.POST("/customer/", middleware.Auth(false), customerController.Create) diff --git a/service/auth.go b/service/auth.go index 3a447ff..4730d67 100644 --- a/service/auth.go +++ b/service/auth.go @@ -2,10 +2,10 @@ package service import ( "context" - "erp/api_errors" + dto2 "erp/api/dto/auth" config "erp/config" - dto "erp/dto/auth" - models "erp/models" + models "erp/domain" + "erp/utils/api_errors" "github.com/pkg/errors" @@ -14,8 +14,8 @@ import ( type ( AuthService interface { - Register(ctx context.Context, req dto.RegisterRequest) (user *models.User, err error) - Login(ctx context.Context, req dto.LoginRequest) (res *dto.LoginResponse, err error) + Register(ctx context.Context, req dto2.RegisterRequest) (user *models.User, err error) + Login(ctx context.Context, req dto2.LoginRequest) (res *dto2.LoginResponse, err error) } authService struct { userService UserService @@ -32,7 +32,7 @@ func NewAuthService(userService UserService, config *config.Config, jwtService J } } -func (a *authService) Register(ctx context.Context, req dto.RegisterRequest) (user *models.User, err error) { +func (a *authService) Register(ctx context.Context, req dto2.RegisterRequest) (user *models.User, err error) { encryptedPassword, err := bcrypt.GenerateFromPassword( []byte(req.Password), bcrypt.DefaultCost, @@ -53,7 +53,7 @@ func (a *authService) Register(ctx context.Context, req dto.RegisterRequest) (us return user, err } -func (a *authService) Login(ctx context.Context, req dto.LoginRequest) (res *dto.LoginResponse, err error) { +func (a *authService) Login(ctx context.Context, req dto2.LoginRequest) (res *dto2.LoginResponse, err error) { user, err := a.userService.GetByEmail(ctx, req.Email) if err != nil { @@ -78,15 +78,15 @@ func (a *authService) Login(ctx context.Context, req dto.LoginRequest) (res *dto return nil, errors.Wrap(err, "cannot generate auth tokens") } - return &dto.LoginResponse{ - User: dto.UserResponse{ + return &dto2.LoginResponse{ + User: dto2.UserResponse{ ID: user.ID.String(), FirstName: user.FirstName, LastName: user.LastName, Email: user.Email, RoleID: user.RoleID, }, - Token: dto.TokenResponse{ + Token: dto2.TokenResponse{ AccessToken: accessToken, RefreshToken: refreshToken, ExpiresIn: a.config.Jwt.AccessTokenExpiresIn, diff --git a/service/budget.go b/service/budget.go index fb20610..977f525 100644 --- a/service/budget.go +++ b/service/budget.go @@ -2,20 +2,20 @@ package service import ( "context" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" "github.com/jinzhu/copier" "go.uber.org/zap" ) type BudgetService interface { - Create(tx *repository.TX, ctx context.Context, req erpdto.CreateBudgetRequest) (*models.Budget, error) - Update(ctx context.Context, req erpdto.UpdateBudgetRequest) (*models.Budget, error) + Create(tx *repository.TX, ctx context.Context, req erpdto.CreateBudgetRequest) (*domain.Budget, error) + Update(ctx context.Context, req erpdto.UpdateBudgetRequest) (*domain.Budget, error) Delete(ctx context.Context, budgetID string) error - GetOne(ctx context.Context, id string) (*models.Budget, error) - GetList(ctx context.Context, req erpdto.ListBudgetRequest) ([]*models.Budget, int64, error) + GetOne(ctx context.Context, id string) (*domain.Budget, error) + GetList(ctx context.Context, req erpdto.ListBudgetRequest) ([]*domain.Budget, int64, error) } type budgetService struct { @@ -34,8 +34,8 @@ func NewBudgetService(budgetRepo repository.BudgetRepository, db *infrastructure } } -func (p *budgetService) Create(tx *repository.TX, ctx context.Context, req erpdto.CreateBudgetRequest) (*models.Budget, error) { - output := &models.Budget{} +func (p *budgetService) Create(tx *repository.TX, ctx context.Context, req erpdto.CreateBudgetRequest) (*domain.Budget, error) { + output := &domain.Budget{} if err := copier.Copy(&output, &req); err != nil { return nil, err } @@ -46,7 +46,7 @@ func (p *budgetService) Create(tx *repository.TX, ctx context.Context, req erpdt return output, nil } -func (p *budgetService) Update(ctx context.Context, req erpdto.UpdateBudgetRequest) (*models.Budget, error) { +func (p *budgetService) Update(ctx context.Context, req erpdto.UpdateBudgetRequest) (*domain.Budget, error) { output, err := p.budgetRepo.GetOneById(ctx, req.Id.String()) if err != nil { return nil, err @@ -62,11 +62,11 @@ func (p *budgetService) Update(ctx context.Context, req erpdto.UpdateBudgetReque return output, nil } -func (p *budgetService) GetList(ctx context.Context, req erpdto.ListBudgetRequest) ([]*models.Budget, int64, error) { +func (p *budgetService) GetList(ctx context.Context, req erpdto.ListBudgetRequest) ([]*domain.Budget, int64, error) { return p.budgetRepo.GetList(ctx, req) } -func (p *budgetService) GetOne(ctx context.Context, id string) (*models.Budget, error) { +func (p *budgetService) GetOne(ctx context.Context, id string) (*domain.Budget, error) { return p.budgetRepo.GetOneById(ctx, id) } diff --git a/service/cashbook.go b/service/cashbook.go index 831791f..5e03a20 100644 --- a/service/cashbook.go +++ b/service/cashbook.go @@ -2,23 +2,23 @@ package service import ( "context" + erpdto "erp/api/dto/finance" "erp/constants" - erpdto "erp/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" "github.com/jinzhu/copier" "go.uber.org/zap" ) type CashbookService interface { - Create(ctx context.Context, req erpdto.CreateCashbookRequest) (*models.Cashbook, error) - Update(ctx context.Context, req erpdto.UpdateCashbookRequest) (*models.Cashbook, error) - GetList(ctx context.Context, req erpdto.ListCashbookRequest) ([]*models.Cashbook, int64, error) - GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) ([]*models.Cashbook, int64, error) + Create(ctx context.Context, req erpdto.CreateCashbookRequest) (*domain.Cashbook, error) + Update(ctx context.Context, req erpdto.UpdateCashbookRequest) (*domain.Cashbook, error) + GetList(ctx context.Context, req erpdto.ListCashbookRequest) ([]*domain.Cashbook, int64, error) + GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) ([]*domain.Cashbook, int64, error) Delete(ctx context.Context, transactionID string) error - GetCashbookByOrderId(tx *repository.TX, ctx context.Context, orderId string) (*models.Cashbook, error) - GetOne(ctx context.Context, id string) (*models.Cashbook, error) + GetCashbookByOrderId(tx *repository.TX, ctx context.Context, orderId string) (*domain.Cashbook, error) + GetOne(ctx context.Context, id string) (*domain.Cashbook, error) } type cashbookService struct { @@ -37,8 +37,8 @@ func NewCashbookService(cashbookRepo repository.CashbookRepository, db *infrastr } } -func (s *cashbookService) Create(ctx context.Context, req erpdto.CreateCashbookRequest) (*models.Cashbook, error) { - output := &models.Cashbook{} +func (s *cashbookService) Create(ctx context.Context, req erpdto.CreateCashbookRequest) (*domain.Cashbook, error) { + output := &domain.Cashbook{} err := repository.WithTransaction(s.db, func(tx *repository.TX) error { if err := s.CalculateWalletAmount(tx, ctx, req.WalletId.String(), req.Amount, req.Status); err != nil { return err @@ -52,7 +52,7 @@ func (s *cashbookService) Create(ctx context.Context, req erpdto.CreateCashbookR return output, err } -func (s *cashbookService) Update(ctx context.Context, req erpdto.UpdateCashbookRequest) (*models.Cashbook, error) { +func (s *cashbookService) Update(ctx context.Context, req erpdto.UpdateCashbookRequest) (*domain.Cashbook, error) { output, err := s.cashbookRepo.GetOneById(ctx, req.Id.String()) if err != nil { return nil, err @@ -73,19 +73,19 @@ func (s *cashbookService) Update(ctx context.Context, req erpdto.UpdateCashbookR return output, err } -func (s *cashbookService) GetList(ctx context.Context, req erpdto.ListCashbookRequest) ([]*models.Cashbook, int64, error) { +func (s *cashbookService) GetList(ctx context.Context, req erpdto.ListCashbookRequest) ([]*domain.Cashbook, int64, error) { return s.cashbookRepo.GetList(ctx, req) } -func (s *cashbookService) GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) ([]*models.Cashbook, int64, error) { +func (s *cashbookService) GetListDebt(ctx context.Context, req erpdto.ListCashbookRequest) ([]*domain.Cashbook, int64, error) { return s.cashbookRepo.GetListDebt(ctx, req) } -func (s *cashbookService) GetOne(ctx context.Context, id string) (*models.Cashbook, error) { +func (s *cashbookService) GetOne(ctx context.Context, id string) (*domain.Cashbook, error) { return s.cashbookRepo.GetOneById(ctx, id) } -func (s *cashbookService) GetCashbookByOrderId(tx *repository.TX, ctx context.Context, orderId string) (*models.Cashbook, error) { +func (s *cashbookService) GetCashbookByOrderId(tx *repository.TX, ctx context.Context, orderId string) (*domain.Cashbook, error) { return s.cashbookRepo.GetCashbookByOrderId(tx, ctx, orderId) } diff --git a/service/category.go b/service/category.go index 7510e5e..01863b9 100644 --- a/service/category.go +++ b/service/category.go @@ -2,9 +2,9 @@ package service import ( "context" + "erp/api/dto/erp" config "erp/config" - "erp/dto/erp" - models "erp/models" + models "erp/domain" repository "erp/repository" "erp/utils" "github.com/pkg/errors" diff --git a/service/category_product.go b/service/category_product.go index 3ab4b8f..47b3c5f 100644 --- a/service/category_product.go +++ b/service/category_product.go @@ -2,15 +2,15 @@ package service import ( "context" + "erp/api/dto/erp" config "erp/config" - erpdto "erp/dto/erp" - models "erp/models" + models "erp/domain" repository "erp/repository" "erp/utils" ) type ( - ERPCategoryProductService interface { + CategoryProductService interface { Create(ctx context.Context, req erpdto.CategoryProductRequest) (*models.CategoryProduct, error) Update(ctx context.Context, req erpdto.CategoryProductRequest) (*models.CategoryProduct, error) Delete(ctx context.Context, id string) error @@ -22,7 +22,7 @@ type ( } ) -func NewCategoryProductService(catProductRepo repository.CategoryProductRepository, config *config.Config) ERPCategoryProductService { +func NewCategoryProductService(catProductRepo repository.CategoryProductRepository, config *config.Config) CategoryProductService { return &CategoryProductServiceImpl{ catProductRepo: catProductRepo, config: config, @@ -33,7 +33,7 @@ func (u *CategoryProductServiceImpl) Create(ctx context.Context, req erpdto.Cate res := models.CategoryProduct{} var err error - if err = utils.Copy(req, res); err != nil { + if err = utils.Copy(&res, &req); err != nil { return nil, err } if err = u.catProductRepo.Create(nil, ctx, &res); err != nil { diff --git a/service/customer.go b/service/customer.go index 3bc8946..60a4baa 100644 --- a/service/customer.go +++ b/service/customer.go @@ -2,9 +2,9 @@ package service import ( "context" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" "github.com/jinzhu/copier" "go.uber.org/zap" @@ -12,10 +12,10 @@ import ( ) type ERPCustomerService interface { - ListCustomer(ctx context.Context, req erpdto.ListCustomerRequest) ([]*models.Customer, *int64, error) - GetOneById(ctx context.Context, id string) (*models.CustomerDetailResponse, error) - CreateCustomer(ctx context.Context, req erpdto.CreateCustomerRequest) (*models.Customer, error) - UpdateCustomer(ctx context.Context, req erpdto.UpdateCustomerRequest) (*models.Customer, error) + ListCustomer(ctx context.Context, req erpdto.ListCustomerRequest) ([]*domain.Customer, *int64, error) + GetOneById(ctx context.Context, id string) (*domain.CustomerDetailResponse, error) + CreateCustomer(ctx context.Context, req erpdto.CreateCustomerRequest) (*domain.Customer, error) + UpdateCustomer(ctx context.Context, req erpdto.UpdateCustomerRequest) (*domain.Customer, error) DeleteCustomer(ctx context.Context, customerId string) error } @@ -37,7 +37,7 @@ func NewCustomerService(erpCustomerRepo repository.ERPCustomerRepository, db *in } } -func (s *erpCustomerService) ListCustomer(ctx context.Context, req erpdto.ListCustomerRequest) ([]*models.Customer, *int64, error) { +func (s *erpCustomerService) ListCustomer(ctx context.Context, req erpdto.ListCustomerRequest) ([]*domain.Customer, *int64, error) { customers, total, err := s.erpCustomerRepo.List(ctx, req) if err != nil { return nil, nil, err @@ -46,7 +46,7 @@ func (s *erpCustomerService) ListCustomer(ctx context.Context, req erpdto.ListCu return customers, total, nil } -func (s *erpCustomerService) GetOneById(ctx context.Context, id string) (*models.CustomerDetailResponse, error) { +func (s *erpCustomerService) GetOneById(ctx context.Context, id string) (*domain.CustomerDetailResponse, error) { customer, err := s.erpCustomerRepo.FindOneByID(ctx, id) if err != nil { return nil, err @@ -62,7 +62,7 @@ func (s *erpCustomerService) GetOneById(ctx context.Context, id string) (*models return nil, err } - output := &models.CustomerDetailResponse{} + output := &domain.CustomerDetailResponse{} if err = copier.Copy(&output, &customer); err != nil { log.Println("Copy struct failed!") @@ -75,8 +75,8 @@ func (s *erpCustomerService) GetOneById(ctx context.Context, id string) (*models return output, nil } -func (s *erpCustomerService) CreateCustomer(ctx context.Context, req erpdto.CreateCustomerRequest) (*models.Customer, error) { - customer := &models.Customer{} +func (s *erpCustomerService) CreateCustomer(ctx context.Context, req erpdto.CreateCustomerRequest) (*domain.Customer, error) { + customer := &domain.Customer{} if err := copier.Copy(&customer, &req); err != nil { log.Println("Copy struct failed!") @@ -91,8 +91,8 @@ func (s *erpCustomerService) CreateCustomer(ctx context.Context, req erpdto.Crea return customer, nil } -func (s *erpCustomerService) UpdateCustomer(ctx context.Context, req erpdto.UpdateCustomerRequest) (*models.Customer, error) { - customer := &models.Customer{} +func (s *erpCustomerService) UpdateCustomer(ctx context.Context, req erpdto.UpdateCustomerRequest) (*domain.Customer, error) { + customer := &domain.Customer{} if err := copier.Copy(&customer, &req); err != nil { log.Println("Copy struct failed!") diff --git a/service/employee_management.go b/service/employee_management.go index 5421a9d..230a5da 100644 --- a/service/employee_management.go +++ b/service/employee_management.go @@ -2,9 +2,9 @@ package service import ( "context" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" "erp/utils" @@ -78,7 +78,7 @@ func (e *erpEmployeeManagementService) CreateRole(ctx context.Context, req erpdt } func (e *erpEmployeeManagementService) CreateEmployee(ctx context.Context, req erpdto.CreateEmployeeRequest) (id string, err error) { - var user *models.User + var user *domain.User err = repository.WithTransaction(e.db, func(tx *repository.TX) error { encryptedPassword, err := bcrypt.GenerateFromPassword( @@ -90,7 +90,7 @@ func (e *erpEmployeeManagementService) CreateEmployee(ctx context.Context, req e return errors.WithStack(err) } - user, err = e.userRepo.Create(tx, ctx, models.User{ + user, err = e.userRepo.Create(tx, ctx, domain.User{ FirstName: req.FirstName, LastName: req.LastName, Email: req.Email, diff --git a/service/jwt.go b/service/jwt.go index e0d8010..48dfe85 100644 --- a/service/jwt.go +++ b/service/jwt.go @@ -1,10 +1,10 @@ package service import ( - "erp/api_errors" + "erp/api/dto/auth" config "erp/config" "erp/constants" - dto "erp/dto/auth" + "erp/utils/api_errors" "time" "github.com/golang-jwt/jwt" diff --git a/service/order.go b/service/order.go index c4cb9ad..d340e64 100644 --- a/service/order.go +++ b/service/order.go @@ -2,13 +2,13 @@ package service import ( "context" - "erp/api_errors" + erpdto2 "erp/api/dto/erp" "erp/constants" - erpdto "erp/dto/erp" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" "erp/utils" + "erp/utils/api_errors" "erp/utils/valid_pointer" "errors" "github.com/jinzhu/copier" @@ -18,12 +18,12 @@ import ( ) type OrderService interface { - CreateFlow(ctx context.Context, req erpdto.CreateOrderRequest) (*models.Order, error) - UpdateFlow(ctx context.Context, req erpdto.UpdateOrderRequest) (*models.Order, error) - GetList(ctx context.Context, req erpdto.GetListOrderRequest) ([]*models.Order, int64, error) - GetOverview(ctx context.Context, req erpdto.GetListOrderRequest) ([]*models.OrderOverview, error) - GetBestSeller(ctx context.Context, req erpdto.GetListOrderRequest) ([]*models.ProductBestSellerResponse, error) - GetOne(ctx context.Context, id string) (*models.Order, error) + CreateFlow(ctx context.Context, req erpdto2.CreateOrderRequest) (*domain.Order, error) + UpdateFlow(ctx context.Context, req erpdto2.UpdateOrderRequest) (*domain.Order, error) + GetList(ctx context.Context, req erpdto2.GetListOrderRequest) ([]*domain.Order, int64, error) + GetOverview(ctx context.Context, req erpdto2.GetListOrderRequest) ([]*domain.OrderOverview, error) + GetBestSeller(ctx context.Context, req erpdto2.GetListOrderRequest) ([]*domain.ProductBestSellerResponse, error) + GetOne(ctx context.Context, id string) (*domain.Order, error) } type orderService struct { @@ -62,7 +62,7 @@ func NewOrderService( } } -func (s *orderService) CreateFlow(ctx context.Context, req erpdto.CreateOrderRequest) (*models.Order, error) { +func (s *orderService) CreateFlow(ctx context.Context, req erpdto2.CreateOrderRequest) (*domain.Order, error) { // get order code req.Code = s.getOrderCode(ctx) @@ -106,7 +106,7 @@ func (s *orderService) CreateFlow(ctx context.Context, req erpdto.CreateOrderReq return nil, err } - order := &models.Order{} + order := &domain.Order{} err = repository.WithTransaction(s.db, func(tx *repository.TX) error { @@ -144,7 +144,7 @@ func (s *orderService) CreateFlow(ctx context.Context, req erpdto.CreateOrderReq return order, err } -func (s *orderService) updateCreateProQuantity(tx *repository.TX, ctx context.Context, products []*models.Product, mapOrderItem map[string]erpdto.OrderItemRequest) error { +func (s *orderService) updateCreateProQuantity(tx *repository.TX, ctx context.Context, products []*domain.Product, mapOrderItem map[string]erpdto2.OrderItemRequest) error { // if quantity is null, only update sold // if quantity is not null, update quantity and sold for _, value := range products { @@ -161,13 +161,13 @@ func (s *orderService) updateCreateProQuantity(tx *repository.TX, ctx context.Co return nil } -func (s *orderService) createUserRevenue(tx *repository.TX, ctx context.Context, req erpdto.CreateOrderRequest) error { +func (s *orderService) createUserRevenue(tx *repository.TX, ctx context.Context, req erpdto2.CreateOrderRequest) error { if req.Payment <= 0 { return nil } now := time.Now() - cashbook := &models.Cashbook{ + cashbook := &domain.Cashbook{ OrderId: valid_pointer.UUIDPointer(req.OrderId), Amount: req.Payment, Status: constants.StatusIn, @@ -180,7 +180,7 @@ func (s *orderService) createUserRevenue(tx *repository.TX, ctx context.Context, return s.cashbookRepo.Create(tx, ctx, cashbook) } -func (s *orderService) updateUserRevenue(tx *repository.TX, ctx context.Context, trans *models.Cashbook, req erpdto.CreateOrderRequest) error { +func (s *orderService) updateUserRevenue(tx *repository.TX, ctx context.Context, trans *domain.Cashbook, req erpdto2.CreateOrderRequest) error { trans.Amount = req.Payment if req.Payment <= 0 { return nil @@ -204,15 +204,15 @@ func (s *orderService) validateTotal(ctx context.Context, requestTotal, calculat return nil } -func (s *orderService) validateOrderItem(orderItems []erpdto.OrderItemRequest, products []*models.Product) error { +func (s *orderService) validateOrderItem(orderItems []erpdto2.OrderItemRequest, products []*domain.Product) error { if len(orderItems) != len(products) { return errors.New(api_errors.ErrOrderItemInvalid) } return nil } -func (s *orderService) create(tx *repository.TX, ctx context.Context, req erpdto.CreateOrderRequest) (*models.Order, error) { - order := &models.Order{} +func (s *orderService) create(tx *repository.TX, ctx context.Context, req erpdto2.CreateOrderRequest) (*domain.Order, error) { + order := &domain.Order{} if err := utils.Copy(order, req); err != nil { return order, err @@ -222,9 +222,9 @@ func (s *orderService) create(tx *repository.TX, ctx context.Context, req erpdto } -func (s *orderService) getProductIdsAndMapOrderItem(ctx context.Context, orderItems []erpdto.OrderItemRequest) ([]string, map[string]erpdto.OrderItemRequest) { +func (s *orderService) getProductIdsAndMapOrderItem(ctx context.Context, orderItems []erpdto2.OrderItemRequest) ([]string, map[string]erpdto2.OrderItemRequest) { productIds := []string{} - mapOrderItem := map[string]erpdto.OrderItemRequest{} + mapOrderItem := map[string]erpdto2.OrderItemRequest{} for _, value := range orderItems { productIds = append(productIds, value.ProductId.String()) mapOrderItem[value.ProductId.String()] = value @@ -241,8 +241,8 @@ func (s *orderService) getCustomer(ctx context.Context, customerId *uuid.UUID) e return nil } -func (s *orderService) handlePayment(tx *repository.TX, ctx context.Context, req erpdto.CreateOrderRequest) error { - if req.Status != erpdto.OrderDelivery && req.Status != erpdto.OrderComplete { +func (s *orderService) handlePayment(tx *repository.TX, ctx context.Context, req erpdto2.CreateOrderRequest) error { + if req.Status != erpdto2.OrderDelivery && req.Status != erpdto2.OrderComplete { return nil } if req.CustomerId == nil { @@ -272,7 +272,7 @@ func (s *orderService) handlePayment(tx *repository.TX, ctx context.Context, req } } else { // create cashbook - cashbook = &models.Cashbook{} + cashbook = &domain.Cashbook{} if err = utils.Copy(&cashbook, req); err != nil { return err } @@ -307,7 +307,7 @@ func (s *orderService) handlePayment(tx *repository.TX, ctx context.Context, req return nil } -func (s *orderService) GetDiscount(ctx context.Context, discountType *erpdto.DiscountType, total, discountReq float64) (float64, error) { +func (s *orderService) GetDiscount(ctx context.Context, discountType *erpdto2.DiscountType, total, discountReq float64) (float64, error) { if discountType == nil { return 0, nil } @@ -334,7 +334,7 @@ func (s *orderService) GetDiscount(ctx context.Context, discountType *erpdto.Dis // check customer_id use promote, is_active, quantity, start_date, end_date, max_amount // check promote_type, get discount_value // update quantity_use, create promote_use -func (s *orderService) PromoteFlow(ctx context.Context, req erpdto.CreateOrderRequest, total float64) (float64, error) { +func (s *orderService) PromoteFlow(ctx context.Context, req erpdto2.CreateOrderRequest, total float64) (float64, error) { // check promote id exist if req.PromoteCode == nil { return 0, nil @@ -381,7 +381,7 @@ func (s *orderService) PromoteFlow(ctx context.Context, req erpdto.CreateOrderRe } // UpdateById promote_use - if err = s.promoteService.CreatePromoteUse(ctx, erpdto.CreatePromoteUseRequest{ + if err = s.promoteService.CreatePromoteUse(ctx, erpdto2.CreatePromoteUseRequest{ CustomerId: req.CustomerId, PromoteCode: req.PromoteCode, }); err != nil { @@ -404,7 +404,7 @@ func (s *orderService) PromoteFlow(ctx context.Context, req erpdto.CreateOrderRe return promoteFee, nil } -func (s *orderService) calculateTotalAmount(ctx context.Context, amount float64, req erpdto.CreateOrderRequest) (float64, error) { +func (s *orderService) calculateTotalAmount(ctx context.Context, amount float64, req erpdto2.CreateOrderRequest) (float64, error) { if utils.ValidFloat64(req.DeliveryFee) < 0 { return 0, errors.New(api_errors.ErrDeliveryFeeInvalid) } @@ -429,7 +429,7 @@ func (s *orderService) calculateTotalAmount(ctx context.Context, amount float64, return total, nil } -func (s *orderService) CalculateAmount(ctx context.Context, products []*models.Product, mapOrderItem map[string]erpdto.OrderItemRequest) (amount float64, costTotal float64, err error) { +func (s *orderService) CalculateAmount(ctx context.Context, products []*domain.Product, mapOrderItem map[string]erpdto2.OrderItemRequest) (amount float64, costTotal float64, err error) { for _, product := range products { if product.Status != constants.ProductStatusActive { return 0.0, 0.0, errors.New(api_errors.ErrProductInvalid) @@ -454,7 +454,7 @@ func (s *orderService) CalculateAmount(ctx context.Context, products []*models.P } // UpdateFlow -func (s *orderService) UpdateFlow(ctx context.Context, req erpdto.UpdateOrderRequest) (*models.Order, error) { +func (s *orderService) UpdateFlow(ctx context.Context, req erpdto2.UpdateOrderRequest) (*domain.Order, error) { // get order order, err := s.erpOrderRepo.GetOneById(ctx, req.OrderId.String()) if err != nil { @@ -468,7 +468,7 @@ func (s *orderService) UpdateFlow(ctx context.Context, req erpdto.UpdateOrderReq // if status == delivery, complete check payment if order.CustomerId != nil { - if err := s.handlePayment(tx, ctx, erpdto.CreateOrderRequest{ + if err := s.handlePayment(tx, ctx, erpdto2.CreateOrderRequest{ OrderId: req.OrderId, Status: req.Status, Payment: req.Payment, @@ -497,7 +497,7 @@ func (s *orderService) UpdateFlow(ctx context.Context, req erpdto.UpdateOrderReq return order, err } -func (s *orderService) updateCancelDebtAndRevenue(tx *repository.TX, ctx context.Context, order *models.Order) error { +func (s *orderService) updateCancelDebtAndRevenue(tx *repository.TX, ctx context.Context, order *domain.Order) error { // get debt debt, err := s.cashbookRepo.GetDebtByOrderId(tx, ctx, order.ID.String()) if err != nil { @@ -522,23 +522,23 @@ func (s *orderService) updateCancelDebtAndRevenue(tx *repository.TX, ctx context return nil } -func (s *orderService) GetList(ctx context.Context, req erpdto.GetListOrderRequest) ([]*models.Order, int64, error) { +func (s *orderService) GetList(ctx context.Context, req erpdto2.GetListOrderRequest) ([]*domain.Order, int64, error) { return s.erpOrderRepo.GetList(ctx, req) } -func (s *orderService) GetOverview(ctx context.Context, req erpdto.GetListOrderRequest) ([]*models.OrderOverview, error) { +func (s *orderService) GetOverview(ctx context.Context, req erpdto2.GetListOrderRequest) ([]*domain.OrderOverview, error) { return s.erpOrderRepo.GetOverview(ctx, req) } -func (s *orderService) GetBestSeller(ctx context.Context, req erpdto.GetListOrderRequest) ([]*models.ProductBestSellerResponse, error) { +func (s *orderService) GetBestSeller(ctx context.Context, req erpdto2.GetListOrderRequest) ([]*domain.ProductBestSellerResponse, error) { return s.erpOrderRepo.GetBestSeller(ctx, req) } -func (s *orderService) GetOne(ctx context.Context, id string) (*models.Order, error) { +func (s *orderService) GetOne(ctx context.Context, id string) (*domain.Order, error) { return s.erpOrderRepo.GetOneById(ctx, id) } -func (s *orderService) checkOrderStatus(ctx context.Context, order *models.Order, req erpdto.UpdateOrderRequest) error { +func (s *orderService) checkOrderStatus(ctx context.Context, order *domain.Order, req erpdto2.UpdateOrderRequest) error { switch order.Status { case constants.Confirm: if req.Status != constants.Delivery && req.Status != constants.Cancel { @@ -558,7 +558,7 @@ func (s *orderService) checkOrderStatus(ctx context.Context, order *models.Order return nil } -func (s *orderService) cancelOrder(tx *repository.TX, ctx context.Context, order *models.Order) error { +func (s *orderService) cancelOrder(tx *repository.TX, ctx context.Context, order *domain.Order) error { // update order order.Status = constants.Cancel if err := s.erpOrderRepo.Update(tx, ctx, order); err != nil { @@ -589,9 +589,9 @@ func (s *orderService) cancelOrder(tx *repository.TX, ctx context.Context, order return nil } -func (s *orderService) mapCancelOrderItem(orderItems []*models.OrderItem) ([]string, map[string]models.OrderItem) { +func (s *orderService) mapCancelOrderItem(orderItems []*domain.OrderItem) ([]string, map[string]domain.OrderItem) { productIds := []string{} - mapOrderItem := map[string]models.OrderItem{} + mapOrderItem := map[string]domain.OrderItem{} for _, value := range orderItems { productIds = append(productIds, value.ProductId.String()) mapOrderItem[value.ProductId.String()] = *value @@ -599,7 +599,7 @@ func (s *orderService) mapCancelOrderItem(orderItems []*models.OrderItem) ([]str return productIds, mapOrderItem } -func (s *orderService) updateCancelProQuantity(tx *repository.TX, ctx context.Context, products []*models.Product, mapOrderItem map[string]models.OrderItem) error { +func (s *orderService) updateCancelProQuantity(tx *repository.TX, ctx context.Context, products []*domain.Product, mapOrderItem map[string]domain.OrderItem) error { // if quantity is null, only update sold // if quantity is not null, update quantity and sold for _, value := range products { diff --git a/service/order_item.go b/service/order_item.go index 343dcc2..ce09c07 100644 --- a/service/order_item.go +++ b/service/order_item.go @@ -2,9 +2,9 @@ package service import ( "context" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" uuid "github.com/satori/go.uuid" "go.uber.org/zap" @@ -12,7 +12,7 @@ import ( type IOrderItemService interface { CreateOrderItemFlow(tx *repository.TX, ctx context.Context, req []erpdto.OrderItemRequest, orderId uuid.UUID) error - GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*models.OrderItem, error) + GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*domain.OrderItem, error) } type orderItemService struct { @@ -37,10 +37,10 @@ func (s *orderItemService) CreateOrderItemFlow(tx *repository.TX, ctx context.Co return s.orderItemRepo.CreateMultiple(tx, ctx, orderItem) } -func (s *orderItemService) mapCreateOrderItem(ctx context.Context, req []erpdto.OrderItemRequest, orderId uuid.UUID) ([]*models.OrderItem, error) { - orderItem := []*models.OrderItem{} +func (s *orderItemService) mapCreateOrderItem(ctx context.Context, req []erpdto.OrderItemRequest, orderId uuid.UUID) ([]*domain.OrderItem, error) { + orderItem := []*domain.OrderItem{} for _, item := range req { - orderItem = append(orderItem, &models.OrderItem{ + orderItem = append(orderItem, &domain.OrderItem{ OrderId: orderId, ProductId: item.ProductId, Quantity: item.Quantity, @@ -50,6 +50,6 @@ func (s *orderItemService) mapCreateOrderItem(ctx context.Context, req []erpdto. return orderItem, nil } -func (s *orderItemService) GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*models.OrderItem, error) { +func (s *orderItemService) GetOrderItemByOrderId(ctx context.Context, orderId string) ([]*domain.OrderItem, error) { return s.orderItemRepo.GetOrderItemByOrderId(ctx, orderId) } diff --git a/service/product.go b/service/product.go index 724726e..9281aac 100644 --- a/service/product.go +++ b/service/product.go @@ -2,10 +2,10 @@ package service import ( "context" + "erp/api/dto/erp" config "erp/config" - erpdto "erp/dto/erp" + models "erp/domain" "erp/infrastructure" - models "erp/models" repository "erp/repository" "erp/utils" "github.com/pkg/errors" diff --git a/service/promote.go b/service/promote.go index e61b5c9..e125604 100644 --- a/service/promote.go +++ b/service/promote.go @@ -2,12 +2,12 @@ package service import ( "context" - "erp/api_errors" + "erp/api/dto/erp" "erp/constants" - erpdto "erp/dto/erp" - "erp/models" + "erp/domain" "erp/repository" "erp/utils" + "erp/utils/api_errors" "github.com/jinzhu/copier" "github.com/pkg/errors" uuid "github.com/satori/go.uuid" @@ -15,12 +15,12 @@ import ( ) type IPromoteService interface { - CreateFlow(ctx context.Context, req erpdto.CreatePromoteRequest) (*models.Promote, error) - GetPromoteById(ctx context.Context, id string) (*models.Promote, error) + CreateFlow(ctx context.Context, req erpdto.CreatePromoteRequest) (*domain.Promote, error) + GetPromoteById(ctx context.Context, id string) (*domain.Promote, error) CountCustomerUsePromote(ctx context.Context, customerId *uuid.UUID, code string) (int64, error) UpdateQuantityUse(ctx context.Context, code string, quantityUse int) error CreatePromoteUse(ctx context.Context, req erpdto.CreatePromoteUseRequest) error - GetPromoteByCode(ctx context.Context, code string) (*models.Promote, error) + GetPromoteByCode(ctx context.Context, code string) (*domain.Promote, error) } type promoteService struct { @@ -33,7 +33,7 @@ func NewPromoteService(promoteRepo repository.IPromoteRepo) IPromoteService { } } -func (s *promoteService) CreateFlow(ctx context.Context, req erpdto.CreatePromoteRequest) (*models.Promote, error) { +func (s *promoteService) CreateFlow(ctx context.Context, req erpdto.CreatePromoteRequest) (*domain.Promote, error) { promote, err := s.promoteRepo.GetPromoteByCode(ctx, req.Code) if err != nil { if !utils.ErrNoRows(err) { @@ -51,7 +51,7 @@ func (s *promoteService) CreateFlow(ctx context.Context, req erpdto.CreatePromot } } - promote = &models.Promote{} + promote = &domain.Promote{} if err := copier.Copy(promote, &req); err != nil { log.Println("Copy struct failed!") return nil, err @@ -64,11 +64,11 @@ func (s *promoteService) CreateFlow(ctx context.Context, req erpdto.CreatePromot return promote, nil } -func (s *promoteService) GetPromoteById(ctx context.Context, id string) (*models.Promote, error) { +func (s *promoteService) GetPromoteById(ctx context.Context, id string) (*domain.Promote, error) { return s.promoteRepo.GetPromoteById(ctx, id) } -func (s *promoteService) GetPromoteByCode(ctx context.Context, code string) (*models.Promote, error) { +func (s *promoteService) GetPromoteByCode(ctx context.Context, code string) (*domain.Promote, error) { return s.promoteRepo.GetPromoteByCode(ctx, code) } @@ -80,7 +80,7 @@ func (s *promoteService) UpdateQuantityUse(ctx context.Context, code string, qua } func (s *promoteService) CreatePromoteUse(ctx context.Context, req erpdto.CreatePromoteUseRequest) error { - promoteUse := &models.PromoteUse{} + promoteUse := &domain.PromoteUse{} if err := copier.Copy(&promoteUse, &req); err != nil { return err } diff --git a/service/store.go b/service/store.go index 7a1821b..8b460bf 100644 --- a/service/store.go +++ b/service/store.go @@ -2,12 +2,12 @@ package service import ( "context" - "erp/api_errors" - erpdto "erp/dto/erp" + "erp/api/dto/erp" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" "erp/utils" + "erp/utils/api_errors" "github.com/pkg/errors" uuid "github.com/satori/go.uuid" @@ -15,9 +15,9 @@ import ( ) type ERPStoreService interface { - CreateStoreAndAssignOwner(ctx context.Context, req erpdto.CreateStoreRequest) (*models.Store, error) - UpdateStore(ctx context.Context, storeID string, req erpdto.UpdateStoreRequest) (*models.Store, error) - ListStore(ctx context.Context, req erpdto.ListStoreRequest) ([]*models.Store, *int64, error) + CreateStoreAndAssignOwner(ctx context.Context, req erpdto.CreateStoreRequest) (*domain.Store, error) + UpdateStore(ctx context.Context, storeID string, req erpdto.UpdateStoreRequest) (*domain.Store, error) + ListStore(ctx context.Context, req erpdto.ListStoreRequest) ([]*domain.Store, *int64, error) DeleteStore(ctx context.Context, storeID string) error } @@ -37,12 +37,12 @@ func NewStoreService(erpStoreRepo repository.ERPStoreRepository, erpRoleRepo rep } } -func (p *erpStoreService) CreateStoreAndAssignOwner(ctx context.Context, req erpdto.CreateStoreRequest) (*models.Store, error) { +func (p *erpStoreService) CreateStoreAndAssignOwner(ctx context.Context, req erpdto.CreateStoreRequest) (*domain.Store, error) { ownerID, err := utils.GetUserUUIDFromContext(ctx) if err != nil { return nil, err } - store := &models.Store{ + store := &domain.Store{ Name: req.Name, Avatar: req.Avatar, Thumbnail: req.Thumbnail, @@ -81,8 +81,8 @@ func (p *erpStoreService) CreateStoreAndAssignOwner(ctx context.Context, req erp return store, nil } -func (p *erpStoreService) UpdateStore(ctx context.Context, storeID string, req erpdto.UpdateStoreRequest) (*models.Store, error) { - u := &models.Store{ +func (p *erpStoreService) UpdateStore(ctx context.Context, storeID string, req erpdto.UpdateStoreRequest) (*domain.Store, error) { + u := &domain.Store{ Name: req.Name, Avatar: req.Avatar, Thumbnail: req.Thumbnail, @@ -104,7 +104,7 @@ func (p *erpStoreService) UpdateStore(ctx context.Context, storeID string, req e return store, nil } -func (p *erpStoreService) ListStore(ctx context.Context, req erpdto.ListStoreRequest) ([]*models.Store, *int64, error) { +func (p *erpStoreService) ListStore(ctx context.Context, req erpdto.ListStoreRequest) ([]*domain.Store, *int64, error) { userID := utils.GetUserStringIDFromContext(ctx) _, err := p.erpStoreRepo.FindByID(ctx, userID) diff --git a/service/transaction_category.go b/service/transaction_category.go index 2bd41bb..7430e94 100644 --- a/service/transaction_category.go +++ b/service/transaction_category.go @@ -2,20 +2,20 @@ package service import ( "context" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" "github.com/jinzhu/copier" "go.uber.org/zap" ) type TransactionCategoryService interface { - Create(tx *repository.TX, ctx context.Context, req erpdto.CreateTransactionCategoryRequest) (*models.CashbookCategory, error) - Update(ctx context.Context, req erpdto.UpdateTransactionCategoryRequest) (*models.CashbookCategory, error) - GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) ([]*models.CashbookCategory, int64, error) + Create(tx *repository.TX, ctx context.Context, req erpdto.CreateTransactionCategoryRequest) (*domain.CashbookCategory, error) + Update(ctx context.Context, req erpdto.UpdateTransactionCategoryRequest) (*domain.CashbookCategory, error) + GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) ([]*domain.CashbookCategory, int64, error) Delete(ctx context.Context, transactionCategoryID string) error - GetOne(ctx context.Context, id string) (*models.CashbookCategory, error) + GetOne(ctx context.Context, id string) (*domain.CashbookCategory, error) } type transactionCategoryService struct { @@ -32,8 +32,8 @@ func NewTransactionCategoryService(transactionCategoryRepo repository.Transactio } } -func (p *transactionCategoryService) Create(tx *repository.TX, ctx context.Context, req erpdto.CreateTransactionCategoryRequest) (*models.CashbookCategory, error) { - output := &models.CashbookCategory{} +func (p *transactionCategoryService) Create(tx *repository.TX, ctx context.Context, req erpdto.CreateTransactionCategoryRequest) (*domain.CashbookCategory, error) { + output := &domain.CashbookCategory{} if err := copier.Copy(&output, &req); err != nil { return nil, err } @@ -44,7 +44,7 @@ func (p *transactionCategoryService) Create(tx *repository.TX, ctx context.Conte return output, nil } -func (p *transactionCategoryService) Update(ctx context.Context, req erpdto.UpdateTransactionCategoryRequest) (*models.CashbookCategory, error) { +func (p *transactionCategoryService) Update(ctx context.Context, req erpdto.UpdateTransactionCategoryRequest) (*domain.CashbookCategory, error) { output, err := p.transactionCategoryRepo.GetOneById(ctx, req.Id.String()) if err != nil { return nil, err @@ -60,11 +60,11 @@ func (p *transactionCategoryService) Update(ctx context.Context, req erpdto.Upda return output, nil } -func (p *transactionCategoryService) GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) ([]*models.CashbookCategory, int64, error) { +func (p *transactionCategoryService) GetList(ctx context.Context, req erpdto.ListTransactionCategoryRequest) ([]*domain.CashbookCategory, int64, error) { return p.transactionCategoryRepo.GetList(ctx, req) } -func (p *transactionCategoryService) GetOne(ctx context.Context, id string) (*models.CashbookCategory, error) { +func (p *transactionCategoryService) GetOne(ctx context.Context, id string) (*domain.CashbookCategory, error) { return p.transactionCategoryRepo.GetOneById(ctx, id) } diff --git a/service/user.go b/service/user.go index 4907c69..44120cc 100644 --- a/service/user.go +++ b/service/user.go @@ -3,7 +3,7 @@ package service import ( "context" config "erp/config" - models "erp/models" + models "erp/domain" repository "erp/repository" "gorm.io/gorm" diff --git a/service/wallet.go b/service/wallet.go index 9f96df2..fc649e4 100644 --- a/service/wallet.go +++ b/service/wallet.go @@ -2,22 +2,22 @@ package service import ( "context" - "erp/api_errors" - erpdto "erp/dto/finance" + erpdto "erp/api/dto/finance" + "erp/domain" "erp/infrastructure" - "erp/models" "erp/repository" + "erp/utils/api_errors" "github.com/jinzhu/copier" "github.com/pkg/errors" "go.uber.org/zap" ) type WalletService interface { - Create(tx *repository.TX, ctx context.Context, req erpdto.CreateWalletRequest) (*models.Wallet, error) - Update(ctx context.Context, req erpdto.UpdateWalletRequest) (*models.Wallet, error) - GetList(ctx context.Context, req erpdto.ListWalletRequest) ([]*models.Wallet, int64, error) + Create(tx *repository.TX, ctx context.Context, req erpdto.CreateWalletRequest) (*domain.Wallet, error) + Update(ctx context.Context, req erpdto.UpdateWalletRequest) (*domain.Wallet, error) + GetList(ctx context.Context, req erpdto.ListWalletRequest) ([]*domain.Wallet, int64, error) Delete(ctx context.Context, walletID string) error - GetOne(ctx context.Context, id string) (*models.Wallet, error) + GetOne(ctx context.Context, id string) (*domain.Wallet, error) } type walletService struct { @@ -34,13 +34,13 @@ func NewWalletService(walletRepo repository.WalletRepository, db *infrastructure } } -func (p *walletService) Create(tx *repository.TX, ctx context.Context, req erpdto.CreateWalletRequest) (*models.Wallet, error) { +func (p *walletService) Create(tx *repository.TX, ctx context.Context, req erpdto.CreateWalletRequest) (*domain.Wallet, error) { // check if wallet name is already exist if _, err := p.walletRepo.GetOneByName(ctx, req.Name); err == nil { return nil, errors.New(api_errors.ErrWalletNameAlreadyExist) } - output := &models.Wallet{} + output := &domain.Wallet{} if err := copier.Copy(&output, &req); err != nil { return nil, err } @@ -58,7 +58,7 @@ func (p *walletService) Create(tx *repository.TX, ctx context.Context, req erpdt return output, nil } -func (p *walletService) Update(ctx context.Context, req erpdto.UpdateWalletRequest) (*models.Wallet, error) { +func (p *walletService) Update(ctx context.Context, req erpdto.UpdateWalletRequest) (*domain.Wallet, error) { output, err := p.walletRepo.GetOneById(ctx, req.Id.String()) if err != nil { return nil, err @@ -81,11 +81,11 @@ func (p *walletService) Update(ctx context.Context, req erpdto.UpdateWalletReque return output, nil } -func (p *walletService) GetList(ctx context.Context, req erpdto.ListWalletRequest) ([]*models.Wallet, int64, error) { +func (p *walletService) GetList(ctx context.Context, req erpdto.ListWalletRequest) ([]*domain.Wallet, int64, error) { return p.walletRepo.GetList(ctx, req) } -func (p *walletService) GetOne(ctx context.Context, id string) (*models.Wallet, error) { +func (p *walletService) GetOne(ctx context.Context, id string) (*domain.Wallet, error) { return p.walletRepo.GetOneById(ctx, id) } diff --git a/test/permission_test.go b/test/permission_test.go index 8bf701c..2325a6a 100644 --- a/test/permission_test.go +++ b/test/permission_test.go @@ -1,7 +1,7 @@ package test import ( - "erp/models" + "erp/domain" erpservice "erp/service" "testing" @@ -32,9 +32,9 @@ func TestListPermission(t *testing.T) { type MockPermissionRepo struct { } -func (*MockPermissionRepo) List() ([]*models.Permission, *int64, error) { +func (*MockPermissionRepo) List() ([]*domain.Permission, *int64, error) { total := int64(3) - return []*models.Permission{ + return []*domain.Permission{ {ID: uuid.NewV4(), Name: "permission1"}, {ID: uuid.NewV4(), Name: "permission2"}, {ID: uuid.NewV4(), Name: "permission3"}, diff --git a/api_errors/errors.go b/utils/api_errors/errors.go similarity index 100% rename from api_errors/errors.go rename to utils/api_errors/errors.go diff --git a/utils/http.go b/utils/http.go index ecbcc1d..4b14c06 100644 --- a/utils/http.go +++ b/utils/http.go @@ -2,7 +2,7 @@ package utils import ( "context" - "erp/api_errors" + "erp/utils/api_errors" "errors" "github.com/gin-gonic/gin"