init
This commit is contained in:
@@ -36,9 +36,6 @@ func CreateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.Cr
|
||||
if metadata == nil {
|
||||
metadata = make(map[string]interface{})
|
||||
}
|
||||
if req.Image != nil {
|
||||
metadata["image"] = *req.Image
|
||||
}
|
||||
|
||||
return &models.CreateProductRequest{
|
||||
OrganizationID: apctx.OrganizationID,
|
||||
@@ -49,6 +46,8 @@ func CreateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.Cr
|
||||
Price: req.Price,
|
||||
Cost: cost,
|
||||
BusinessType: businessType,
|
||||
ImageURL: req.ImageURL,
|
||||
PrinterType: req.PrinterType,
|
||||
Metadata: metadata,
|
||||
Variants: variants,
|
||||
}
|
||||
@@ -59,9 +58,7 @@ func UpdateProductRequestToModel(req *contract.UpdateProductRequest) *models.Upd
|
||||
if metadata == nil {
|
||||
metadata = make(map[string]interface{})
|
||||
}
|
||||
if req.Image != nil {
|
||||
metadata["image"] = *req.Image
|
||||
}
|
||||
|
||||
return &models.UpdateProductRequest{
|
||||
CategoryID: req.CategoryID,
|
||||
SKU: req.SKU,
|
||||
@@ -69,6 +66,8 @@ func UpdateProductRequestToModel(req *contract.UpdateProductRequest) *models.Upd
|
||||
Description: req.Description,
|
||||
Price: req.Price,
|
||||
Cost: req.Cost,
|
||||
ImageURL: req.ImageURL,
|
||||
PrinterType: req.PrinterType,
|
||||
Metadata: metadata,
|
||||
IsActive: req.IsActive,
|
||||
}
|
||||
@@ -98,7 +97,7 @@ func ProductModelResponseToResponse(prod *models.ProductResponse) *contract.Prod
|
||||
}
|
||||
}
|
||||
|
||||
response := &contract.ProductResponse{
|
||||
return &contract.ProductResponse{
|
||||
ID: prod.ID,
|
||||
OrganizationID: prod.OrganizationID,
|
||||
CategoryID: prod.CategoryID,
|
||||
@@ -108,14 +107,14 @@ func ProductModelResponseToResponse(prod *models.ProductResponse) *contract.Prod
|
||||
Price: prod.Price,
|
||||
Cost: prod.Cost,
|
||||
BusinessType: string(prod.BusinessType),
|
||||
ImageURL: prod.ImageURL,
|
||||
PrinterType: prod.PrinterType,
|
||||
Metadata: prod.Metadata,
|
||||
IsActive: prod.IsActive,
|
||||
CreatedAt: prod.CreatedAt,
|
||||
UpdatedAt: prod.UpdatedAt,
|
||||
Variants: variantResponses,
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
// Slice conversions
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package transformer
|
||||
|
||||
import (
|
||||
"apskel-pos-be/internal/contract"
|
||||
"apskel-pos-be/internal/models"
|
||||
)
|
||||
|
||||
type TableTransformer struct{}
|
||||
|
||||
func NewTableTransformer() *TableTransformer {
|
||||
return &TableTransformer{}
|
||||
}
|
||||
|
||||
func (t *TableTransformer) ToContract(model models.TableResponse) *contract.TableResponse {
|
||||
response := &contract.TableResponse{
|
||||
ID: model.ID,
|
||||
OrganizationID: model.OrganizationID,
|
||||
OutletID: model.OutletID,
|
||||
TableName: model.TableName,
|
||||
StartTime: model.StartTime,
|
||||
Status: string(model.Status),
|
||||
OrderID: model.OrderID,
|
||||
PaymentAmount: model.PaymentAmount,
|
||||
PositionX: model.PositionX,
|
||||
PositionY: model.PositionY,
|
||||
Capacity: model.Capacity,
|
||||
IsActive: model.IsActive,
|
||||
Metadata: model.Metadata,
|
||||
CreatedAt: model.CreatedAt,
|
||||
UpdatedAt: model.UpdatedAt,
|
||||
}
|
||||
|
||||
if model.Order != nil {
|
||||
response.Order = &contract.OrderResponse{
|
||||
ID: model.Order.ID,
|
||||
OrganizationID: model.Order.OrganizationID,
|
||||
OutletID: model.Order.OutletID,
|
||||
UserID: model.Order.UserID,
|
||||
CustomerID: model.Order.CustomerID,
|
||||
OrderNumber: model.Order.OrderNumber,
|
||||
TableNumber: model.Order.TableNumber,
|
||||
OrderType: string(model.Order.OrderType),
|
||||
Status: string(model.Order.Status),
|
||||
Subtotal: model.Order.Subtotal,
|
||||
TaxAmount: model.Order.TaxAmount,
|
||||
DiscountAmount: model.Order.DiscountAmount,
|
||||
TotalAmount: model.Order.TotalAmount,
|
||||
TotalCost: model.Order.TotalCost,
|
||||
PaymentStatus: string(model.Order.PaymentStatus),
|
||||
RefundAmount: model.Order.RefundAmount,
|
||||
IsVoid: model.Order.IsVoid,
|
||||
IsRefund: model.Order.IsRefund,
|
||||
VoidReason: model.Order.VoidReason,
|
||||
VoidedAt: model.Order.VoidedAt,
|
||||
VoidedBy: model.Order.VoidedBy,
|
||||
RefundReason: model.Order.RefundReason,
|
||||
RefundedAt: model.Order.RefundedAt,
|
||||
RefundedBy: model.Order.RefundedBy,
|
||||
Metadata: model.Order.Metadata,
|
||||
CreatedAt: model.Order.CreatedAt,
|
||||
UpdatedAt: model.Order.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
func (t *TableTransformer) ToModel(contract contract.TableResponse) *models.TableResponse {
|
||||
response := &models.TableResponse{
|
||||
ID: contract.ID,
|
||||
OrganizationID: contract.OrganizationID,
|
||||
OutletID: contract.OutletID,
|
||||
TableName: contract.TableName,
|
||||
StartTime: contract.StartTime,
|
||||
Status: models.TableStatus(contract.Status),
|
||||
OrderID: contract.OrderID,
|
||||
PaymentAmount: contract.PaymentAmount,
|
||||
PositionX: contract.PositionX,
|
||||
PositionY: contract.PositionY,
|
||||
Capacity: contract.Capacity,
|
||||
IsActive: contract.IsActive,
|
||||
Metadata: contract.Metadata,
|
||||
CreatedAt: contract.CreatedAt,
|
||||
UpdatedAt: contract.UpdatedAt,
|
||||
}
|
||||
|
||||
if contract.Order != nil {
|
||||
response.Order = &models.OrderResponse{
|
||||
ID: contract.Order.ID,
|
||||
OrganizationID: contract.Order.OrganizationID,
|
||||
OutletID: contract.Order.OutletID,
|
||||
UserID: contract.Order.UserID,
|
||||
CustomerID: contract.Order.CustomerID,
|
||||
OrderNumber: contract.Order.OrderNumber,
|
||||
TableNumber: contract.Order.TableNumber,
|
||||
OrderType: models.OrderType(contract.Order.OrderType),
|
||||
Status: models.OrderStatus(contract.Order.Status),
|
||||
Subtotal: contract.Order.Subtotal,
|
||||
TaxAmount: contract.Order.TaxAmount,
|
||||
DiscountAmount: contract.Order.DiscountAmount,
|
||||
TotalAmount: contract.Order.TotalAmount,
|
||||
TotalCost: contract.Order.TotalCost,
|
||||
PaymentStatus: models.PaymentStatus(contract.Order.PaymentStatus),
|
||||
RefundAmount: contract.Order.RefundAmount,
|
||||
IsVoid: contract.Order.IsVoid,
|
||||
IsRefund: contract.Order.IsRefund,
|
||||
VoidReason: contract.Order.VoidReason,
|
||||
VoidedAt: contract.Order.VoidedAt,
|
||||
VoidedBy: contract.Order.VoidedBy,
|
||||
RefundReason: contract.Order.RefundReason,
|
||||
RefundedAt: contract.Order.RefundedAt,
|
||||
RefundedBy: contract.Order.RefundedBy,
|
||||
Metadata: contract.Order.Metadata,
|
||||
CreatedAt: contract.Order.CreatedAt,
|
||||
UpdatedAt: contract.Order.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
@@ -51,6 +51,12 @@ func ChangePasswordRequestToModel(req *contract.ChangePasswordRequest) *models.C
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateUserOutletRequestToModel(req *contract.UpdateUserOutletRequest) *models.UpdateUserOutletRequest {
|
||||
return &models.UpdateUserOutletRequest{
|
||||
OutletID: req.OutletID,
|
||||
}
|
||||
}
|
||||
|
||||
// Model to Contract conversions
|
||||
func UserModelToResponse(user *models.User) *contract.UserResponse {
|
||||
return &contract.UserResponse{
|
||||
|
||||
Reference in New Issue
Block a user