Files
orion/app/modules/loyalty/schemas/__init__.py
Samir Boulahtit 3bf23c1b23
Some checks failed
CI / ruff (push) Successful in 15s
CI / pytest (push) Failing after 2h27m32s
CI / validate (push) Successful in 33s
CI / dependency-scanning (push) Successful in 32s
CI / docs (push) Has been skipped
CI / deploy (push) Has been skipped
feat(android-terminal): Phase C — PIN screen with offline bcrypt verify
Two-pane landscape: scrollable staff list on the left, PIN dots + numeric
keypad on the right. Footer shows online/offline + pending-sync count.

Going with cached-hashes for offline-capable PIN verify (decision logged
in chat). The threat model already accepts the device — a stolen tablet
holds a 1-year store-scoped JWT, so leaking 4-digit bcrypt hashes is
incremental. Hashes only ever leave the server when the requester is a
paired POS tablet, gated by the new endpoint refusing user JWTs.

Backend:
- GET /api/v1/store/loyalty/pins/for-device — returns PINs WITH pin_hash
  for terminal-device JWTs only; user JWTs receive 403.
- PinForDeviceResponse / PinForDeviceListResponse schemas.
- 2 integration tests in TestPinsForDevice (10/10 pass total).

Android:
- PinForDeviceItem / PinForDeviceListResponse Moshi models.
- LoyaltyApi.listPinsForDevice().
- StaffPinRepository.verifyPin(plain) — at.favre.lib bcrypt verify
  against cached hashes; filters active + unlocked rows in one pass.
- PendingTransactionDao.getPendingCount() switched to Flow<Int> so the
  badge auto-updates when transactions sync.
- PinViewModel state machine — loads pins on init, accumulates digits,
  bcrypt-verifies on length >= 4, fires verified/errorMessage. Combines
  pending-sync count + online state into the same StateFlow.
- PinScreen rewrite: avatar-circle staff list, 6-dot PIN display,
  spinner during verify, error label on wrong PIN, status footer.

Open follow-up (intentional, post-launch): tablet doesn't yet report
failed attempts back to the server's lockout counter. Path is clear —
small POST /pins/{id}/record-failed-attempt endpoint plus a call from
attemptVerify's failure branch.

Verified by ./gradlew assembleDebug — clean build.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 22:58:18 +02:00

155 lines
3.5 KiB
Python

# app/modules/loyalty/schemas/__init__.py
"""
Loyalty module Pydantic schemas.
Request and response models for the loyalty API endpoints.
Usage:
from app.modules.loyalty.schemas import (
# Program
ProgramCreate,
ProgramUpdate,
ProgramResponse,
# Card
CardEnrollRequest,
CardResponse,
# Stamp
StampRequest,
StampResponse,
# Points
PointsEarnRequest,
PointsRedeemRequest,
# PIN
PinCreate,
PinVerifyRequest,
)
"""
from app.modules.loyalty.schemas.card import (
CardDetailResponse,
# Card operations
CardEnrollRequest,
CardListResponse,
CardLookupResponse,
CardResponse,
TransactionListResponse,
# Transactions
TransactionResponse,
)
from app.modules.loyalty.schemas.pin import (
# Staff PIN
PinCreate,
PinCreateForMerchant,
PinDetailListResponse,
PinDetailResponse,
PinForDeviceListResponse,
PinForDeviceResponse,
PinListResponse,
PinResponse,
PinUpdate,
PinVerifyRequest,
PinVerifyResponse,
)
from app.modules.loyalty.schemas.points import (
PointsAdjustRequest,
PointsAdjustResponse,
# Points operations
PointsEarnRequest,
PointsEarnResponse,
PointsRedeemRequest,
PointsRedeemResponse,
PointsVoidRequest,
PointsVoidResponse,
)
from app.modules.loyalty.schemas.program import (
# Merchant settings
MerchantSettingsResponse,
MerchantSettingsUpdate,
MerchantStatsResponse,
# Points rewards
PointsRewardConfig,
# Program CRUD
ProgramCreate,
ProgramListResponse,
ProgramResponse,
# Stats
ProgramStatsResponse,
ProgramUpdate,
TierConfig,
)
from app.modules.loyalty.schemas.stamp import (
StampRedeemRequest,
StampRedeemResponse,
# Stamp operations
StampRequest,
StampResponse,
StampVoidRequest,
StampVoidResponse,
)
from app.modules.loyalty.schemas.terminal_device import (
# Terminal device pairing & management
TerminalDeviceCreate,
TerminalDeviceListResponse,
TerminalDevicePairingResponse,
TerminalDeviceResponse,
TerminalDeviceRevoke,
TerminalDeviceUpdate,
)
__all__ = [
# Program
"ProgramCreate",
"ProgramUpdate",
"ProgramResponse",
"ProgramListResponse",
"PointsRewardConfig",
"TierConfig",
"ProgramStatsResponse",
"MerchantStatsResponse",
"MerchantSettingsResponse",
"MerchantSettingsUpdate",
# Card
"CardEnrollRequest",
"CardResponse",
"CardDetailResponse",
"CardListResponse",
"CardLookupResponse",
"TransactionResponse",
"TransactionListResponse",
# Stamp
"StampRequest",
"StampResponse",
"StampRedeemRequest",
"StampRedeemResponse",
"StampVoidRequest",
"StampVoidResponse",
# Points
"PointsEarnRequest",
"PointsEarnResponse",
"PointsRedeemRequest",
"PointsRedeemResponse",
"PointsVoidRequest",
"PointsVoidResponse",
"PointsAdjustRequest",
"PointsAdjustResponse",
# PIN
"PinCreate",
"PinCreateForMerchant",
"PinUpdate",
"PinResponse",
"PinForDeviceResponse",
"PinForDeviceListResponse",
"PinDetailResponse",
"PinListResponse",
"PinDetailListResponse",
"PinVerifyRequest",
"PinVerifyResponse",
# Terminal device
"TerminalDeviceCreate",
"TerminalDeviceUpdate",
"TerminalDeviceRevoke",
"TerminalDeviceResponse",
"TerminalDevicePairingResponse",
"TerminalDeviceListResponse",
]