change order response at self order
This commit is contained in:
parent
bccf02b5f7
commit
7ba776555e
@ -1,8 +1,6 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@ -80,35 +78,7 @@ type SelfOrderListCategoriesResponse struct {
|
||||
}
|
||||
|
||||
type SelfOrderListOrdersResponse struct {
|
||||
Orders []SelfOrderOrderItem `json:"orders"`
|
||||
Orders []OrderResponse `json:"orders"`
|
||||
}
|
||||
|
||||
type SelfOrderOrderItem struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
OrderNumber string `json:"order_number"`
|
||||
TableNumber *string `json:"table_number,omitempty"`
|
||||
OrderType string `json:"order_type"`
|
||||
Status string `json:"status"`
|
||||
Subtotal float64 `json:"subtotal"`
|
||||
TaxAmount float64 `json:"tax_amount"`
|
||||
DiscountAmount float64 `json:"discount_amount"`
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
RemainingAmount float64 `json:"remaining_amount"`
|
||||
PaymentStatus string `json:"payment_status"`
|
||||
IsVoid bool `json:"is_void"`
|
||||
IsRefund bool `json:"is_refund"`
|
||||
Items []SelfOrderOrderLineItem `json:"items,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type SelfOrderOrderLineItem struct {
|
||||
ProductID uuid.UUID `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
ProductVariantID *uuid.UUID `json:"product_variant_id,omitempty"`
|
||||
ProductVariantNam *string `json:"product_variant_name,omitempty"`
|
||||
Quantity int `json:"quantity"`
|
||||
UnitPrice float64 `json:"unit_price"`
|
||||
TotalPrice float64 `json:"total_price"`
|
||||
Notes *string `json:"notes,omitempty"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
type SelfOrderOrderLineItem = OrderItemResponse
|
||||
|
||||
@ -392,44 +392,11 @@ func (h *SelfOrderHandler) GetOrdersBySession(c *gin.Context) {
|
||||
}
|
||||
|
||||
resp := &contract.SelfOrderListOrdersResponse{
|
||||
Orders: make([]contract.SelfOrderOrderItem, 0, len(orders)),
|
||||
Orders: make([]contract.OrderResponse, 0, len(orders)),
|
||||
}
|
||||
|
||||
for _, o := range orders {
|
||||
item := contract.SelfOrderOrderItem{
|
||||
ID: o.ID,
|
||||
OrderNumber: o.OrderNumber,
|
||||
TableNumber: o.TableNumber,
|
||||
OrderType: string(o.OrderType),
|
||||
Status: string(o.Status),
|
||||
Subtotal: o.Subtotal,
|
||||
TaxAmount: o.TaxAmount,
|
||||
DiscountAmount: o.DiscountAmount,
|
||||
TotalAmount: o.TotalAmount,
|
||||
RemainingAmount: o.RemainingAmount,
|
||||
PaymentStatus: string(o.PaymentStatus),
|
||||
IsVoid: o.IsVoid,
|
||||
IsRefund: o.IsRefund,
|
||||
CreatedAt: o.CreatedAt,
|
||||
}
|
||||
for _, oi := range o.OrderItems {
|
||||
lineItem := contract.SelfOrderOrderLineItem{
|
||||
ProductID: oi.ProductID,
|
||||
Quantity: oi.Quantity,
|
||||
UnitPrice: oi.UnitPrice,
|
||||
TotalPrice: oi.TotalPrice,
|
||||
Notes: oi.Notes,
|
||||
Status: string(oi.Status),
|
||||
ProductVariantID: oi.ProductVariantID,
|
||||
}
|
||||
if oi.Product.ID != uuid.Nil {
|
||||
lineItem.ProductName = oi.Product.Name
|
||||
}
|
||||
if oi.ProductVariant != nil {
|
||||
lineItem.ProductVariantNam = &oi.ProductVariant.Name
|
||||
}
|
||||
item.Items = append(item.Items, lineItem)
|
||||
}
|
||||
resp.Orders = append(resp.Orders, item)
|
||||
resp.Orders = append(resp.Orders, *transformer.OrderEntityToContract(o))
|
||||
}
|
||||
|
||||
util.HandleResponse(c.Writer, c.Request, contract.BuildSuccessResponse(resp), "SelfOrderHandler::GetOrdersBySession")
|
||||
|
||||
@ -3,6 +3,7 @@ package transformer
|
||||
import (
|
||||
"apskel-pos-be/internal/constants"
|
||||
"apskel-pos-be/internal/contract"
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/util"
|
||||
"strconv"
|
||||
@ -416,3 +417,122 @@ func SplitBillModelToContract(resp *models.SplitBillResponse) *contract.SplitBil
|
||||
Message: resp.Message,
|
||||
}
|
||||
}
|
||||
|
||||
func OrderEntityToContract(o *entities.Order) *contract.OrderResponse {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
orderItems := make([]contract.OrderItemResponse, 0, len(o.OrderItems))
|
||||
for _, oi := range o.OrderItems {
|
||||
lineItem := contract.OrderItemResponse{
|
||||
ID: oi.ID,
|
||||
OrderID: oi.OrderID,
|
||||
ProductID: oi.ProductID,
|
||||
ProductVariantID: oi.ProductVariantID,
|
||||
Quantity: oi.Quantity,
|
||||
UnitPrice: oi.UnitPrice,
|
||||
TotalPrice: oi.TotalPrice,
|
||||
Modifiers: oi.Modifiers,
|
||||
Notes: oi.Notes,
|
||||
Metadata: oi.Metadata,
|
||||
Status: string(oi.Status),
|
||||
CreatedAt: oi.CreatedAt,
|
||||
UpdatedAt: oi.UpdatedAt,
|
||||
}
|
||||
if oi.Product.ID != uuid.Nil {
|
||||
lineItem.ProductName = oi.Product.Name
|
||||
}
|
||||
if oi.ProductVariant != nil {
|
||||
lineItem.ProductVariantName = &oi.ProductVariant.Name
|
||||
}
|
||||
orderItems = append(orderItems, lineItem)
|
||||
}
|
||||
|
||||
payments := make([]contract.PaymentResponse, 0, len(o.Payments))
|
||||
for i := range o.Payments {
|
||||
if p := PaymentEntityToContract(&o.Payments[i]); p != nil {
|
||||
payments = append(payments, *p)
|
||||
}
|
||||
}
|
||||
|
||||
return &contract.OrderResponse{
|
||||
ID: o.ID,
|
||||
OrderNumber: o.OrderNumber,
|
||||
OutletID: o.OutletID,
|
||||
UserID: o.UserID,
|
||||
TableNumber: o.TableNumber,
|
||||
OrderType: string(o.OrderType),
|
||||
Status: string(o.Status),
|
||||
Subtotal: o.Subtotal,
|
||||
TaxAmount: o.TaxAmount,
|
||||
DiscountAmount: o.DiscountAmount,
|
||||
TotalAmount: o.TotalAmount,
|
||||
TotalCost: o.TotalCost,
|
||||
RemainingAmount: o.RemainingAmount,
|
||||
PaymentStatus: string(o.PaymentStatus),
|
||||
RefundAmount: o.RefundAmount,
|
||||
IsVoid: o.IsVoid,
|
||||
IsRefund: o.IsRefund,
|
||||
VoidReason: o.VoidReason,
|
||||
VoidedAt: o.VoidedAt,
|
||||
VoidedBy: o.VoidedBy,
|
||||
RefundReason: o.RefundReason,
|
||||
RefundedAt: o.RefundedAt,
|
||||
RefundedBy: o.RefundedBy,
|
||||
Metadata: o.Metadata,
|
||||
CreatedAt: o.CreatedAt,
|
||||
UpdatedAt: o.UpdatedAt,
|
||||
OrderItems: orderItems,
|
||||
Payments: payments,
|
||||
TotalPaid: o.GetTotalPaid(),
|
||||
PaymentCount: len(o.Payments),
|
||||
}
|
||||
}
|
||||
|
||||
func PaymentEntityToContract(p *entities.Payment) *contract.PaymentResponse {
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var splitType *string
|
||||
if p.SplitType != nil {
|
||||
s := string(*p.SplitType)
|
||||
splitType = &s
|
||||
}
|
||||
|
||||
paymentOrderItems := make([]contract.PaymentOrderItemResponse, 0, len(p.PaymentOrderItems))
|
||||
for _, poi := range p.PaymentOrderItems {
|
||||
paymentOrderItems = append(paymentOrderItems, contract.PaymentOrderItemResponse{
|
||||
ID: poi.ID,
|
||||
PaymentID: poi.PaymentID,
|
||||
OrderItemID: poi.OrderItemID,
|
||||
Amount: poi.Amount,
|
||||
CreatedAt: poi.CreatedAt,
|
||||
UpdatedAt: poi.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return &contract.PaymentResponse{
|
||||
ID: p.ID,
|
||||
OrderID: p.OrderID,
|
||||
PaymentMethodID: p.PaymentMethodID,
|
||||
PaymentMethodName: p.PaymentMethod.Name,
|
||||
PaymentMethodType: string(p.PaymentMethod.Type),
|
||||
Amount: p.Amount,
|
||||
Status: string(p.Status),
|
||||
TransactionID: p.TransactionID,
|
||||
SplitNumber: p.SplitNumber,
|
||||
SplitTotal: p.SplitTotal,
|
||||
SplitType: splitType,
|
||||
SplitDescription: p.SplitDescription,
|
||||
RefundAmount: p.RefundAmount,
|
||||
RefundReason: p.RefundReason,
|
||||
RefundedAt: p.RefundedAt,
|
||||
RefundedBy: p.RefundedBy,
|
||||
Metadata: p.Metadata,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
PaymentOrderItems: paymentOrderItems,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user