50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package processor
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
|
||
|
|
"apskel-pos-be/internal/models"
|
||
|
|
"apskel-pos-be/internal/repository"
|
||
|
|
)
|
||
|
|
|
||
|
|
// CustomerOutletProcessor lists the outlets the customer app shows: the active
|
||
|
|
// outlets of the customer's organization, where their wallet can be used (K4).
|
||
|
|
type CustomerOutletProcessor struct {
|
||
|
|
repo repository.CustomerOutletRepository
|
||
|
|
settings outletSettingsReader
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCustomerOutletProcessor(repo repository.CustomerOutletRepository, settings outletSettingsReader) *CustomerOutletProcessor {
|
||
|
|
return &CustomerOutletProcessor{repo: repo, settings: settings}
|
||
|
|
}
|
||
|
|
|
||
|
|
// List is GET /customer/outlets.
|
||
|
|
func (p *CustomerOutletProcessor) List(ctx context.Context, customerID uuid.UUID) ([]models.CustomerOutlet, error) {
|
||
|
|
organizationID, err := p.repo.CustomerOrganizationID(ctx, customerID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
outlets, err := p.repo.ListActiveOutlets(ctx, organizationID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
list := make([]models.CustomerOutlet, 0, len(outlets))
|
||
|
|
for _, o := range outlets {
|
||
|
|
settings, err := p.settings.Outlet(ctx, o.ID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
list = append(list, models.CustomerOutlet{
|
||
|
|
ID: o.ID,
|
||
|
|
Name: o.Name,
|
||
|
|
Address: o.Address,
|
||
|
|
AcceptsPointPayment: settings.PointPayment.AcceptPayment,
|
||
|
|
EarnsPoints: settings.Point.Enabled,
|
||
|
|
EarnsCoins: settings.Coin.Enabled,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return list, nil
|
||
|
|
}
|