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:
co-authored by
Claude Opus 5.5
parent
c1ec6a3dfd
commit
a24d5f0561
@@ -0,0 +1,57 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"apskel-pos-be/internal/constants"
|
||||
"apskel-pos-be/internal/contract"
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/processor"
|
||||
"apskel-pos-be/internal/repository"
|
||||
)
|
||||
|
||||
// CustomerOrderService serves the customer app's order history.
|
||||
type CustomerOrderService interface {
|
||||
List(ctx context.Context, customerID uuid.UUID, query models.ListCustomerOrdersQuery) *contract.Response
|
||||
Detail(ctx context.Context, customerID, orderID uuid.UUID) *contract.Response
|
||||
}
|
||||
|
||||
type CustomerOrderServiceImpl struct {
|
||||
orders *processor.CustomerOrderProcessor
|
||||
}
|
||||
|
||||
func NewCustomerOrderService(orders *processor.CustomerOrderProcessor) *CustomerOrderServiceImpl {
|
||||
return &CustomerOrderServiceImpl{orders: orders}
|
||||
}
|
||||
|
||||
func (s *CustomerOrderServiceImpl) List(ctx context.Context, customerID uuid.UUID, query models.ListCustomerOrdersQuery) *contract.Response {
|
||||
orders, err := s.orders.List(ctx, customerID, query)
|
||||
if err != nil {
|
||||
return customerOrderErrorResponse(err)
|
||||
}
|
||||
return contract.BuildSuccessResponse(orders)
|
||||
}
|
||||
|
||||
func (s *CustomerOrderServiceImpl) Detail(ctx context.Context, customerID, orderID uuid.UUID) *contract.Response {
|
||||
order, err := s.orders.Detail(ctx, customerID, orderID)
|
||||
if err != nil {
|
||||
return customerOrderErrorResponse(err)
|
||||
}
|
||||
return contract.BuildSuccessResponse(order)
|
||||
}
|
||||
|
||||
func customerOrderErrorResponse(err error) *contract.Response {
|
||||
code := constants.InternalServerErrorCode
|
||||
switch {
|
||||
case errors.Is(err, repository.ErrCustomerOrderNotFound):
|
||||
code = constants.NotFoundErrorCode
|
||||
case errors.Is(err, processor.ErrInvalidWalletQuery):
|
||||
code = constants.ValidationErrorCode
|
||||
}
|
||||
return contract.BuildErrorResponse([]*contract.ResponseError{
|
||||
contract.NewResponseError(code, constants.RequestEntity, err.Error()),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user