feat: implement component-item management with CRUD operations and status updates
This commit is contained in:
56
internal/mapper/component_item_mapper.go
Normal file
56
internal/mapper/component_item_mapper.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package mapper
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"wm-backend/internal/models"
|
||||
db "wm-backend/sqlc_gen"
|
||||
)
|
||||
|
||||
func ToDomainComponentItem(r db.ComponentItem) *models.ComponentItem {
|
||||
return &models.ComponentItem{
|
||||
ID: r.ID,
|
||||
ComponentID: r.ComponentID,
|
||||
ContainerID: r.ContainerID,
|
||||
Quantity: r.Quantity,
|
||||
Status: string(r.Status),
|
||||
Metadata: json.RawMessage(r.Metadata),
|
||||
CreatedAt: r.CreatedAt,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ToModelComponentItem(r *models.ComponentItem) *db.CreateComponentItemParams {
|
||||
return &db.CreateComponentItemParams{
|
||||
ComponentID: r.ComponentID,
|
||||
ContainerID: r.ContainerID,
|
||||
Quantity: r.Quantity,
|
||||
Status: db.ComponentItemStatusEnum(r.Status),
|
||||
Metadata: []byte(r.Metadata),
|
||||
CreatedAt: r.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ToUpdateModelComponentItem(r *models.ComponentItem) *db.UpdateComponentItemParams {
|
||||
return &db.UpdateComponentItemParams{
|
||||
ComponentID: r.ComponentID,
|
||||
ContainerID: r.ContainerID,
|
||||
Metadata: []byte(r.Metadata),
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
ID: r.ID,
|
||||
}
|
||||
}
|
||||
|
||||
func ToDomainFindComponentItem(r db.FindComponentItemRow) *models.FindComponentItemResult {
|
||||
return &models.FindComponentItemResult{
|
||||
ComponentName: r.ComponentName,
|
||||
TypeName: r.TypeName,
|
||||
Quantity: r.Quantity,
|
||||
Status: string(r.Status),
|
||||
ContainerName: r.ContainerName,
|
||||
ContainerType: string(r.ContainerType),
|
||||
ShelfName: r.ShelfName,
|
||||
CabinetName: r.CabinetName,
|
||||
RoomName: r.RoomName,
|
||||
WarehouseName: r.WarehouseName,
|
||||
}
|
||||
}
|
||||
45
internal/mapper/component_status_history_mapper.go
Normal file
45
internal/mapper/component_status_history_mapper.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package mapper
|
||||
|
||||
import (
|
||||
"wm-backend/internal/models"
|
||||
db "wm-backend/sqlc_gen"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func ToDomainComponentStatusHistory(r db.ComponentStatusHistory) *models.ComponentStatusHistory {
|
||||
return &models.ComponentStatusHistory{
|
||||
ID: r.ID,
|
||||
ComponentItemID: r.ComponentItemID,
|
||||
OldStatus: string(r.OldStatus.ComponentItemStatusEnum),
|
||||
NewStatus: string(r.NewStatus),
|
||||
ChangedQuantity: r.ChangedQuantity.Int32,
|
||||
Note: r.Note.String,
|
||||
ChangedBy: r.ChangedBy.String,
|
||||
ChangedAt: r.ChangedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ToModelComponentStatusHistory(r *models.ComponentStatusHistory) *db.CreateComponentStatusHistoryParams {
|
||||
return &db.CreateComponentStatusHistoryParams{
|
||||
ComponentItemID: r.ComponentItemID,
|
||||
OldStatus: db.NullComponentItemStatusEnum{
|
||||
ComponentItemStatusEnum: db.ComponentItemStatusEnum(r.OldStatus),
|
||||
Valid: r.OldStatus != "",
|
||||
},
|
||||
NewStatus: db.ComponentItemStatusEnum(r.NewStatus),
|
||||
ChangedQuantity: pgtype.Int4{
|
||||
Int32: r.ChangedQuantity,
|
||||
Valid: r.ChangedQuantity != 0,
|
||||
},
|
||||
Note: pgtype.Text{
|
||||
String: r.Note,
|
||||
Valid: r.Note != "",
|
||||
},
|
||||
ChangedBy: pgtype.Text{
|
||||
String: r.ChangedBy,
|
||||
Valid: r.ChangedBy != "",
|
||||
},
|
||||
ChangedAt: r.ChangedAt,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user