GET /customer/wallet now reads the EnakPoint & EnakCoin wallet (docs/prd-point-coin.md F6, PC-106): spendable point and coin balances, the rupiah value of one EnakPoint and of the balance, the nearest day each currency loses balance (grouped by Asia/Jakarta day), and recent ledger rows. The fields of the pre-wallet response stay, filled from the wallet, so app versions that read them keep working. Adds GET /customer/wallet/transactions with pagination and filters for currency, one or more types, and an inclusive date range. Each row shows where the value came from (additions) or went to (deductions) as in ยง8.1, and additions list their lots and earliest expiry. The counterparty id, the admin and the metadata are left out; the description already carries the masked name. A malformed query answers 400, a missing customer 404. /customer/points and /customer/tokens keep their shape and now read the wallet too, so customer_points_repository is no longer used for balances. Balances are what the customer can spend: lots that have expired but that the expiry job has not processed are not counted. The point value is read from organization_settings (loyalty.point.value, default 1) through a small repository that the typed settings reader in PC-109 will build on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// OrganizationSettingRepository reads organization_settings, the key-value settings
|
|
// that apply to every outlet of an organization (docs/prd-point-coin.md F2).
|
|
type OrganizationSettingRepository interface {
|
|
// Get returns the stored value of a key and whether one is stored. A key that has
|
|
// never been set is not an error: the caller falls back to the key's default.
|
|
Get(ctx context.Context, organizationID uuid.UUID, key string) (string, bool, error)
|
|
}
|
|
|
|
type organizationSettingRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewOrganizationSettingRepository(db *gorm.DB) OrganizationSettingRepository {
|
|
return &organizationSettingRepository{db: db}
|
|
}
|
|
|
|
func (r *organizationSettingRepository) Get(ctx context.Context, organizationID uuid.UUID, key string) (string, bool, error) {
|
|
var values []*string
|
|
err := DBFromContext(ctx, r.db).WithContext(ctx).
|
|
Table("organization_settings").
|
|
Where("organization_id = ? AND key = ?", organizationID, key).
|
|
Limit(1).
|
|
Pluck("value", &values).Error
|
|
if err != nil {
|
|
return "", false, fmt.Errorf("failed to get organization setting %s: %w", key, err)
|
|
}
|
|
if len(values) == 0 || values[0] == nil {
|
|
return "", false, nil
|
|
}
|
|
return *values[0], true, nil
|
|
}
|