|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Annotated |
| 3 | + |
| 4 | +from fastapi import APIRouter |
| 5 | +from fastapi import Depends |
| 6 | + |
| 7 | +from wacruit.src.apps.common.schemas import ListResponse |
| 8 | +from wacruit.src.apps.pre_registration.models import PreRegistration |
| 9 | +from wacruit.src.apps.pre_registration.schemas import CreatePreRegistrationRequest |
| 10 | +from wacruit.src.apps.pre_registration.schemas import PreRegistrationResponse |
| 11 | +from wacruit.src.apps.pre_registration.schemas import UpdatePreRegistrationRequest |
| 12 | +from wacruit.src.apps.pre_registration.services import PreRegistrationService |
| 13 | +from wacruit.src.apps.user.dependencies import AdminUser |
| 14 | + |
| 15 | +v3_router = APIRouter(prefix="/v3/pre-registration", tags=["preregistration"]) |
| 16 | + |
| 17 | + |
| 18 | +@v3_router.get("/active", status_code=HTTPStatus.OK) |
| 19 | +def get_active_pre_registration( |
| 20 | + pre_registration_service: Annotated[PreRegistrationService, Depends()] |
| 21 | +) -> PreRegistrationResponse: |
| 22 | + pre_registration = pre_registration_service.get_active_pre_registration() |
| 23 | + return PreRegistrationResponse.from_orm(pre_registration) |
| 24 | + |
| 25 | + |
| 26 | +@v3_router.get("", status_code=HTTPStatus.OK) |
| 27 | +def get_pre_registration( |
| 28 | + admin_user: AdminUser, |
| 29 | + pre_registration_service: Annotated[PreRegistrationService, Depends()], |
| 30 | +) -> ListResponse[PreRegistrationResponse]: |
| 31 | + pre_registration_list = pre_registration_service.get_pre_registration() |
| 32 | + return ListResponse( |
| 33 | + items=[PreRegistrationResponse.from_orm(item) for item in pre_registration_list] |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +@v3_router.post("", status_code=HTTPStatus.CREATED) |
| 38 | +def create_pre_registration( |
| 39 | + admin_user: AdminUser, |
| 40 | + request: CreatePreRegistrationRequest, |
| 41 | + pre_registration_service: Annotated[PreRegistrationService, Depends()], |
| 42 | +) -> PreRegistrationResponse: |
| 43 | + res = pre_registration_service.create_pre_registration(request) |
| 44 | + return PreRegistrationResponse.from_orm(res) |
| 45 | + |
| 46 | + |
| 47 | +@v3_router.patch("/{pre_registration_id}", status_code=HTTPStatus.OK) |
| 48 | +def update_pre_registration( |
| 49 | + admin_user: AdminUser, |
| 50 | + request: UpdatePreRegistrationRequest, |
| 51 | + pre_registration_id: int, |
| 52 | + pre_registration_service: Annotated[PreRegistrationService, Depends()], |
| 53 | +) -> PreRegistrationResponse: |
| 54 | + res = pre_registration_service.update_pre_registration(pre_registration_id, request) |
| 55 | + return PreRegistrationResponse.from_orm(res) |
| 56 | + |
| 57 | + |
| 58 | +@v3_router.delete("/{pre_registration_id}", status_code=HTTPStatus.NO_CONTENT) |
| 59 | +def delete_pre_registration( |
| 60 | + admin_user: AdminUser, |
| 61 | + pre_registration_id: int, |
| 62 | + pre_registration_service: Annotated[PreRegistrationService, Depends()], |
| 63 | +) -> None: |
| 64 | + pre_registration_service.delete_pre_registration(pre_registration_id) |
0 commit comments