137 lines
3.6 KiB
Python
137 lines
3.6 KiB
Python
from io import BytesIO
|
|
|
|
from fastapi import APIRouter, Response
|
|
|
|
from backend.dependecies import SessionDependency, CurrentUserDependency, PaginationDependency
|
|
from generators.work_shifts_qr_code_generator import WorkShiftsQRCodeGenerator
|
|
from schemas.work_shifts import *
|
|
from services.work_shifts import WorkShiftsService
|
|
|
|
work_shifts_router = APIRouter(
|
|
prefix="/work-shifts",
|
|
tags=["work-shifts"],
|
|
)
|
|
|
|
|
|
@work_shifts_router.get(
|
|
"/generate-qr-code/{user_id}",
|
|
operation_id="generate_qr_code",
|
|
)
|
|
async def generate_qr_code(
|
|
session: SessionDependency,
|
|
user_id: int,
|
|
):
|
|
pdf_file: BytesIO = await WorkShiftsQRCodeGenerator(session).generate(user_id)
|
|
return Response(pdf_file.getvalue(), media_type="application/pdf")
|
|
|
|
|
|
@work_shifts_router.post(
|
|
"/start-shift/{user_id}",
|
|
response_model=StartShiftResponse,
|
|
operation_id="start_shift",
|
|
)
|
|
async def start_shift(
|
|
session: SessionDependency,
|
|
user_id: int,
|
|
):
|
|
return await WorkShiftsService(session).start_shift(user_id)
|
|
|
|
|
|
@work_shifts_router.post(
|
|
"/finish-shift/{user_id}",
|
|
response_model=FinishShiftResponse,
|
|
operation_id="finish_shift",
|
|
)
|
|
async def finish_shift(
|
|
session: SessionDependency,
|
|
user_id: int,
|
|
user: CurrentUserDependency,
|
|
):
|
|
return await WorkShiftsService(session).finish_shift_by_user_id(user, user_id)
|
|
|
|
|
|
@work_shifts_router.post(
|
|
"/finish-shift-by-id/{shift_id}",
|
|
response_model=FinishShiftByIdResponse,
|
|
operation_id="finish_work_shift_by_id",
|
|
)
|
|
async def finish_work_shift_by_id(
|
|
session: SessionDependency,
|
|
user: CurrentUserDependency,
|
|
shift_id: int,
|
|
):
|
|
return await WorkShiftsService(session).finish_shift_by_id(user, shift_id)
|
|
|
|
|
|
@work_shifts_router.get(
|
|
"/get-shifts/{is_active}",
|
|
response_model=GetWorkShiftsResponse,
|
|
operation_id="get_shifts",
|
|
)
|
|
async def get_shifts(
|
|
session: SessionDependency,
|
|
pagination: PaginationDependency,
|
|
is_active: bool,
|
|
):
|
|
return await WorkShiftsService(session).get_shifts(is_active, pagination)
|
|
|
|
|
|
@work_shifts_router.delete(
|
|
"/delete-shift/{shift_id}",
|
|
response_model=DeleteShiftResponse,
|
|
operation_id="delete_work_shift",
|
|
)
|
|
async def delete_work_shift(
|
|
session: SessionDependency,
|
|
shift_id: int,
|
|
):
|
|
return await WorkShiftsService(session).delete_shift(shift_id)
|
|
|
|
|
|
@work_shifts_router.post(
|
|
"/pause/start/{shift_id}",
|
|
response_model=StartPauseByShiftIdResponse,
|
|
operation_id="start_pause_by_shift_id",
|
|
)
|
|
async def start_pause_by_shift_id(
|
|
session: SessionDependency,
|
|
shift_id: int,
|
|
):
|
|
return await WorkShiftsService(session).start_pause_by_shift_id(shift_id)
|
|
|
|
|
|
@work_shifts_router.post(
|
|
"/pause/start/for-user/{user_id}",
|
|
response_model=StartPauseByUserIdResponse,
|
|
operation_id="start_pause_by_user_id",
|
|
)
|
|
async def start_pause_by_user_id(
|
|
session: SessionDependency,
|
|
user_id: int,
|
|
):
|
|
return await WorkShiftsService(session).start_pause_by_user_id(user_id)
|
|
|
|
|
|
@work_shifts_router.post(
|
|
"/pause/finish/{shift_id}",
|
|
response_model=FinishPauseByShiftIdResponse,
|
|
operation_id="finish_pause_by_shift_id",
|
|
)
|
|
async def finish_pause_by_shift_id(
|
|
session: SessionDependency,
|
|
shift_id: int,
|
|
):
|
|
return await WorkShiftsService(session).finish_pause_by_shift_id(shift_id)
|
|
|
|
|
|
@work_shifts_router.post(
|
|
"/pause/finish/for-user/{shift_id}",
|
|
response_model=FinishPauseByUserIdResponse,
|
|
operation_id="finish_pause_by_user_id",
|
|
)
|
|
async def finish_pause_by_user_id(
|
|
session: SessionDependency,
|
|
user_id: int,
|
|
):
|
|
return await WorkShiftsService(session).finish_pause_by_user_id(user_id)
|