upodate system
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
type CashierSessionResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
CashierID int64 `json:"cashier_id"`
|
||||
OpenedAt time.Time `json:"opened_at"`
|
||||
ClosedAt *time.Time `json:"closed_at,omitempty"`
|
||||
@@ -35,6 +36,7 @@ func MapToCashierSessionResponse(e *entity.CashierSession) *CashierSessionRespon
|
||||
|
||||
return &CashierSessionResponse{
|
||||
ID: e.ID,
|
||||
PartnerID: e.PartnerID,
|
||||
CashierID: e.CashierID,
|
||||
OpenedAt: e.OpenedAt,
|
||||
ClosedAt: e.ClosedAt,
|
||||
|
||||
@@ -3,6 +3,7 @@ package response
|
||||
import (
|
||||
"enaklo-pos-be/internal/constants/order"
|
||||
"enaklo-pos-be/internal/constants/transaction"
|
||||
"enaklo-pos-be/internal/entity"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -204,3 +205,52 @@ type OrderHistoryResponse struct {
|
||||
Tax float64 `json:"tax"`
|
||||
RestaurantName string `json:"restaurant_name"`
|
||||
}
|
||||
|
||||
func MapOrderHistoryResponse(orders []*entity.Order) []OrderHistoryResponse {
|
||||
responseData := make([]OrderHistoryResponse, 0, len(orders))
|
||||
|
||||
for _, order := range orders {
|
||||
orderResponse := mapOrderToResponse(order)
|
||||
responseData = append(responseData, orderResponse)
|
||||
}
|
||||
|
||||
return responseData
|
||||
}
|
||||
|
||||
func mapOrderToResponse(order *entity.Order) OrderHistoryResponse {
|
||||
paymentFormatter := NewPaymentFormatter()
|
||||
return OrderHistoryResponse{
|
||||
ID: order.ID,
|
||||
CustomerName: order.CustomerName,
|
||||
CustomerID: order.CustomerID,
|
||||
IsMember: order.IsMemberOrder(),
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
Total: order.Total,
|
||||
PaymentType: paymentFormatter.Format(order.PaymentType, order.PaymentProvider),
|
||||
TableNumber: order.TableNumber,
|
||||
OrderType: order.OrderType,
|
||||
OrderItems: mapOrderItems(order.OrderItems),
|
||||
CreatedAt: order.CreatedAt.Format(time.RFC3339),
|
||||
Tax: order.Tax,
|
||||
}
|
||||
}
|
||||
|
||||
func mapOrderItems(items []entity.OrderItem) []OrderItemResponse {
|
||||
orderItems := make([]OrderItemResponse, 0, len(items))
|
||||
|
||||
for _, item := range items {
|
||||
orderItems = append(orderItems, OrderItemResponse{
|
||||
OrderItemID: item.ID,
|
||||
ProductID: item.ItemID,
|
||||
ProductName: item.ItemName,
|
||||
Price: item.Price,
|
||||
Quantity: item.Quantity,
|
||||
Subtotal: item.Price * float64(item.Quantity),
|
||||
Notes: item.Notes,
|
||||
Status: item.Status,
|
||||
})
|
||||
}
|
||||
|
||||
return orderItems
|
||||
}
|
||||
|
||||
@@ -23,12 +23,14 @@ type OrderInquiryResponse struct {
|
||||
}
|
||||
|
||||
type OrderItemResponse struct {
|
||||
OrderItemID int64 `json:"order_item_id"`
|
||||
ProductID int64 `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
Price float64 `json:"price"`
|
||||
Quantity int `json:"quantity"`
|
||||
Subtotal float64 `json:"subtotal"`
|
||||
Notes string `json:"notes"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func mapToOrderItemResponses(items []entity.OrderItem) []OrderItemResponse {
|
||||
@@ -109,12 +111,14 @@ func MapToOrderItemResponses(items []entity.OrderItem) []OrderItemResponse {
|
||||
result := make([]OrderItemResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, OrderItemResponse{
|
||||
OrderItemID: item.ID,
|
||||
ProductID: item.ItemID,
|
||||
ProductName: item.ItemName,
|
||||
Price: item.Price,
|
||||
Quantity: item.Quantity,
|
||||
Subtotal: item.Price * float64(item.Quantity),
|
||||
Notes: item.Notes,
|
||||
Status: item.Status,
|
||||
})
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package response
|
||||
|
||||
type PaginationHelper struct{}
|
||||
|
||||
func NewPaginationHelper() *PaginationHelper {
|
||||
return &PaginationHelper{}
|
||||
}
|
||||
|
||||
func (p *PaginationHelper) BuildPagingMeta(offset, limit int, total int64) *PagingMeta {
|
||||
page := 1
|
||||
if limit > 0 {
|
||||
page = (offset / limit) + 1
|
||||
}
|
||||
|
||||
return &PagingMeta{
|
||||
Page: page,
|
||||
Total: total,
|
||||
Limit: limit,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PaginationHelper) calculateTotalPages(total int64, limit int) int {
|
||||
if limit <= 0 {
|
||||
return 1
|
||||
}
|
||||
return int((total + int64(limit) - 1) / int64(limit))
|
||||
}
|
||||
|
||||
func (p *PaginationHelper) hasNextPage(offset, limit int, total int64) bool {
|
||||
if limit <= 0 {
|
||||
return false
|
||||
}
|
||||
return int64(offset+limit) < total
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package response
|
||||
|
||||
import "fmt"
|
||||
|
||||
type PaymentFormatter interface {
|
||||
Format(paymentType, paymentProvider string) string
|
||||
}
|
||||
|
||||
type paymentFormatter struct{}
|
||||
|
||||
func NewPaymentFormatter() PaymentFormatter {
|
||||
return &paymentFormatter{}
|
||||
}
|
||||
|
||||
func (f *paymentFormatter) Format(paymentType, paymentProvider string) string {
|
||||
if paymentProvider != "" {
|
||||
return fmt.Sprintf("%s (%s)", paymentType, paymentProvider)
|
||||
}
|
||||
return paymentType
|
||||
}
|
||||
Reference in New Issue
Block a user