Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion rating_api/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,20 @@ 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:
if not query:
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)
Expand Down
2 changes: 2 additions & 0 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down