This commit is contained in:
parent
b992a73698
commit
1f6f722eef
|
@ -100,7 +100,17 @@ 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(Topic.slug).join(ShoutTopic, and_(ShoutTopic.topic == Topic.id, ShoutTopic.shout == shout.id, ShoutTopic.main == True)).first().pop()
|
main_topic = (
|
||||||
|
session.query(ShoutTopics.topic_slug)
|
||||||
|
.filter(
|
||||||
|
ShoutTopics.shout_id == shout.id,
|
||||||
|
ShoutTopics.main == True
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
|
||||||
|
if main_topic:
|
||||||
|
shout.main_topic = main_topic[0]
|
||||||
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")
|
||||||
|
@ -159,7 +169,17 @@ 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():
|
||||||
shout.main_topic = session.query(Topic.slug).join(ShoutTopic, and_(ShoutTopic.topic == Topic.id, ShoutTopic.shout == shout.id, ShoutTopic.main == True)).first().pop()
|
main_topic = (
|
||||||
|
session.query(ShoutTopics.topic_slug)
|
||||||
|
.filter(
|
||||||
|
ShoutTopics.shout_id == shout.id,
|
||||||
|
ShoutTopics.main == True
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
|
||||||
|
if main_topic:
|
||||||
|
shout.main_topic = main_topic[0]
|
||||||
shout.stat = {
|
shout.stat = {
|
||||||
"viewed": await ViewedStorage.get_shout(shout.slug),
|
"viewed": await ViewedStorage.get_shout(shout.slug),
|
||||||
"reacted": reacted_stat,
|
"reacted": reacted_stat,
|
||||||
|
@ -193,10 +213,17 @@ 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(
|
main_topic = (
|
||||||
|
session.query(ShoutTopics.topic_slug)
|
||||||
|
.filter(
|
||||||
ShoutTopics.shout_id == shout.id,
|
ShoutTopics.shout_id == shout.id,
|
||||||
ShoutTopics.main == True
|
ShoutTopics.main == True
|
||||||
).first().pop()
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
|
||||||
|
if main_topic:
|
||||||
|
shout.main_topic = main_topic[0]
|
||||||
shouts.append(shout)
|
shouts.append(shout)
|
||||||
|
|
||||||
return shouts
|
return shouts
|
||||||
|
@ -249,7 +276,17 @@ 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(Topic.slug).join(ShoutTopic, and_(ShoutTopic.topic == Topic.id, ShoutTopic.shout == shout.id, ShoutTopic.main == True)).first().pop()
|
main_topic = (
|
||||||
|
session.query(ShoutTopics.topic_slug)
|
||||||
|
.filter(
|
||||||
|
ShoutTopics.shout_id == shout.id,
|
||||||
|
ShoutTopics.main == True
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
|
||||||
|
if main_topic:
|
||||||
|
shout.main_topic = main_topic[0]
|
||||||
shout.stat = {
|
shout.stat = {
|
||||||
"viewed": await ViewedStorage.get_shout(shout.slug),
|
"viewed": await ViewedStorage.get_shout(shout.slug),
|
||||||
"reacted": reacted_stat,
|
"reacted": reacted_stat,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user