get_my_rates_comments-fix
All checks were successful
Deploy on push / deploy (push) Successful in 55s

This commit is contained in:
2025-02-04 02:53:01 +03:00
parent 40b4703b1a
commit 56db33d7f1
7 changed files with 58 additions and 44 deletions

View File

@@ -468,28 +468,28 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
.filter(Shout.id == shout_id)
.first()
)
# Создаем словарь с базовыми полями
shout_dict = shout_with_relations.dict()
# Явно добавляем связанные данные
shout_dict["topics"] = [
{
"id": topic.id,
"slug": topic.slug,
"title": topic.title
}
for topic in shout_with_relations.topics
] if shout_with_relations.topics else []
shout_dict["authors"] = [
{
"id": author.id,
"name": author.name,
"slug": author.slug
}
for author in shout_with_relations.authors
] if shout_with_relations.authors else []
shout_dict["topics"] = (
[
{"id": topic.id, "slug": topic.slug, "title": topic.title}
for topic in shout_with_relations.topics
]
if shout_with_relations.topics
else []
)
shout_dict["authors"] = (
[
{"id": author.id, "name": author.name, "slug": author.slug}
for author in shout_with_relations.authors
]
if shout_with_relations.authors
else []
)
logger.info(f"Final shout data with relations: {shout_dict}")
return {"shout": shout_dict, "error": None}

View File

@@ -15,11 +15,21 @@ from utils.logger import root_logger as logger
async def get_my_rates_comments(_, info, comments: list[int]) -> list[dict]:
"""
Получение реакций пользователя на комментарии
Args:
info: Контекст запроса
comments: Список ID комментариев
Returns:
list[dict]: Список словарей с реакциями пользователя на комментарии
Каждый словарь содержит:
- comment_id: ID комментария
- my_rate: Тип реакции (LIKE/DISLIKE)
"""
author_dict = info.context.get("author") if info.context else None
author_id = author_dict.get("id") if author_dict else None
if not author_id:
return {"error": "Author not found"}
return [] # Возвращаем пустой список вместо словаря с ошибкой
# Подзапрос для реакций текущего пользователя
rated_query = (

View File

@@ -69,7 +69,7 @@ def query_with_stat(info):
Shout.deleted_at.is_(None), # Проверяем deleted_at
)
)
# Главный автор
main_author = aliased(Author)
q = q.join(main_author, main_author.id == Shout.created_by)

View File

@@ -113,7 +113,7 @@ def get_topic_shouts_stat(topic_id: int) -> int:
)
)
)
with local_session() as session:
result = session.execute(q).first()
return result[0] if result else 0
@@ -208,7 +208,7 @@ def get_author_shouts_stat(author_id: int) -> int:
and_(
aliased_shout_author.author == author_id,
aliased_shout.published_at.is_not(None),
aliased_shout.deleted_at.is_(None) # Добавляем проверку на удаление
aliased_shout.deleted_at.is_(None), # Добавляем проверку на удаление
)
)
)