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

This commit is contained in:
Untone 2025-02-12 00:31:18 +03:00
parent 5a4f75537d
commit 52b608da99
6 changed files with 22 additions and 9 deletions

View File

@ -1,6 +1,5 @@
import time
from sqlalchemy import select
from sqlalchemy.sql import and_
from cache.cache import (

View File

@ -12,16 +12,14 @@ from cache.cache import (
invalidate_shouts_cache,
)
from orm.author import Author
from orm.draft import Draft
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.topic import Topic
from resolvers.draft import create_draft, publish_draft
from resolvers.follower import follow, unfollow
from resolvers.stat import get_with_stat
from services.auth import login_required
from services.db import local_session
from services.notify import notify_shout
from services.schema import mutation, query
from services.schema import query
from services.search import search_service
from utils.logger import root_logger as logger
@ -582,6 +580,9 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
else []
)
# Add main_topic to the shout dictionary
shout_dict["main_topic"] = get_main_topic_slug(shout_with_relations.topics)
shout_dict["authors"] = (
[
{"id": author.id, "name": author.name, "slug": author.slug}
@ -641,3 +642,19 @@ async def delete_shout(_, info, shout_id: int):
return {"error": None}
else:
return {"error": "access denied"}
def get_main_topic_slug(topics):
"""Get the slug of the main topic from a list of topics.
Args:
topics: List of ShoutTopic objects
Returns:
str: Slug of the main topic, or None if no main topic found
"""
if not topics:
return None
main_topic = next((t for t in topics.reverse() if t.main), None)
return main_topic.topic.slug if main_topic else { "slug": "notopic", "title": "no topic", "id": 0 }

View File

@ -9,7 +9,6 @@ from starlette.testclient import TestClient
from main import app
from services.db import Base
from services.redis import redis
from settings import DB_URL
# Use SQLite for testing
TEST_DB_URL = "sqlite:///test.db"

View File

@ -3,7 +3,7 @@ from datetime import datetime
import pytest
from orm.author import Author
from orm.reaction import Reaction, ReactionKind
from orm.reaction import ReactionKind
from orm.shout import Shout

View File

@ -6,9 +6,7 @@ from pydantic import ValidationError
from auth.validations import (
AuthInput,
AuthResponse,
OAuthInput,
TokenPayload,
UserLoginInput,
UserRegistrationInput,
)

View File

@ -105,7 +105,7 @@ root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(stream)
root_logger.addFilter(filter)
ignore_logs = ["_trace", "httpx", "_client", "_trace.atrace", "aiohttp", "_client"]
ignore_logs = ["_trace", "httpx", "_client", "atrace", "aiohttp", "_client"]
for lgr in ignore_logs:
loggr = logging.getLogger(lgr)
loggr.setLevel(logging.INFO)