diff --git a/database/entities/m_warehouse_entity.go b/database/entities/m_warehouse_entity.go index 2024e3a..8b9147a 100644 --- a/database/entities/m_warehouse_entity.go +++ b/database/entities/m_warehouse_entity.go @@ -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"` - 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"` + PIC M_User `gorm:"foreignKey:PICID;references:ID"` FullAuditTrail } diff --git a/modules/warehouse/controller/warehouse_controller.go b/modules/warehouse/controller/warehouse_controller.go index da4920f..30a99ed 100644 --- a/modules/warehouse/controller/warehouse_controller.go +++ b/modules/warehouse/controller/warehouse_controller.go @@ -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) } diff --git a/modules/warehouse/dto/warehouse_dto.go b/modules/warehouse/dto/warehouse_dto.go index 2805b25..3b3b56c 100644 --- a/modules/warehouse/dto/warehouse_dto.go +++ b/modules/warehouse/dto/warehouse_dto.go @@ -2,6 +2,8 @@ package dto import ( "errors" + + pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto" ) const ( @@ -24,29 +26,32 @@ var ( ) type WarehouseCreateRequest struct { - Code string `json:"code" binding:"required"` - Name string `json:"name" binding:"required"` - Description string `json:"description"` - Status string `json:"status" binding:"required"` - DissallowNegativeInventory bool `json:"dissallow_negative_inventory"` - ClientID string `json:"client_id" binding:"required"` + Code string `json:"code" binding:"required"` + Name string `json:"name" binding:"required"` + 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"` } type WarehouseUpdateRequest struct { - Code string `json:"code"` - Name string `json:"name"` - Description string `json:"description"` - Status string `json:"status"` - DissallowNegativeInventory bool `json:"dissallow_negative_inventory"` - ClientID string `json:"client_id"` + Code string `json:"code"` + Name string `json:"name"` + Description string `json:"description"` + Status string `json:"status"` + DissallowNegativeInventory bool `json:"dissallow_negative_inventory"` + PICID *string `json:"pic_id"` + ClientID string `json:"client_id"` } type WarehouseResponse struct { - ID string `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Description string `json:"description"` - Status string `json:"status"` - DissallowNegativeInventory bool `json:"dissallow_negative_inventory"` - ClientID string `json:"client_id"` + ID string `json:"id"` + Code string `json:"code"` + Name string `json:"name"` + Description string `json:"description"` + Status string `json:"status"` + DissallowNegativeInventory bool `json:"dissallow_negative_inventory"` + ClientID string `json:"client_id"` + PIC *pkgdto.IdNameResponse `json:"pic"` }