68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
|
import logging
|
||
|
from datetime import datetime, timedelta
|
||
|
|
||
|
from fastapi import APIRouter, status, Path
|
||
|
from src.models.record import RecordStart, RecordInfo
|
||
|
|
||
|
router = APIRouter(prefix="/records", tags=["Records"])
|
||
|
|
||
|
|
||
|
@router.get("/", response_model=list[RecordInfo], summary="Get a list of all records")
|
||
|
async def all_tags() -> list[RecordInfo]:
|
||
|
"""Returns a list of all records."""
|
||
|
|
||
|
return [
|
||
|
RecordInfo(
|
||
|
start=datetime.now() - timedelta(hours=3),
|
||
|
end=datetime.now(),
|
||
|
project="Uni",
|
||
|
tags=["Listening Lectures", "Not be concentrated"]
|
||
|
),
|
||
|
RecordInfo(
|
||
|
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: RecordStart):
|
||
|
"""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: RecordStart):
|
||
|
"""End a record."""
|
||
|
|
||
|
print('end record', record)
|
||
|
|
||
|
|
||
|
@router.get("/{id}", response_model=RecordInfo, summary="Get a record by id")
|
||
|
async def get_record(id: str = Path(..., title="ID of the record")) -> RecordInfo:
|
||
|
"""Fetch a record by id."""
|
||
|
|
||
|
return RecordInfo(
|
||
|
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: RecordInfo, id: str = Path(..., title="ID of the record")):
|
||
|
"""Apply partial updates to a record."""
|
||
|
|
||
|
logging.debug(f"Patching record {id} with {record}")
|