From 48f03d8dc061858b53bcc6a37d29ba83ca72ccdc Mon Sep 17 00:00:00 2001 From: seeleng Date: Tue, 24 Sep 2024 02:20:40 +0800 Subject: [PATCH] feat: add /points/:id/notes route --- backend/src/app.py | 3 ++- backend/src/notes/router.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/src/app.py b/backend/src/app.py index f6de8664..7299c006 100644 --- a/backend/src/app.py +++ b/backend/src/app.py @@ -5,7 +5,7 @@ from src.profile.router import router as profile_router from src.events.router import router as events_router from src.user_questions.router import router as user_questions_router -from src.notes.router import router as notes_router +from src.notes.router import router as notes_router, points_router from contextlib import asynccontextmanager import logging @@ -40,3 +40,4 @@ async def lifespan(app: FastAPI): server.include_router(events_router) server.include_router(user_questions_router) server.include_router(notes_router) +server.include_router(points_router) diff --git a/backend/src/notes/router.py b/backend/src/notes/router.py index 5ed1e17e..a4e2c647 100644 --- a/backend/src/notes/router.py +++ b/backend/src/notes/router.py @@ -77,3 +77,21 @@ def delete_note( ): session.delete(note) session.commit() + + +points_router = APIRouter(prefix="/points", tags=["points"]) + + +@points_router.get("/:id/notes") +def get_point_notes( + user: Annotated[User, Depends(get_current_user)], + session=Depends(get_session), +): + # TODO: validate point + notes = session.scalars( + select(Note) + .where(Note.parent_id == id) + .where(Note.parent_type == NoteType.POINT) + .where(Note.user_id == user.id) + ) + return notes