reactions-fixes

This commit is contained in:
tonyrewin 2022-08-05 18:55:07 +03:00
parent 1d66ae562d
commit 360373e84a
2 changed files with 18 additions and 42 deletions

View File

@ -105,54 +105,23 @@ async def delete_reaction(_, info, id):
return {} return {}
@query.field("reactionsByShout") @query.field("reactionsByShout")
def get_shout_reactions(_, info, slug) -> List[Shout]: def get_shout_reactions(_, info, slug)-> List[Reaction]:
shouts = [] #offset = page * size
with local_session() as session: #end = offset + size
shoutslugs = session.query(ShoutReactionsFollower.shout).\ return ReactionsStorage.reactions_by_shout.get(slug, []) #[offset:end]
join(User).where(Reaction.createdBy == User.slug).\
filter(ShoutReactionsFollower.follower == slug,
ShoutReactionsFollower.deletedAt == None).all()
shoutslugs = list(set(shoutslugs))
shouts = session.query(Shout).filter(Shout.slug in shoutslugs).all()
return shouts
@query.field("reactionsAll") @query.field("reactionsAll")
def get_all_reactions(_, info, page=1, size=10) -> List[Reaction]: def get_all_reactions(_, info, page=1, size=10) -> List[Reaction]:
reactions = [] offset = page * size
with local_session() as session: end = offset + size
return ReactionsStorage.reactions[offset:end]
# reactions = session.execute(select(Reaction, func.max(Reaction.createdAt).label("reactionCreatedAt")).\
# join(Shout, Reaction.shout == Shout.slug).\
# group_by(Reaction.id).\
# order_by(desc("reactionCreatedAt")).\
# join( User, Reaction.createdBy == User.slug ).\
# join( Shout, Reaction.shout == Shout.slug ).\
# filter( Reaction.deletedAt == None ).\
# limit(size).offset(page * size).all())
reactions = session.query(Reaction).\
options(
joinedload(User),
joinedload(Shout)
).\
join( User, Reaction.createdBy == User.slug ).\
join( Shout, Reaction.shout == Shout.slug ).\
filter( Reaction.deletedAt == None ).\
limit(size).offset(page * size).all()
# print(reactions[0].dict())
return reactions
@query.field("reactionsByAuthor") @query.field("reactionsByAuthor")
def get_reactions_by_author(_, info, slug, page=1, size=50) -> List[Reaction]: def get_reactions_by_author(_, info, slug, page=1, size=50) -> List[Reaction]:
reactions = [] offset = page * size
with local_session() as session: end = offset + size
reactions = session.query(Reaction).\ return ReactionsStorage.reactions_by_author.get(slug, [])[offset:end]
join(Shout).where(Reaction.shout == Shout.slug).\
filter(Reaction.deletedAt == None, Reaction.createdBy == slug).\
limit(size).offset(page * size).all() # pagination
return reactions
@mutation.field("viewReaction") @mutation.field("viewReaction")

View File

@ -320,13 +320,20 @@ type Reaction {
old_thread: String old_thread: String
} }
type Author {
slug: String!
name: String!
userpic: String
caption: String
}
# is publication # is publication
type Shout { type Shout {
id: Int! id: Int!
slug: String! slug: String!
body: String! body: String!
createdAt: DateTime! createdAt: DateTime!
authors: [User!]! authors: [Author!]!
# ratings: [Rating] # ratings: [Rating]
community: String community: String
cover: String cover: String