From c9665549e09056ced229f2692c01512944025094 Mon Sep 17 00:00:00 2001 From: Zimovchik <63729114+Zimovchik@users.noreply.github.com> Date: Sat, 3 May 2025 10:47:45 +0300 Subject: [PATCH 1/5] added new suject filter for comment --- rating_api/models/db.py | 5 +++++ rating_api/routes/comment.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 28b75fa..3c3ae21 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -144,6 +144,11 @@ 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 and_(Comment.review_status == ReviewStatus.APPROVED, func.lower(Comment.subject).contains(query)) class LecturerUserComment(BaseDbModel): diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index b17ffa0..8194b96 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 From c61c944acd83a6b141a0f296e348fd1063c5b75e Mon Sep 17 00:00:00 2001 From: MikhailPI1 Date: Sat, 3 May 2025 15:20:16 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20true()=20->=20true=20=D0=B2=20db?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rating_api/models/db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 28b75fa..d967344 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -136,13 +136,13 @@ def order_by_mark(self, query: str, asc_order: bool) -> UnaryExpression[float] | @hybrid_method def search_by_lectorer_id(self, query: int) -> bool: if not query: - return true() + return true return and_(Comment.review_status == ReviewStatus.APPROVED, Comment.lecturer_id == query) @hybrid_method def search_by_user_id(self, query: int) -> bool: if not query: - return true() + return true return Comment.user_id == query From bf154dbe476a25f09d9f307dde44f8635b53fb9f Mon Sep 17 00:00:00 2001 From: MikhailPI1 Date: Wed, 14 May 2025 19:57:51 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=91=D1=8B=D0=BB=D0=B0=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D1=80=D1=86=D0=B0=D0=B8=D1=8F=20uuid=20=D0=B2=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D1=82=D1=83=D1=80=D1=83=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rating_api/models/db.py | 1 + rating_api/routes/comment.py | 2 +- tests/conftest.py | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 97412a0..9e9fd7f 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -144,6 +144,7 @@ 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: diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index 8194b96..b7b8151 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -264,8 +264,8 @@ async def review_comment( `approved` - комментарий одобрен и возвращается при запросе лектора `dismissed` - комментарий отклонен, не отображается в запросе лектора """ - check_comment: Comment = Comment.query(session=db.session).filter(Comment.uuid == uuid).one_or_none() + if not check_comment: raise ObjectNotFound(Comment, uuid) diff --git a/tests/conftest.py b/tests/conftest.py index cfc960f..88687b6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +import uuid + import pytest from fastapi.testclient import TestClient from sqlalchemy import create_engine @@ -46,6 +48,7 @@ def lecturer(dbsession): @pytest.fixture def comment(dbsession, lecturer): _comment = Comment( + uuid=uuid.uuid4(), user_id=0, create_ts="2025-04-25T19:38:56.408Z", subject="test_subject", From ba0b4ae7763327d11e1d647834cc6b80ae657ed4 Mon Sep 17 00:00:00 2001 From: MikhailPI1 Date: Sun, 13 Jul 2025 12:02:36 +0400 Subject: [PATCH 4/5] Update db.py --- rating_api/models/db.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 57771ae..64abf1b 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -139,7 +139,6 @@ def search_by_lectorer_id(self, query: int) -> bool: return true() return and_(Comment.review_status == ReviewStatus.APPROVED, Comment.lecturer_id == query) - @hybrid_method def search_by_user_id(self, query: int) -> bool: if not query: From 2c3da4da890c675ae812e50b07c6ffb1e449bf89 Mon Sep 17 00:00:00 2001 From: MikhailPI1 Date: Sun, 13 Jul 2025 12:03:30 +0400 Subject: [PATCH 5/5] Update db.py --- rating_api/models/db.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 64abf1b..f7ef0ef 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -152,7 +152,6 @@ def search_by_subject(self, query: str) -> bool: return and_(Comment.review_status == ReviewStatus.APPROVED, func.lower(Comment.subject).contains(query)) - class LecturerUserComment(BaseDbModel): id: Mapped[int] = mapped_column(Integer, primary_key=True) user_id: Mapped[int] = mapped_column(Integer, nullable=False)