feat(customer): order history and detail for the customer app

Adds GET /customer/orders and GET /customer/orders/:id for the customer
app: the orders linked to the logged-in customer across their
organization's outlets, newest first, paginated (limit 1-100, default 20).

The list shows the order number, outlet, type, status, total, item count,
void/refund flags and the EnakPoint and EnakCoin it earned. The detail adds
the amounts, the items with product and variant names, weight and unit
for weighed lines, modifiers and notes, and the payments with the method
and, for EnakPoint, the points used. Costs, cashier and other internal
fields are left out. Another customer's order answers 404 like one that
does not exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
efrilm
2026-09-30 19:36:35 +07:00
co-authored by Claude Opus 5.5
parent c1ec6a3dfd
commit a24d5f0561
9 changed files with 651 additions and 1 deletions
@@ -0,0 +1,49 @@
package handler
import (
"github.com/gin-gonic/gin"
"apskel-pos-be/internal/constants"
"apskel-pos-be/internal/contract"
"apskel-pos-be/internal/models"
"apskel-pos-be/internal/service"
"apskel-pos-be/internal/util"
)
// CustomerOrderHandler serves the customer app's order history.
type CustomerOrderHandler struct {
orders service.CustomerOrderService
}
func NewCustomerOrderHandler(orders service.CustomerOrderService) *CustomerOrderHandler {
return &CustomerOrderHandler{orders: orders}
}
// List is GET /customer/orders?page=&limit=.
func (h *CustomerOrderHandler) List(c *gin.Context) {
customerID, ok := customerIDFromGin(c, "CustomerOrderHandler::List")
if !ok {
return
}
var query models.ListCustomerOrdersQuery
if err := c.ShouldBindQuery(&query); err != nil {
util.HandleResponse(c.Writer, c.Request, contract.BuildErrorResponse([]*contract.ResponseError{
contract.NewResponseError(constants.MalformedFieldErrorCode, constants.RequestEntity, "page and limit must be whole numbers"),
}), "CustomerOrderHandler::List")
return
}
util.HandleResponse(c.Writer, c.Request, h.orders.List(c.Request.Context(), customerID, query), "CustomerOrderHandler::List")
}
// Detail is GET /customer/orders/:id.
func (h *CustomerOrderHandler) Detail(c *gin.Context) {
customerID, ok := customerIDFromGin(c, "CustomerOrderHandler::Detail")
if !ok {
return
}
orderID, ok := parseUUIDParam(c, "id", "CustomerOrderHandler::Detail")
if !ok {
return
}
util.HandleResponse(c.Writer, c.Request, h.orders.Detail(c.Request.Context(), customerID, orderID), "CustomerOrderHandler::Detail")
}