import logging from datetime import datetime, timedelta from fastapi import APIRouter, status, Path from src.models.record import RecordStartCreate, RecordRead, RecordCreate router = APIRouter(prefix="/records", tags=["Records"]) @router.get("/", response_model=list[RecordRead], summary="Get a list of all records") async def all_tags() -> list[RecordRead]: """Returns a list of all records.""" return [ RecordRead( start=datetime.now() - timedelta(hours=3), end=datetime.now(), project="Uni", tags=["Listening Lectures", "Not be concentrated"] ), RecordRead( start=datetime.now() - timedelta(hours=7), end=datetime.now() - timedelta(hours=4), project="Uni", tags=["Listening Lectures", "Not be concentrated"] ) ] @router.post("/start", status_code=status.HTTP_201_CREATED, summary="Start a record") async def start_record(record: RecordStartCreate): """Start a record.""" print('starting record', record) @router.post("/end", status_code=status.HTTP_204_NO_CONTENT, summary="End a record") async def end_record(record: RecordStartCreate): """End a record.""" print('end record', record) @router.get("/{id}", response_model=RecordRead, summary="Get a record by id") async def get_record(id: str = Path(..., title="ID of the record")) -> RecordRead: """Fetch a record by id.""" return RecordRead( start=datetime.now() - timedelta(hours=3), end=datetime.now(), project="Uni", tags=["Listening Lectures", "Not be concentrated"] ) @router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT, summary="Delete a record by id") async def delete_record(id: str = Path(..., title="ID of the record")): """Delete a tag specified by name.""" logging.debug(f"Deleting record {id}") @router.patch("/{id}", summary="Apply partial updates to a record by id") async def patch_record(record: RecordCreate, id: str = Path(..., title="ID of the record")): """Apply partial updates to a record.""" logging.debug(f"Patching record {id} with {record}")