diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 28b75fa..99d46d6 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -137,7 +137,7 @@ def order_by_mark(self, query: str, asc_order: bool) -> UnaryExpression[float] | def search_by_lectorer_id(self, query: int) -> bool: if not query: return true() - return and_(Comment.review_status == ReviewStatus.APPROVED, Comment.lecturer_id == query) + return Comment.lecturer_id == query @hybrid_method def search_by_user_id(self, query: int) -> bool: @@ -145,6 +145,12 @@ def search_by_user_id(self, query: int) -> bool: return true() return Comment.user_id == query + @hybrid_method + def search_by_subject(self, query: str) -> bool: + if not query: + return true() + return func.lower(Comment.subject).contains(query.lower()) + class LecturerUserComment(BaseDbModel): id: Mapped[int] = mapped_column(Integer, primary_key=True) diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index 787113a..529398c 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -173,6 +173,7 @@ async def get_comments( offset: int = 0, lecturer_id: int | None = None, user_id: int | None = None, + subject: str | None = None, order_by: str = Query( enum=["create_ts", "mark_kindness", "mark_freebie", "mark_clarity", "mark_general"], default="create_ts", @@ -206,6 +207,7 @@ async def get_comments( Comment.query(session=db.session) .filter(Comment.search_by_lectorer_id(lecturer_id)) .filter(Comment.search_by_user_id(user_id)) + .filter(Comment.search_by_subject(subject)) .order_by( Comment.order_by_mark(order_by, asc_order) if "mark" in order_by