feat: implement component-item management with CRUD operations and status updates
This commit is contained in:
42
internal/models/component_item_model.go
Normal file
42
internal/models/component_item_model.go
Normal 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"`
|
||||
}
|
||||
14
internal/models/component_status_history_model.go
Normal file
14
internal/models/component_status_history_model.go
Normal 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"`
|
||||
}
|
||||
24
internal/models/requests/component_item_request.go
Normal file
24
internal/models/requests/component_item_request.go
Normal 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"`
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
28
internal/models/responses/component_item_response.go
Normal file
28
internal/models/responses/component_item_response.go
Normal 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"`
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package responses
|
||||
|
||||
type CreateComponentStatusHistoryResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
Reference in New Issue
Block a user