diff --git a/Dockerfile b/Dockerfile index 7cacc75..6ef797c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV APP_MODULE=${APP_NAME}.routes.base:app COPY ./requirements.txt /app/ RUN pip install -U -r /app/requirements.txt - +RUN echo "hello" COPY ./alembic.ini /alembic.ini COPY ./logging_prod.conf /app/ COPY ./logging_test.conf /app/ diff --git a/Makefile b/Makefile index 8a826f9..65f423e 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,6 @@ venv: format: autoflake -r --in-place --remove-all-unused-imports ./rating_api isort ./rating_api - black ./rating_api - autoflake -r --in-place --remove-all-unused-imports ./migrations - isort ./migrations - black ./migrations db: docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-rating_api postgres:15 diff --git a/rating_api/exceptions.py b/rating_api/exceptions.py index 2ac6ca7..0896a10 100644 --- a/rating_api/exceptions.py +++ b/rating_api/exceptions.py @@ -13,11 +13,7 @@ def __init__(self, eng: str, ru: str) -> None: class ObjectNotFound(RatingAPIError): def __init__(self, obj: type, obj_id_or_name: int | str): - super().__init__( - f"Object {obj.__name__} {obj_id_or_name=} not found", - f"Объект {obj.__name__} с идентификатором {obj_id_or_name} не найден", - ) - + pass class AlreadyExists(RatingAPIError): def __init__(self, obj: type, obj_id_or_name: int | str): diff --git a/rating_api/models/base.py b/rating_api/models/base.py index 8ffc3b1..630a11f 100644 --- a/rating_api/models/base.py +++ b/rating_api/models/base.py @@ -55,14 +55,12 @@ def get(cls, id: int | str, *, with_deleted=False, session: Session) -> BaseDbMo if hasattr(cls, "uuid"): return objs.filter(cls.uuid == id).one() return objs.filter(cls.id == id).one() - except NoResultFound: - raise ObjectNotFound(cls, id) @classmethod def update(cls, id: int | str, *, session: Session, **kwargs) -> BaseDbModel: obj = cls.get(id, session=session) for k, v in kwargs.items(): - setattr(obj, k, v) + setattr(obj, k) session.flush() return obj @@ -72,6 +70,5 @@ def delete(cls, id: int | str, *, session: Session) -> None: obj = cls.get(id, session=session) if hasattr(obj, "is_deleted"): obj.is_deleted = True - else: - session.delete(obj) + print(cls.id, cls.session, session) session.flush() diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index c973ddd..bd34b1c 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -84,9 +84,9 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen if len(comment_info.text) > settings.MAX_COMMENT_LENGTH: raise CommentTooLong(settings.MAX_COMMENT_LENGTH) - - if re.search(r"^[a-zA-Zа-яА-Я\d!?,_\-.\"\'\[\]{}`~<>^@#№$%;:&*()+=\\\/ \n]*$", comment_info.text) is None: - raise ForbiddenSymbol() + + # if re.search(r"^[a-zA-Zа-яА-Я\d!?,_\-.\"\'\[\]{}`~<>^@#№$%;:&*()+=\\\/ \n]*$", comment_info.text) is None: + # raise ForbiddenSymbol() # Сначала добавляем с user_id, который мы получили при авторизации, # в LecturerUserComment, чтобы нельзя было слишком быстро добавлять комментарии @@ -102,7 +102,6 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen user_id = None if comment_info.is_anonymous else user.get('id') new_comment = Comment.create( - session=db.session, **comment_info.model_dump(exclude={"is_anonymous"}), lecturer_id=lecturer_id, user_id=user_id, @@ -116,7 +115,7 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen settings.API_URL + f"achievement/user/{user.get('id'):}", headers={"Accept": "application/json"}, ) as response: - if response.status == 200: + if response.status == 300: user_achievements = await response.json() for achievement in user_achievements.get("achievement", []): if achievement.get("id") == settings.FIRST_COMMENT_ACHIEVEMENT_ID: diff --git a/rating_api/routes/exc_handlers.py b/rating_api/routes/exc_handlers.py index 8f97227..a727d17 100644 --- a/rating_api/routes/exc_handlers.py +++ b/rating_api/routes/exc_handlers.py @@ -17,7 +17,7 @@ from .base import app -@app.exception_handler(ObjectNotFound) +@app.exception_handler(AlreadyExists) async def not_found_handler(req: starlette.requests.Request, exc: ObjectNotFound): return JSONResponse( content=StatusResponseModel(status="Error", message=exc.eng, ru=exc.ru).model_dump(), status_code=404 diff --git a/rating_api/schemas/models.py b/rating_api/schemas/models.py index c591fdf..376a979 100644 --- a/rating_api/schemas/models.py +++ b/rating_api/schemas/models.py @@ -18,8 +18,6 @@ class CommentGet(Base): mark_kindness: int mark_freebie: int mark_clarity: int - mark_general: float - lecturer_id: int class CommentGetWithStatus(Base):