From c1aff93cb747757b0ce2a9d8c6e66f52a17650d6 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Tue, 18 Nov 2025 23:25:12 +0300 Subject: [PATCH 1/4] updated comments --- ...f91_add_user_full_name_to_comment_table.py | 28 +++++++++++++++++++ rating_api/models/db.py | 1 + rating_api/routes/comment.py | 7 +++++ rating_api/schemas/models.py | 1 + 4 files changed, 37 insertions(+) create mode 100644 migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py diff --git a/migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py b/migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py new file mode 100644 index 0000000..838dc21 --- /dev/null +++ b/migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py @@ -0,0 +1,28 @@ +"""Add user_full_name to Comment table + +Revision ID: d322e8331f91 +Revises: beb11fd89531 +Create Date: 2025-11-18 23:16:20.029675 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'd322e8331f91' +down_revision = 'beb11fd89531' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('comment', sa.Column('user_fullname', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('comment', 'user_fullname') + # ### end Alembic commands ### diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 4724411..e9c473f 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -135,6 +135,7 @@ def order_by_name( class Comment(BaseDbModel): uuid: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) user_id: Mapped[int] = mapped_column(Integer, nullable=True) + user_fullname: Mapped[str | None] = mapped_column(String, nullable=True, default=None) create_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False) update_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False) subject: Mapped[str] = mapped_column(String, nullable=True) diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index 9011277..2c16fdc 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -102,11 +102,18 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen # Обрабатываем анонимность комментария, и удаляем этот флаг чтобы добавить запись в БД user_id = None if comment_info.is_anonymous else user.get('id') + user_fullname = None + if not comment_info.is_anonymous: + userdata_info = user.get("userdata", []) + fullname_info = list(filter(lambda x: "Полное имя" == x['param'], userdata_info)) + user_fullname = fullname_info[0]["value"] if len(fullname_info) != 0 else None + new_comment = Comment.create( session=db.session, **comment_info.model_dump(exclude={"is_anonymous"}), lecturer_id=lecturer_id, user_id=user_id, + user_fullname=user_fullname, review_status=ReviewStatus.PENDING, ) diff --git a/rating_api/schemas/models.py b/rating_api/schemas/models.py index ad1b0a0..b99fede 100644 --- a/rating_api/schemas/models.py +++ b/rating_api/schemas/models.py @@ -25,6 +25,7 @@ class CommentGet(Base): lecturer_id: int like_count: int dislike_count: int + user_fullname: str | None = None class CommentGetWithStatus(CommentGet): From 22ca550b5b159a34f06a4a28437201127cb6f6c6 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Tue, 18 Nov 2025 23:39:04 +0300 Subject: [PATCH 2/4] Formated migration file --- .../d322e8331f91_add_user_full_name_to_comment_table.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py b/migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py index 838dc21..d7b089e 100644 --- a/migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py +++ b/migrations/versions/d322e8331f91_add_user_full_name_to_comment_table.py @@ -5,8 +5,9 @@ Create Date: 2025-11-18 23:16:20.029675 """ -from alembic import op + import sqlalchemy as sa +from alembic import op # revision identifiers, used by Alembic. From 0ee11ab1cdec104d831f609a777193f93ecd294f Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Wed, 19 Nov 2025 22:34:04 +0300 Subject: [PATCH 3/4] made small fixes --- ...ff796adace_small_edit_for_user_fullname.py | 25 +++++++++++++++++++ rating_api/models/db.py | 2 +- rating_api/routes/comment.py | 6 ++--- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/e3ff796adace_small_edit_for_user_fullname.py diff --git a/migrations/versions/e3ff796adace_small_edit_for_user_fullname.py b/migrations/versions/e3ff796adace_small_edit_for_user_fullname.py new file mode 100644 index 0000000..e14e6ff --- /dev/null +++ b/migrations/versions/e3ff796adace_small_edit_for_user_fullname.py @@ -0,0 +1,25 @@ +"""small_edit_for_user_fullname + +Revision ID: e3ff796adace +Revises: d322e8331f91 +Create Date: 2025-11-19 22:31:52.469988 + +""" + +# revision identifiers, used by Alembic. +revision = 'e3ff796adace' +down_revision = 'd322e8331f91' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ### diff --git a/rating_api/models/db.py b/rating_api/models/db.py index e9c473f..6929947 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -135,7 +135,7 @@ def order_by_name( class Comment(BaseDbModel): uuid: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) user_id: Mapped[int] = mapped_column(Integer, nullable=True) - user_fullname: Mapped[str | None] = mapped_column(String, nullable=True, default=None) + user_fullname: Mapped[str | None] = mapped_column(String, nullable=True) create_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False) update_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False) subject: Mapped[str] = mapped_column(String, nullable=True) diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index 2c16fdc..2d5579e 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -102,18 +102,18 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen # Обрабатываем анонимность комментария, и удаляем этот флаг чтобы добавить запись в БД user_id = None if comment_info.is_anonymous else user.get('id') - user_fullname = None + fullname = None if not comment_info.is_anonymous: userdata_info = user.get("userdata", []) fullname_info = list(filter(lambda x: "Полное имя" == x['param'], userdata_info)) - user_fullname = fullname_info[0]["value"] if len(fullname_info) != 0 else None + fullname = fullname_info[0]["value"] if len(fullname_info) != 0 else None new_comment = Comment.create( session=db.session, **comment_info.model_dump(exclude={"is_anonymous"}), lecturer_id=lecturer_id, user_id=user_id, - user_fullname=user_fullname, + user_fullname=fullname, review_status=ReviewStatus.PENDING, ) From 62f828e50a12ddc916540fd596cb8a9e750bae86 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Wed, 19 Nov 2025 23:34:27 +0300 Subject: [PATCH 4/4] deleted empty migration file --- ...ff796adace_small_edit_for_user_fullname.py | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 migrations/versions/e3ff796adace_small_edit_for_user_fullname.py diff --git a/migrations/versions/e3ff796adace_small_edit_for_user_fullname.py b/migrations/versions/e3ff796adace_small_edit_for_user_fullname.py deleted file mode 100644 index e14e6ff..0000000 --- a/migrations/versions/e3ff796adace_small_edit_for_user_fullname.py +++ /dev/null @@ -1,25 +0,0 @@ -"""small_edit_for_user_fullname - -Revision ID: e3ff796adace -Revises: d322e8331f91 -Create Date: 2025-11-19 22:31:52.469988 - -""" - -# revision identifiers, used by Alembic. -revision = 'e3ff796adace' -down_revision = 'd322e8331f91' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - pass - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - pass - # ### end Alembic commands ###