This commit is contained in:
parent
724e9bd5a0
commit
3acedcc7d6
|
@ -141,6 +141,21 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
|
||||||
shout_input["updated_at"] = current_time # Set updated_at as Unix timestamp
|
shout_input["updated_at"] = current_time # Set updated_at as Unix timestamp
|
||||||
Shout.update(shout, shout_input)
|
Shout.update(shout, shout_input)
|
||||||
session.add(shout)
|
session.add(shout)
|
||||||
|
|
||||||
|
# main topic
|
||||||
|
# TODO: test main_topic update
|
||||||
|
if "main_topic" in shout_input:
|
||||||
|
old_main_topic = session.query(ShoutTopic).filter(and_(ShoutTopic.shout == shout.id, ShoutTopic.main == True)).first()
|
||||||
|
main_topic = session.query(Topic).filter(Topic.slug == shout_input["main_topic"]).first()
|
||||||
|
new_main_topic = session.query(ShoutTopic).filter(and_(ShoutTopic.shout == shout.id, ShoutTopic.topic == main_topic.id)).first()
|
||||||
|
if old_main_topic is not new_main_topic:
|
||||||
|
old_main_topic.main = False
|
||||||
|
new_main_topic.main = True
|
||||||
|
session.add(old_main_topic)
|
||||||
|
session.add(new_main_topic)
|
||||||
|
|
||||||
|
session.commit()
|
||||||
|
|
||||||
if publish:
|
if publish:
|
||||||
if shout.visibility is ShoutVisibility.AUTHORS.value:
|
if shout.visibility is ShoutVisibility.AUTHORS.value:
|
||||||
shout_dict = shout.dict()
|
shout_dict = shout.dict()
|
||||||
|
|
|
@ -100,11 +100,7 @@ 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()
|
||||||
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")
|
||||||
|
@ -163,11 +159,7 @@ 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(Topic.slug).join(ShoutTopic, and_(ShoutTopic.topic == Topic.id, ShoutTopic.shout == shout.id, ShoutTopic.main == True)).first()
|
||||||
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,
|
||||||
|
@ -257,10 +249,7 @@ 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(
|
shout.main_topic = session.query(Topic.slug).join(ShoutTopic, and_(ShoutTopic.topic == Topic.id, ShoutTopic.shout == shout.id, ShoutTopic.main == True)).first()
|
||||||
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,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user