46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
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,
|
|
}
|
|
}
|