feat(warehouse): Update warehouse entity and DTO to include PICID and related changes in controller

This commit is contained in:
Habib Fatkhul Rohman 2025-11-10 14:40:37 +07:00
parent c7a36f0bbd
commit e0275ee82c
3 changed files with 50 additions and 23 deletions

View File

@ -10,9 +10,11 @@ type MWarehouseEntity struct {
Status string `gorm:"type:varchar(50);not null;" json:"status"`
DissallowNegativeInventory bool `gorm:"type:boolean;default:false;" json:"dissallow_negative_inventory"`
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"`
PIC M_User `gorm:"foreignKey:PICID;references:ID"`
FullAuditTrail
}

View File

@ -27,9 +27,9 @@ type warehouseController struct {
}
func (w *warehouseController) Create(ctx *gin.Context) {
clientId := ctx.MustGet("client_id").(string)
// clientId := ctx.MustGet("client_id").(string)
var req dto.WarehouseCreateRequest
req.ClientID = clientId
// req.ClientID = clientId
if err := ctx.ShouldBindJSON(&req); err != nil {
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
ctx.JSON(http.StatusBadRequest, res)
@ -95,13 +95,33 @@ func (w *warehouseController) GetAll(ctx *gin.Context) {
ctx.JSON(http.StatusBadRequest, res)
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)
if err != nil {
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_WAREHOUSE, err.Error(), nil)
ctx.JSON(http.StatusInternalServerError, res)
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)
}

View File

@ -2,6 +2,8 @@ package dto
import (
"errors"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
)
const (
@ -29,6 +31,7 @@ type WarehouseCreateRequest struct {
Description string `json:"description"`
Status string `json:"status" binding:"required"`
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
PICID *string `json:"pic_id"`
ClientID string `json:"client_id" binding:"required"`
}
@ -38,6 +41,7 @@ type WarehouseUpdateRequest struct {
Description string `json:"description"`
Status string `json:"status"`
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
PICID *string `json:"pic_id"`
ClientID string `json:"client_id"`
}
@ -49,4 +53,5 @@ type WarehouseResponse struct {
Status string `json:"status"`
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
ClientID string `json:"client_id"`
PIC *pkgdto.IdNameResponse `json:"pic"`
}