collections fix, single shout fix
This commit is contained in:
parent
04aaaab609
commit
3358ba8b99
|
@ -1,4 +1,4 @@
|
||||||
from orm.collection import Collection
|
from orm.collection import Collection, ShoutCollection
|
||||||
from base.orm import local_session
|
from base.orm import local_session
|
||||||
from orm.user import User
|
from orm.user import User
|
||||||
from base.resolvers import mutation, query
|
from base.resolvers import mutation, query
|
||||||
|
@ -68,6 +68,25 @@ async def get_user_collections(_, info, userslug):
|
||||||
query(Collection).\
|
query(Collection).\
|
||||||
where(and_(Collection.createdBy == userslug, Collection.publishedAt != None)).\
|
where(and_(Collection.createdBy == userslug, Collection.publishedAt != None)).\
|
||||||
all()
|
all()
|
||||||
|
for c in collections:
|
||||||
|
shouts = session.query(ShoutCollection).filter(ShoutCollection.collection == c.id).all()
|
||||||
|
c.amount = len(shouts)
|
||||||
|
return collections
|
||||||
|
|
||||||
|
@query.field("getMyCollections")
|
||||||
|
async def get_user_collections(_, info, userslug):
|
||||||
|
collections = []
|
||||||
|
with local_session() as session:
|
||||||
|
user = session.query(User).filter(User.slug == userslug).first()
|
||||||
|
if user:
|
||||||
|
# TODO: check rights here
|
||||||
|
collections = session.\
|
||||||
|
query(Collection).\
|
||||||
|
where(and_(Collection.createdBy == userslug, Collection.publishedAt != None)).\
|
||||||
|
all()
|
||||||
|
for c in collections:
|
||||||
|
shouts = session.query(ShoutCollection).filter(ShoutCollection.collection == c.id).all()
|
||||||
|
c.amount = len(shouts)
|
||||||
return collections
|
return collections
|
||||||
|
|
||||||
@query.field("getMyColelctions")
|
@query.field("getMyColelctions")
|
||||||
|
|
|
@ -55,23 +55,20 @@ async def get_shout_by_slug(_, info, slug):
|
||||||
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
|
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
|
||||||
selected_fields = set(["authors", "topics"]).intersection(all_fields)
|
selected_fields = set(["authors", "topics"]).intersection(all_fields)
|
||||||
select_options = [selectinload(getattr(Shout, field)) for field in selected_fields]
|
select_options = [selectinload(getattr(Shout, field)) for field in selected_fields]
|
||||||
|
shout = {}
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
try: s = text(open('src/queries/shout-by-slug.sql', 'r').read() % slug)
|
try: s = text(open('src/queries/shout-by-slug.sql', 'r').read() % slug)
|
||||||
except: pass
|
except: pass
|
||||||
shout_q = session.query(Shout).\
|
shout = session.query(Shout).\
|
||||||
options(select_options).\
|
options(select_options).\
|
||||||
filter(Shout.slug == slug)
|
filter(Shout.slug == slug).first()
|
||||||
|
|
||||||
print(shout_q.statement)
|
|
||||||
|
|
||||||
shout = shout_q.first()
|
|
||||||
for a in shout.authors:
|
|
||||||
a.caption = await ShoutAuthorStorage.get_author_caption(slug, a.slug)
|
|
||||||
|
|
||||||
if not shout:
|
if not shout:
|
||||||
print(f"shout with slug {slug} not exist")
|
print(f"shout with slug {slug} not exist")
|
||||||
return {"error" : "shout not found"}
|
return {"error" : "shout not found"}
|
||||||
|
else:
|
||||||
|
for a in shout.authors:
|
||||||
|
a.caption = await ShoutAuthorStorage.get_author_caption(slug, a.slug)
|
||||||
return shout
|
return shout
|
||||||
|
|
||||||
@query.field("shoutsByTopics")
|
@query.field("shoutsByTopics")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user