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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Add user_full_name to Comment table

Revision ID: d322e8331f91
Revises: beb11fd89531
Create Date: 2025-11-18 23:16:20.029675

"""

import sqlalchemy as sa
from alembic import op


# 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 ###
1 change: 1 addition & 0 deletions rating_api/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)
Expand Down
7 changes: 7 additions & 0 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

fullname = None
if not comment_info.is_anonymous:
userdata_info = user.get("userdata", [])
fullname_info = list(filter(lambda x: "Полное имя" == x['param'], userdata_info))
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=fullname,
review_status=ReviewStatus.PENDING,
)

Expand Down
1 change: 1 addition & 0 deletions rating_api/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CommentGet(Base):
lecturer_id: int
like_count: int
dislike_count: int
user_fullname: str | None = None


class CommentGetWithStatus(CommentGet):
Expand Down