Skip to content

Commit

Permalink
[sprint-1][EA-3] category: get total product
Browse files Browse the repository at this point in the history
  • Loading branch information
Duchieuctk41 committed Jan 25, 2024
1 parent 7e2c2f8 commit d4edacf
Show file tree
Hide file tree
Showing 85 changed files with 491 additions and 406 deletions.
2 changes: 1 addition & 1 deletion api/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions api/controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package controller

import (
"erp/api"
dto "erp/dto/auth"
dto2 "erp/api/dto/auth"
service "erp/service"
"net/http"

Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/cashbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/cashbook_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
75 changes: 75 additions & 0 deletions api/controllers/category_product.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion api/controllers/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/employee_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package controller

import (
"erp/api"
erpdto "erp/dto/erp"
"erp/api/dto/erp"
"erp/lib"
erpservice "erp/service"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ var Module = fx.Options(
NewERPCategoryController, NewERPCustomerController, NewERPEmployeeManagementController,
NewERPProductController, NewERPStoreController, NewOrderController, NewPromoteController,
NewCashbookController, NewTransactionCategoryController, NewWalletController,
NewBudgetController,
NewBudgetController, NewCategoryProductController,
))
4 changes: 2 additions & 2 deletions api/controllers/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package controller

import (
"erp/api"
erpdto "erp/dto/erp"
"erp/api/dto/erp"
erpservice "erp/service"
"erp/utils"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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"`
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions dto/finance/budget.go → api/dto/finance/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package finance

import (
"erp/api/request"
"erp/models"
"erp/domain"
uuid "github.com/satori/go.uuid"
"time"
)
Expand Down Expand Up @@ -31,6 +31,6 @@ type ListBudgetRequest struct {
}

type BudgetResponse struct {
models.Budget
domain.Budget
Spent float64 `json:"spent"`
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions api/middlewares/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"),
// })
Expand All @@ -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"),
// })
Expand All @@ -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"),
// })
Expand Down
2 changes: 1 addition & 1 deletion models/base.go → domain/base.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import (
"gorm.io/gorm"
Expand Down
2 changes: 1 addition & 1 deletion models/budget.go → domain/budget.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import (
uuid "github.com/satori/go.uuid"
Expand Down
9 changes: 4 additions & 5 deletions models/category.go → domain/category.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion models/category_product.go → domain/category_product.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import uuid "github.com/satori/go.uuid"

Expand Down
2 changes: 1 addition & 1 deletion models/customer.go → domain/customer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

type Customer struct {
BaseModel
Expand Down
2 changes: 1 addition & 1 deletion models/debt.go → domain/debt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion models/order.go → domain/order.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import uuid "github.com/satori/go.uuid"

Expand Down
2 changes: 1 addition & 1 deletion models/order_item.go → domain/order_item.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import uuid "github.com/satori/go.uuid"

Expand Down
2 changes: 1 addition & 1 deletion models/permission.go → domain/permission.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import uuid "github.com/satori/go.uuid"

Expand Down
2 changes: 1 addition & 1 deletion models/product.go → domain/product.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import (
uuid "github.com/satori/go.uuid"
Expand Down
2 changes: 1 addition & 1 deletion models/promote.go → domain/promote.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import (
uuid "github.com/satori/go.uuid"
Expand Down
2 changes: 1 addition & 1 deletion models/role.go → domain/role.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import (
uuid "github.com/satori/go.uuid"
Expand Down
2 changes: 1 addition & 1 deletion models/store.go → domain/store.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

type Store struct {
BaseModel
Expand Down
2 changes: 1 addition & 1 deletion models/transaction.go → domain/transaction.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package domain

import (
"github.com/lib/pq"
Expand Down
Loading

0 comments on commit d4edacf

Please sign in to comment.