feat: implement component-item management with CRUD operations and status updates
This commit is contained in:
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