-
Notifications
You must be signed in to change notification settings - Fork 3
Лайки к комментариям #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary
|
|
Что нужно обсудить/сделать:
|
Если функционально это аналогично, я бы сказал, что нужны |
| from sqlalchemy import UUID, Boolean, DateTime | ||
| from sqlalchemy import Enum as DbEnum | ||
| from sqlalchemy import ForeignKey, Integer, String, UnaryExpression, and_, func, nulls_last, or_, true | ||
| from sqlalchemy import ForeignKey, Integer, String, UnaryExpression, and_, func, nulls_last, or_, select, true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем селект
| class CommentLike(BaseDbModel): | ||
| id: Mapped[int] = mapped_column(Integer, primary_key=True) | ||
| user_id: Mapped[int] = mapped_column(Integer, nullable=False) | ||
| comment_uuid: Mapped[uuid.UUID] = mapped_column(UUID, nullable=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а мб отношение полноценное сделаем?
| like_counts = ( | ||
| select(CommentLike.comment_uuid, func.count(CommentLike.id).label('like_count')) | ||
| .where(CommentLike.is_deleted == False) | ||
| .group_by(CommentLike.comment_uuid) | ||
| .alias("like_counts") | ||
| ) | ||
| # получаем комменты с лайками к ним | ||
| comments_query = select(Comment, func.coalesce(like_counts.c.like_count, 0).label('like_count')).outerjoin( | ||
| like_counts, Comment.uuid == like_counts.c.comment_uuid | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
мб вынесем всю эту логику в гибрид-метод?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это я так, на скорую руку писал, нужно будет переделать, да
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
мне кажется, я тогда с джоином не разобрался как его без селекта сделать
| else: | ||
| if "rating.comment.review" not in [scope['name'] for scope in user.get('session_scopes')]: | ||
| raise ForbiddenAction(Comment) | ||
| comments_query = comments_query.where(Comment.review_status == ReviewStatus.PENDING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно через фильтр а не через where, чтобы стилистику кода сохранять
|
|
||
| comments_query = comments_query.offset(offset).limit(limit) | ||
|
|
||
| comments_with_likes = db.session.execute(comments_query).all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ну вот так не пишем, тоже не наш стиль бэкенда
|
💩 Code linting failed, use |
Изменения
Добавление функционала лайков на комментарии.
Детали реализации
Check-List
blackиisortдля Back-End илиPrettierдля Front-End?