Skip to content

Conversation

@Zimovchik
Copy link
Member

Изменения

Добавление функционала лайков на комментарии.

Детали реализации

  • Юзер может поставить или убрать лайк с коммента
  • Нельзя поставить больше 1 лайка на комментарий
  • При дергании get_comments лайки считаются для всех комментов одним запросов в базу

Check-List

  • Вы проверили свой код перед отправкой запроса?
  • Вы написали тесты к реализованным функциям?
  • Вы не забыли применить форматирование black и isort для Back-End или Prettier для Front-End?

Захаров Иван Михайлович added 2 commits February 14, 2025 13:43
@Zimovchik Zimovchik self-assigned this Feb 15, 2025
@Zimovchik Zimovchik linked an issue Feb 15, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Feb 15, 2025

Summary

Tests Skipped Failures Errors Time
51 0 💤 4 ❌ 0 🔥 8.530s ⏱️

@Zimovchik
Copy link
Member Author

Zimovchik commented Feb 15, 2025

Что нужно обсудить/сделать:

  1. Нужны ли нам дизлайки или хватит только лайков
  2. Нужно написать тесты
  3. Посмотреть скорость расчета количества лайков, когда комментариев много
  4. Добавить сортировку комментариев по лайкам

@MarkShidran
Copy link
Member

Что нужно обсудить/сделать:

  1. Нужны ли нам дизлайки или хватит только лайков

Если функционально это аналогично, я бы сказал, что нужны

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
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а мб отношение полноценное сделаем?

Comment on lines +185 to +194
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
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мб вынесем всю эту логику в гибрид-метод?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это я так, на скорую руку писал, нужно будет переделать, да

Copy link
Member Author

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)
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну вот так не пишем, тоже не наш стиль бэкенда

@github-actions
Copy link

github-actions bot commented Apr 8, 2025

💩 Code linting failed, use black and isort to fix it.

@Zimovchik Zimovchik closed this Jul 26, 2025
@Zimovchik Zimovchik deleted the likes branch July 26, 2025 13:02
@Zimovchik
Copy link
Member Author

#132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

лайки/дизлайки на отзывы

4 participants