Skip to content

Commit c1aff93

Browse files
updated comments
1 parent 69b1456 commit c1aff93

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Add user_full_name to Comment table
2+
3+
Revision ID: d322e8331f91
4+
Revises: beb11fd89531
5+
Create Date: 2025-11-18 23:16:20.029675
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'd322e8331f91'
14+
down_revision = 'beb11fd89531'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('comment', sa.Column('user_fullname', sa.String(), nullable=True))
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade():
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
op.drop_column('comment', 'user_fullname')
28+
# ### end Alembic commands ###

rating_api/models/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def order_by_name(
135135
class Comment(BaseDbModel):
136136
uuid: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4)
137137
user_id: Mapped[int] = mapped_column(Integer, nullable=True)
138+
user_fullname: Mapped[str | None] = mapped_column(String, nullable=True, default=None)
138139
create_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False)
139140
update_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False)
140141
subject: Mapped[str] = mapped_column(String, nullable=True)

rating_api/routes/comment.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,18 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen
102102
# Обрабатываем анонимность комментария, и удаляем этот флаг чтобы добавить запись в БД
103103
user_id = None if comment_info.is_anonymous else user.get('id')
104104

105+
user_fullname = None
106+
if not comment_info.is_anonymous:
107+
userdata_info = user.get("userdata", [])
108+
fullname_info = list(filter(lambda x: "Полное имя" == x['param'], userdata_info))
109+
user_fullname = fullname_info[0]["value"] if len(fullname_info) != 0 else None
110+
105111
new_comment = Comment.create(
106112
session=db.session,
107113
**comment_info.model_dump(exclude={"is_anonymous"}),
108114
lecturer_id=lecturer_id,
109115
user_id=user_id,
116+
user_fullname=user_fullname,
110117
review_status=ReviewStatus.PENDING,
111118
)
112119

rating_api/schemas/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CommentGet(Base):
2525
lecturer_id: int
2626
like_count: int
2727
dislike_count: int
28+
user_fullname: str | None = None
2829

2930

3031
class CommentGetWithStatus(CommentGet):

0 commit comments

Comments
 (0)