Skip to content

Commit 21fc7e5

Browse files
authored
Merge pull request #158 from profcomff/add_user_fullname_for_comment
2 parents 69b1456 + 62f828e commit 21fc7e5

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = 'd322e8331f91'
15+
down_revision = 'beb11fd89531'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.add_column('comment', sa.Column('user_fullname', sa.String(), nullable=True))
23+
# ### end Alembic commands ###
24+
25+
26+
def downgrade():
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
op.drop_column('comment', 'user_fullname')
29+
# ### 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)
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+
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+
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=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)