diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 99d46d6..f7ef0ef 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 Comment.lecturer_id == query + return and_(Comment.review_status == ReviewStatus.APPROVED, Comment.lecturer_id == query) @hybrid_method def search_by_user_id(self, query: int) -> bool: @@ -149,7 +149,7 @@ def search_by_user_id(self, query: int) -> bool: def search_by_subject(self, query: str) -> bool: if not query: return true() - return func.lower(Comment.subject).contains(query.lower()) + 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 529398c..85ec635 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -260,8 +260,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",