2021-12-21 21:00:58 +01:00
|
|
|
import logging
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
from fastapi import APIRouter, status, Path
|
2021-12-22 09:06:08 +01:00
|
|
|
from src.models.record import RecordStartCreate, RecordRead, RecordCreate
|
2021-12-21 21:00:58 +01:00
|
|
|
|
|
|
|
router = APIRouter(prefix="/records", tags=["Records"])
|
|
|
|
|
|
|
|
|
2021-12-22 09:06:08 +01:00
|
|
|
@router.get("/", response_model=list[RecordRead], summary="Get a list of all records")
|
|
|
|
async def all_tags() -> list[RecordRead]:
|
2021-12-21 21:00:58 +01:00
|
|
|
"""Returns a list of all records."""
|
|
|
|
|
|
|
|
return [
|
2021-12-22 09:06:08 +01:00
|
|
|
RecordRead(
|
2021-12-21 21:00:58 +01:00
|
|
|
start=datetime.now() - timedelta(hours=3),
|
|
|
|
end=datetime.now(),
|
|
|
|
project="Uni",
|
|
|
|
tags=["Listening Lectures", "Not be concentrated"]
|
|
|
|
),
|
2021-12-22 09:06:08 +01:00
|
|
|
RecordRead(
|
2021-12-21 21:00:58 +01:00
|
|
|
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")
|
2021-12-22 09:06:08 +01:00
|
|
|
async def start_record(record: RecordStartCreate):
|
2021-12-21 21:00:58 +01:00
|
|
|
"""Start a record."""
|
|
|
|
|
|
|
|
print('starting record', record)
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/end", status_code=status.HTTP_204_NO_CONTENT, summary="End a record")
|
2021-12-22 09:06:08 +01:00
|
|
|
async def end_record(record: RecordStartCreate):
|
2021-12-21 21:00:58 +01:00
|
|
|
"""End a record."""
|
|
|
|
|
|
|
|
print('end record', record)
|
|
|
|
|
|
|
|
|
2021-12-22 09:06:08 +01:00
|
|
|
@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:
|
2021-12-21 21:00:58 +01:00
|
|
|
"""Fetch a record by id."""
|
|
|
|
|
2021-12-22 09:06:08 +01:00
|
|
|
return RecordRead(
|
2021-12-21 21:00:58 +01:00
|
|
|
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")
|
2021-12-22 09:06:08 +01:00
|
|
|
async def patch_record(record: RecordCreate, id: str = Path(..., title="ID of the record")):
|
2021-12-21 21:00:58 +01:00
|
|
|
"""Apply partial updates to a record."""
|
|
|
|
|
|
|
|
logging.debug(f"Patching record {id} with {record}")
|