Adds GET /customer/outlets for the customer app: the active outlets of the customer's organization, where their EnakPoint and EnakCoin can be used, sorted by name. Each carries its name and address, and from the outlet's loyalty settings whether the cashier accepts EnakPoint and whether orders there earn EnakPoint or EnakCoin. Nothing internal (printer settings, tax rate) is exposed. The outlets list under /outlets needs a staff token, so the app had no way to show where the wallet works. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"apskel-pos-be/internal/constants"
|
|
"apskel-pos-be/internal/contract"
|
|
"apskel-pos-be/internal/processor"
|
|
"apskel-pos-be/internal/repository"
|
|
)
|
|
|
|
// CustomerOutletService serves the outlets list of the customer app.
|
|
type CustomerOutletService interface {
|
|
List(ctx context.Context, customerID uuid.UUID) *contract.Response
|
|
}
|
|
|
|
type CustomerOutletServiceImpl struct {
|
|
outlets *processor.CustomerOutletProcessor
|
|
}
|
|
|
|
func NewCustomerOutletService(outlets *processor.CustomerOutletProcessor) *CustomerOutletServiceImpl {
|
|
return &CustomerOutletServiceImpl{outlets: outlets}
|
|
}
|
|
|
|
func (s *CustomerOutletServiceImpl) List(ctx context.Context, customerID uuid.UUID) *contract.Response {
|
|
outlets, err := s.outlets.List(ctx, customerID)
|
|
if err != nil {
|
|
code := constants.InternalServerErrorCode
|
|
if errors.Is(err, repository.ErrWalletNotFound) {
|
|
code = constants.NotFoundErrorCode
|
|
}
|
|
return contract.BuildErrorResponse([]*contract.ResponseError{
|
|
contract.NewResponseError(code, constants.RequestEntity, err.Error()),
|
|
})
|
|
}
|
|
return contract.BuildSuccessResponse(outlets)
|
|
}
|