Fix: Update permission names, models and constants

Permission renames:
- BOOK_APPOINTMENT -> CREATE_EXCHANGE
- VIEW_OWN_APPOINTMENTS -> VIEW_OWN_EXCHANGES
- CANCEL_OWN_APPOINTMENT -> CANCEL_OWN_EXCHANGE
- VIEW_ALL_APPOINTMENTS -> VIEW_ALL_EXCHANGES
- CANCEL_ANY_APPOINTMENT -> CANCEL_ANY_EXCHANGE
- Add COMPLETE_EXCHANGE permission

Model changes:
- Delete AppointmentStatus enum
- Delete Appointment model

Schema changes:
- Delete BookingRequest (was for old booking)
- Delete AppointmentResponse, PaginatedAppointments
- Delete BookableSlot, AvailableSlotsResponse (unused)

Constants changes:
- Remove appointmentStatuses from shared/constants.json
- Merge booking constants into exchange section
- Update shared_constants.py and validate_constants.py
This commit is contained in:
counterweight 2025-12-22 20:28:21 +01:00
parent 743129b11d
commit fa07490b7b
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
6 changed files with 32 additions and 147 deletions

View file

@ -180,7 +180,7 @@ def _to_exchange_response(
@router.get("/price", response_model=ExchangePriceResponse)
async def get_exchange_price(
db: AsyncSession = Depends(get_db),
_current_user: User = Depends(require_permission(Permission.BOOK_APPOINTMENT)),
_current_user: User = Depends(require_permission(Permission.CREATE_EXCHANGE)),
) -> ExchangePriceResponse:
"""
Get the current BTC/EUR price for trading.
@ -275,7 +275,7 @@ async def get_exchange_price(
async def create_exchange(
request: ExchangeRequest,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(require_permission(Permission.BOOK_APPOINTMENT)),
current_user: User = Depends(require_permission(Permission.CREATE_EXCHANGE)),
) -> ExchangeResponse:
"""
Create a new exchange trade booking.
@ -415,7 +415,7 @@ trades_router = APIRouter(prefix="/api/trades", tags=["trades"])
@trades_router.get("", response_model=list[ExchangeResponse])
async def get_my_trades(
db: AsyncSession = Depends(get_db),
current_user: User = Depends(require_permission(Permission.VIEW_OWN_APPOINTMENTS)),
current_user: User = Depends(require_permission(Permission.VIEW_OWN_EXCHANGES)),
) -> list[ExchangeResponse]:
"""Get the current user's exchanges, sorted by date (newest first)."""
result = await db.execute(
@ -432,7 +432,7 @@ async def get_my_trades(
async def cancel_my_trade(
exchange_id: int,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(require_permission(Permission.CANCEL_OWN_APPOINTMENT)),
current_user: User = Depends(require_permission(Permission.CANCEL_OWN_EXCHANGE)),
) -> ExchangeResponse:
"""Cancel one of the current user's exchanges."""
# Get the exchange with eager loading of user relationship
@ -512,7 +512,7 @@ def _to_admin_exchange_response(exchange: Exchange) -> AdminExchangeResponse:
@admin_trades_router.get("/upcoming", response_model=list[AdminExchangeResponse])
async def get_upcoming_trades(
db: AsyncSession = Depends(get_db),
_current_user: User = Depends(require_permission(Permission.VIEW_ALL_APPOINTMENTS)),
_current_user: User = Depends(require_permission(Permission.VIEW_ALL_EXCHANGES)),
) -> list[AdminExchangeResponse]:
"""Get all upcoming booked trades, sorted by slot time ascending."""
now = datetime.now(UTC)
@ -539,7 +539,7 @@ async def get_past_trades(
end_date: date | None = None,
user_search: str | None = None,
db: AsyncSession = Depends(get_db),
_current_user: User = Depends(require_permission(Permission.VIEW_ALL_APPOINTMENTS)),
_current_user: User = Depends(require_permission(Permission.VIEW_ALL_EXCHANGES)),
) -> list[AdminExchangeResponse]:
"""
Get past trades with optional filters.
@ -599,9 +599,7 @@ async def get_past_trades(
async def complete_trade(
exchange_id: int,
db: AsyncSession = Depends(get_db),
_current_user: User = Depends(
require_permission(Permission.CANCEL_ANY_APPOINTMENT)
),
_current_user: User = Depends(require_permission(Permission.CANCEL_ANY_EXCHANGE)),
) -> AdminExchangeResponse:
"""Mark a trade as completed. Only possible after slot time has passed."""
@ -647,9 +645,7 @@ async def complete_trade(
async def mark_no_show(
exchange_id: int,
db: AsyncSession = Depends(get_db),
_current_user: User = Depends(
require_permission(Permission.CANCEL_ANY_APPOINTMENT)
),
_current_user: User = Depends(require_permission(Permission.CANCEL_ANY_EXCHANGE)),
) -> AdminExchangeResponse:
"""Mark a trade as no-show. Only possible after slot time has passed."""
@ -693,9 +689,7 @@ async def mark_no_show(
async def admin_cancel_trade(
exchange_id: int,
db: AsyncSession = Depends(get_db),
_current_user: User = Depends(
require_permission(Permission.CANCEL_ANY_APPOINTMENT)
),
_current_user: User = Depends(require_permission(Permission.CANCEL_ANY_EXCHANGE)),
) -> AdminExchangeResponse:
"""Cancel any trade (admin only)."""