add-main_topic
All checks were successful
deploy / deploy (push) Successful in 1m32s

This commit is contained in:
Untone 2023-12-09 19:22:47 +03:00
parent c1adaf3ed6
commit 724e9bd5a0
2 changed files with 20 additions and 0 deletions

View File

@ -100,6 +100,11 @@ async def get_shout(_, _info, slug=None, shout_id=None):
for author in shout.authors: for author in shout.authors:
if author.id == author_caption.author: if author.id == author_caption.author:
author.caption = author_caption.caption author.caption = author_caption.caption
shout.main_topic = session.query(ShoutTopics.topic_slug).filter(
ShoutTopics.shout_id == shout.id,
ShoutTopics.main == True
).first()
return shout return shout
except Exception: except Exception:
raise HTTPException(status_code=404, detail=f"shout {slug or shout_id} not found") raise HTTPException(status_code=404, detail=f"shout {slug or shout_id} not found")
@ -125,6 +130,7 @@ async def load_shouts_by(_, _info, options):
} }
:return: Shout[] :return: Shout[]
""" """
# base # base
q = ( q = (
select(Shout) select(Shout)
@ -157,6 +163,11 @@ async def load_shouts_by(_, _info, options):
shouts = [] shouts = []
with local_session() as session: with local_session() as session:
for [shout, reacted_stat, commented_stat, rating_stat, _last_comment] in session.execute(q).unique(): for [shout, reacted_stat, commented_stat, rating_stat, _last_comment] in session.execute(q).unique():
# Query the ShoutTopics table for the main topic
shout.main_topic = session.query(ShoutTopics.topic_slug).filter(
ShoutTopics.shout_id == shout.id,
ShoutTopics.main == True
).first()
shout.stat = { shout.stat = {
"viewed": await ViewedStorage.get_shout(shout.slug), "viewed": await ViewedStorage.get_shout(shout.slug),
"reacted": reacted_stat, "reacted": reacted_stat,
@ -190,6 +201,10 @@ async def load_shouts_drafts(_, info):
q = q.filter(Shout.created_by == reader.id) q = q.filter(Shout.created_by == reader.id)
q = q.group_by(Shout.id) q = q.group_by(Shout.id)
for [shout] in session.execute(q).unique(): for [shout] in session.execute(q).unique():
shout.main_topic = session.query(ShoutTopics.topic_slug).filter(
ShoutTopics.shout_id == shout.id,
ShoutTopics.main == True
).first()
shouts.append(shout) shouts.append(shout)
return shouts return shouts
@ -242,6 +257,10 @@ async def load_shouts_feed(_, info, options):
shouts = [] shouts = []
for [shout, reacted_stat, commented_stat, rating_stat, _last_comment] in session.execute(q).unique(): for [shout, reacted_stat, commented_stat, rating_stat, _last_comment] in session.execute(q).unique():
shout.main_topic = session.query(ShoutTopics.topic_slug).filter(
ShoutTopics.shout_id == shout.id,
ShoutTopics.main == True
).first()
shout.stat = { shout.stat = {
"viewed": await ViewedStorage.get_shout(shout.slug), "viewed": await ViewedStorage.get_shout(shout.slug),
"reacted": reacted_stat, "reacted": reacted_stat,

View File

@ -115,6 +115,7 @@ type Shout {
lead: String lead: String
description: String description: String
created_at: Int! created_at: Int!
main_topic: String
topics: [Topic] topics: [Topic]
created_by: Author! created_by: Author!
updated_by: Author updated_by: Author