Merge branch 'self-order+notification' of https://gits.altru.id/apksel-dev/apskel-pos-backend into self-order+notification
This commit is contained in:
commit
4ea8e32a8e
@ -1,8 +1,6 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@ -80,36 +78,5 @@ type SelfOrderListCategoriesResponse struct {
|
||||
}
|
||||
|
||||
type SelfOrderListOrdersResponse struct {
|
||||
Orders []SelfOrderOrderItem `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"`
|
||||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||
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"`
|
||||
Orders []OrderResponse `json:"orders"`
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"apskel-pos-be/internal/contract"
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/logger"
|
||||
"apskel-pos-be/internal/mappers"
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/pkg/tabletoken"
|
||||
"apskel-pos-be/internal/processor"
|
||||
@ -391,48 +392,15 @@ func (h *SelfOrderHandler) GetOrdersBySession(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
resp := &contract.SelfOrderListOrdersResponse{
|
||||
Orders: make([]contract.SelfOrderOrderItem, 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,
|
||||
Metadata: o.Metadata,
|
||||
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)
|
||||
modelOrders := mappers.OrderEntitiesToResponses(orders)
|
||||
contractOrders := make([]contract.OrderResponse, len(modelOrders))
|
||||
for i := range modelOrders {
|
||||
contractOrders[i] = *transformer.OrderModelToContract(&modelOrders[i])
|
||||
}
|
||||
|
||||
resp := &contract.SelfOrderListOrdersResponse{
|
||||
Orders: contractOrders,
|
||||
}
|
||||
util.HandleResponse(c.Writer, c.Request, contract.BuildSuccessResponse(resp), "SelfOrderHandler::GetOrdersBySession")
|
||||
}
|
||||
|
||||
@ -441,6 +409,7 @@ func (h *SelfOrderHandler) validateCreateOrderRequest(req *contract.SelfOrderCre
|
||||
return fmt.Errorf("session_id is required")
|
||||
}
|
||||
if len(req.OrderItems) == 0 {
|
||||
|
||||
return fmt.Errorf("at least one order item is required")
|
||||
}
|
||||
for i, item := range req.OrderItems {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user