feat(warehouse): Update warehouse entity and DTO to include PICID and related changes in controller
This commit is contained in:
parent
c7a36f0bbd
commit
e0275ee82c
|
|
@ -10,9 +10,11 @@ type MWarehouseEntity struct {
|
||||||
Status string `gorm:"type:varchar(50);not null;" json:"status"`
|
Status string `gorm:"type:varchar(50);not null;" json:"status"`
|
||||||
DissallowNegativeInventory bool `gorm:"type:boolean;default:false;" json:"dissallow_negative_inventory"`
|
DissallowNegativeInventory bool `gorm:"type:boolean;default:false;" json:"dissallow_negative_inventory"`
|
||||||
|
|
||||||
ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"`
|
PICID *uuid.UUID `gorm:"type:uuid;index;" json:"pic_id"`
|
||||||
|
ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"`
|
||||||
|
|
||||||
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
|
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
|
||||||
|
PIC M_User `gorm:"foreignKey:PICID;references:ID"`
|
||||||
|
|
||||||
FullAuditTrail
|
FullAuditTrail
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ type warehouseController struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *warehouseController) Create(ctx *gin.Context) {
|
func (w *warehouseController) Create(ctx *gin.Context) {
|
||||||
clientId := ctx.MustGet("client_id").(string)
|
// clientId := ctx.MustGet("client_id").(string)
|
||||||
var req dto.WarehouseCreateRequest
|
var req dto.WarehouseCreateRequest
|
||||||
req.ClientID = clientId
|
// req.ClientID = clientId
|
||||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
|
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
|
||||||
ctx.JSON(http.StatusBadRequest, res)
|
ctx.JSON(http.StatusBadRequest, res)
|
||||||
|
|
@ -95,13 +95,33 @@ func (w *warehouseController) GetAll(ctx *gin.Context) {
|
||||||
ctx.JSON(http.StatusBadRequest, res)
|
ctx.JSON(http.StatusBadRequest, res)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAll := ctx.Query("get_all")
|
||||||
|
if getAll != "" {
|
||||||
|
warehouses, _, err := w.warehouseService.GetAll(ctx, filter)
|
||||||
|
if err != nil {
|
||||||
|
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_WAREHOUSE, err.Error(), nil)
|
||||||
|
ctx.JSON(http.StatusBadRequest, res)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_GET_WAREHOUSE, warehouses)
|
||||||
|
ctx.JSON(http.StatusOK, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ambil limit & offset dari query param (default: limit=10, offset=0)
|
||||||
|
perPage := utils.ParseInt(ctx.DefaultQuery("per_page", "10"))
|
||||||
|
page := utils.ParseInt(ctx.DefaultQuery("page", "1"))
|
||||||
|
filter.PerPage = perPage
|
||||||
|
filter.Page = (page - 1) * perPage
|
||||||
warehouses, total, err := w.warehouseService.GetAll(ctx, filter)
|
warehouses, total, err := w.warehouseService.GetAll(ctx, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_WAREHOUSE, err.Error(), nil)
|
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_WAREHOUSE, err.Error(), nil)
|
||||||
ctx.JSON(http.StatusInternalServerError, res)
|
ctx.JSON(http.StatusInternalServerError, res)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_GET_WAREHOUSE, gin.H{"data": warehouses, "total": total})
|
paginationResponse := utils.BuildPaginationResponse(perPage, page, total)
|
||||||
|
res := utils.BuildResponseSuccessWithPagination(http.StatusOK, dto.MESSAGE_SUCCESS_GET_WAREHOUSE, warehouses, paginationResponse)
|
||||||
ctx.JSON(http.StatusOK, res)
|
ctx.JSON(http.StatusOK, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -24,29 +26,32 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type WarehouseCreateRequest struct {
|
type WarehouseCreateRequest struct {
|
||||||
Code string `json:"code" binding:"required"`
|
Code string `json:"code" binding:"required"`
|
||||||
Name string `json:"name" binding:"required"`
|
Name string `json:"name" binding:"required"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Status string `json:"status" binding:"required"`
|
Status string `json:"status" binding:"required"`
|
||||||
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
||||||
ClientID string `json:"client_id" binding:"required"`
|
PICID *string `json:"pic_id"`
|
||||||
|
ClientID string `json:"client_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WarehouseUpdateRequest struct {
|
type WarehouseUpdateRequest struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
||||||
ClientID string `json:"client_id"`
|
PICID *string `json:"pic_id"`
|
||||||
|
ClientID string `json:"client_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WarehouseResponse struct {
|
type WarehouseResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
||||||
ClientID string `json:"client_id"`
|
ClientID string `json:"client_id"`
|
||||||
|
PIC *pkgdto.IdNameResponse `json:"pic"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue