Files
apskel-pos-backend/internal/transformer/category_transformer.go
T

74 lines
2.0 KiB
Go
Raw Normal View History

2025-07-18 20:10:29 +07:00
package transformer
import (
"apskel-pos-be/internal/appcontext"
"apskel-pos-be/internal/contract"
"apskel-pos-be/internal/models"
)
func CreateCategoryRequestToModel(apctx *appcontext.ContextInfo, req *contract.CreateCategoryRequest) *models.CreateCategoryRequest {
2026-05-21 21:27:57 +07:00
order := 0
if req.Order != nil {
order = *req.Order
}
2025-07-18 20:10:29 +07:00
return &models.CreateCategoryRequest{
2026-10-02 23:30:03 +07:00
OrganizationID: apctx.OrganizationID,
OutletID: req.OutletID,
ParentID: req.ParentID,
Name: req.Name,
Description: req.Description,
ImageURL: nil,
Order: order,
OwnerFeePercent: req.OwnerFeePercent,
2025-07-18 20:10:29 +07:00
}
}
func UpdateCategoryRequestToModel(req *contract.UpdateCategoryRequest) *models.UpdateCategoryRequest {
return &models.UpdateCategoryRequest{
2026-10-02 23:30:03 +07:00
Name: req.Name,
Description: req.Description,
ImageURL: nil,
OutletID: req.OutletID,
ParentID: req.ParentID,
Order: req.Order,
OwnerFeePercent: req.OwnerFeePercent,
IsActive: nil,
ClearParentID: req.ClearParentID,
ClearOwnerFeePercent: req.ClearOwnerFeePercent,
2025-07-18 20:10:29 +07:00
}
}
func CategoryModelResponseToResponse(cat *models.CategoryResponse) *contract.CategoryResponse {
if cat == nil {
return nil
}
return &contract.CategoryResponse{
2026-10-02 23:30:03 +07:00
ID: cat.ID,
OrganizationID: cat.OrganizationID,
OutletID: cat.OutletID,
ParentID: cat.ParentID,
ParentName: cat.ParentName,
Name: cat.Name,
Description: cat.Description,
BusinessType: "restaurant",
Order: cat.Order,
OwnerFeePercent: cat.OwnerFeePercent,
Metadata: map[string]interface{}{},
CreatedAt: cat.CreatedAt,
UpdatedAt: cat.UpdatedAt,
2025-07-18 20:10:29 +07:00
}
}
func CategoriesToResponses(categories []models.CategoryResponse) []contract.CategoryResponse {
responses := make([]contract.CategoryResponse, len(categories))
for i, cat := range categories {
response := CategoryModelResponseToResponse(&cat)
if response != nil {
responses[i] = *response
}
}
return responses
}