feat: implement component-item management with CRUD operations and status updates

This commit is contained in:
Tran Anh Tuan
2026-05-11 17:49:18 +07:00
parent 9ea72b4eea
commit 0ff65a18c0
23 changed files with 3870 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package models
import (
"encoding/json"
"time"
)
type ComponentItem struct {
ID int64 `json:"id"`
ComponentID int64 `json:"componentId"`
ContainerID int64 `json:"containerId"`
Quantity int32 `json:"quantity"`
Status string `json:"status"`
Metadata json.RawMessage `json:"metadata"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// UpdateStatusResult holds the results of a component item status change operation.
// Different fields are populated depending on the case:
// - Case 1 (change all): only ComponentItem and StatusHistory are set
// - Case 2 (split): NewComponentItemID is also set
// - Case 3 (merge): MergedComponentItemID is also set
type UpdateStatusResult struct {
ComponentItem ComponentItem
StatusHistory ComponentStatusHistory
NewComponentItemID *int64
MergedComponentItemID *int64
}
type FindComponentItemResult struct {
ComponentName string `json:"componentName"`
TypeName string `json:"typeName"`
Quantity int32 `json:"quantity"`
Status string `json:"status"`
ContainerName string `json:"containerName"`
ContainerType string `json:"containerType"`
ShelfName string `json:"shelfName"`
CabinetName string `json:"cabinetName"`
RoomName string `json:"roomName"`
WarehouseName string `json:"warehouseName"`
}

View File

@@ -0,0 +1,14 @@
package models
import "time"
type ComponentStatusHistory struct {
ID int64 `json:"id"`
ComponentItemID int64 `json:"componentItemId"`
OldStatus string `json:"oldStatus"`
NewStatus string `json:"newStatus"`
ChangedQuantity int32 `json:"changedQuantity"`
Note string `json:"note"`
ChangedBy string `json:"changedBy"`
ChangedAt time.Time `json:"changedAt"`
}

View File

@@ -0,0 +1,24 @@
package requests
import "encoding/json"
type CreateComponentItemRequest struct {
ComponentID int64 `json:"componentId" binding:"required"`
ContainerID int64 `json:"containerId" binding:"required"`
Quantity int32 `json:"quantity" binding:"required"`
Status string `json:"status" binding:"required"`
Metadata json.RawMessage `json:"metadata"`
}
type UpdateComponentItemRequest struct {
ComponentID *int64 `json:"componentId"`
ContainerID *int64 `json:"containerId"`
Metadata json.RawMessage `json:"metadata"`
}
// UpdateComponentItemStatusRequest represents the request body for changing the status of a component item.
type UpdateComponentItemStatusRequest struct {
Status string `json:"status" binding:"required,oneof=normal damaged long_unused expired pending_inspection"`
ChangedQuantity *int32 `json:"changedQuantity"`
Note string `json:"note"`
}

View File

@@ -0,0 +1,8 @@
package requests
type CreateComponentStatusHistoryRequest struct {
OldStatus string `json:"oldStatus"`
NewStatus string `json:"newStatus" binding:"required"`
ChangedQuantity *int32 `json:"changedQuantity"`
Note string `json:"note"`
}

View File

@@ -0,0 +1,28 @@
package responses
import "encoding/json"
type CreateComponentItemResponse struct {
ID int64 `json:"id"`
}
type UpdateComponentItemResponse struct {
ID int64 `json:"id"`
ComponentID int64 `json:"componentId"`
ContainerID int64 `json:"containerId"`
Quantity int32 `json:"quantity"`
Status string `json:"status"`
Metadata json.RawMessage `json:"metadata"`
}
// UpdateComponentItemStatusResponse represents the response for a status change operation.
// Different fields are populated depending on the case (change all, split, merge).
type UpdateComponentItemStatusResponse struct {
ID int64 `json:"id"`
OldStatus string `json:"oldStatus"`
NewStatus string `json:"newStatus"`
ChangedQuantity int32 `json:"changedQuantity"`
HistoryID int64 `json:"historyId"`
NewComponentItemID *int64 `json:"newComponentItemId,omitempty"`
MergedComponentItemID *int64 `json:"mergedComponentItemId,omitempty"`
}

View File

@@ -0,0 +1,5 @@
package responses
type CreateComponentStatusHistoryResponse struct {
ID int64 `json:"id"`
}