TorbatYar/backend/services/delivery/app/commands/availability.py
Mortezakoohjani 72077908f1 feat(delivery): deploy backend phases 10.2-10.8 through settlement
Ship fleet, availability, pricing, dispatch, routing, tracking, and settlement on delivery-service 0.10.8.0 with migrations and phase tests green.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 21:01:23 +03:30

91 lines
2.9 KiB
Python

"""Availability command handlers — Phase 10.3."""
from __future__ import annotations
from uuid import UUID
from sqlalchemy.ext.asyncio import AsyncSession
from app.schemas.availability import (
DriverAvailabilityUpsert,
ShiftAssignmentCreate,
ShiftAssignmentUpdate,
ShiftCreate,
ShiftUpdate,
WorkingZoneCreate,
WorkingZoneUpdate,
)
from app.services.availability import AvailabilityService, ShiftService, WorkingZoneService
from shared.security import CurrentUser
class AvailabilityCommands:
def __init__(self, session: AsyncSession) -> None:
self.availability = AvailabilityService(session)
self.shifts = ShiftService(session)
self.zones = WorkingZoneService(session)
async def upsert_availability(
self,
tenant_id: UUID,
driver_id: UUID,
body: DriverAvailabilityUpsert,
*,
actor: CurrentUser | None,
):
return await self.availability.upsert_for_driver(
tenant_id, driver_id, body, actor=actor
)
async def create_shift(
self, tenant_id: UUID, body: ShiftCreate, *, actor: CurrentUser | None
):
return await self.shifts.create(tenant_id, body, actor=actor)
async def update_shift(
self, tenant_id: UUID, shift_id: UUID, body: ShiftUpdate, *, actor: CurrentUser | None
):
return await self.shifts.update(tenant_id, shift_id, body, actor=actor)
async def delete_shift(
self, tenant_id: UUID, shift_id: UUID, *, actor: CurrentUser | None
):
return await self.shifts.soft_delete(tenant_id, shift_id, actor=actor)
async def assign_shift(
self,
tenant_id: UUID,
shift_id: UUID,
body: ShiftAssignmentCreate,
*,
actor: CurrentUser | None,
):
return await self.shifts.assign_driver(tenant_id, shift_id, body, actor=actor)
async def update_shift_assignment(
self,
tenant_id: UUID,
shift_id: UUID,
assignment_id: UUID,
body: ShiftAssignmentUpdate,
*,
actor: CurrentUser | None,
):
return await self.shifts.update_assignment(
tenant_id, shift_id, assignment_id, body, actor=actor
)
async def create_zone(
self, tenant_id: UUID, body: WorkingZoneCreate, *, actor: CurrentUser | None
):
return await self.zones.create(tenant_id, body, actor=actor)
async def update_zone(
self, tenant_id: UUID, zone_id: UUID, body: WorkingZoneUpdate, *, actor: CurrentUser | None
):
return await self.zones.update(tenant_id, zone_id, body, actor=actor)
async def delete_zone(
self, tenant_id: UUID, zone_id: UUID, *, actor: CurrentUser | None
):
return await self.zones.soft_delete(tenant_id, zone_id, actor=actor)