load-shouts-discussed-coauthored
All checks were successful
Deploy on push / deploy (push) Successful in 2m4s
All checks were successful
Deploy on push / deploy (push) Successful in 2m4s
This commit is contained in:
parent
1223c633d4
commit
77282ade62
|
@ -35,6 +35,8 @@ from resolvers.reader import (
|
|||
load_shouts_random_topic,
|
||||
load_shouts_search,
|
||||
load_shouts_unrated,
|
||||
load_shouts_coauthored,
|
||||
load_shouts_discussed,
|
||||
)
|
||||
from resolvers.topic import (
|
||||
get_topic,
|
||||
|
@ -79,6 +81,8 @@ __all__ = [
|
|||
"load_shouts_followed",
|
||||
"load_shouts_followed_by",
|
||||
"load_shouts_unrated",
|
||||
"load_shouts_coauthored",
|
||||
"load_shouts_discussed",
|
||||
"load_shouts_random_top",
|
||||
"load_shouts_random_topic",
|
||||
# follower
|
||||
|
|
|
@ -342,6 +342,7 @@ def apply_reaction_filters(by, q):
|
|||
|
||||
if by.get("comment", False):
|
||||
q = q.filter(Reaction.kind == ReactionKind.COMMENT.value)
|
||||
|
||||
if by.get("rating", False):
|
||||
q = q.filter(Reaction.kind.in_(RATING_REACTIONS))
|
||||
|
||||
|
@ -367,6 +368,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
|
|||
:topic - to filter by topic
|
||||
:search - to search by reactions' body
|
||||
:comment - true if body.length > 0
|
||||
:rating - true if kind is rating related
|
||||
:after - amount of time ago
|
||||
:sort - a fieldname to sort desc by default
|
||||
}
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
from sqlalchemy.orm import aliased, joinedload
|
||||
from sqlalchemy.sql.expression import and_, asc, bindparam, case, desc, distinct, func, nulls_last, or_, select, text
|
||||
from sqlalchemy.sql.expression import (
|
||||
and_,
|
||||
asc,
|
||||
bindparam,
|
||||
case,
|
||||
desc,
|
||||
distinct,
|
||||
func,
|
||||
nulls_last,
|
||||
or_,
|
||||
select,
|
||||
text,
|
||||
)
|
||||
|
||||
from orm.author import Author, AuthorFollower
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
|
@ -154,7 +166,7 @@ async def load_shouts_by(_, _info, options):
|
|||
}
|
||||
offset: 0
|
||||
limit: 50
|
||||
order_by: 'created_at' | 'commented' | 'likes_stat'
|
||||
order_by: "likes" | "followers" | "comments" | "last_comment"
|
||||
order_by_desc: true
|
||||
|
||||
}
|
||||
|
@ -331,7 +343,10 @@ async def load_shouts_unrated(_, info, limit: int = 50, offset: int = 0):
|
|||
Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value]),
|
||||
),
|
||||
)
|
||||
.outerjoin(Author, and_(Author.user == bindparam("user_id"), Reaction.created_by == Author.id))
|
||||
.outerjoin(
|
||||
Author,
|
||||
and_(Author.user == bindparam("user_id"), Reaction.created_by == Author.id),
|
||||
)
|
||||
.where(
|
||||
and_(
|
||||
Shout.deleted_at.is_(None),
|
||||
|
@ -471,3 +486,33 @@ def fetch_shouts_by_topic(topic, limit):
|
|||
shouts = get_shouts_from_query(q)
|
||||
|
||||
return shouts
|
||||
|
||||
|
||||
@query.field("load_shouts_coauthored")
|
||||
@login_required
|
||||
async def load_shouts_coauthored(_, info, limit=50, offset=0):
|
||||
author_id = info.context.get("author", {}).get("id")
|
||||
shouts_query = query_shouts().filter(Shout.authors.any(id=author_id)).where(Shout.deleted_at.is_(None))
|
||||
shouts = get_shouts_from_query(shouts_query.limit(limit).offset(offset))
|
||||
return shouts
|
||||
|
||||
|
||||
@query.field("load_shouts_discussed")
|
||||
@login_required
|
||||
async def load_shouts_discussed(_, info, limit=50, offset=0):
|
||||
author_id = info.context.get("author", {}).get("id")
|
||||
q = query_shouts()
|
||||
q = (
|
||||
q.outerjoin(
|
||||
Reaction,
|
||||
and_(
|
||||
Reaction.shout == Shout.id,
|
||||
Reaction.created_by == author_id,
|
||||
Reaction.kind.is_(ReactionKind.COMMENT.value),
|
||||
),
|
||||
)
|
||||
.outerjoin(Author, Reaction.created_by == Author.id)
|
||||
.where(and_(Shout.deleted_at.is_(None), Shout.published_at.is_not(None)))
|
||||
)
|
||||
q = q.limit(limit).offset(offset)
|
||||
return await get_shouts_from_query(q)
|
||||
|
|
|
@ -76,7 +76,6 @@ def add_author_stat_columns(q):
|
|||
return q
|
||||
|
||||
|
||||
|
||||
def get_topic_shouts_stat(topic_id: int):
|
||||
q = (
|
||||
select(func.count(distinct(ShoutTopic.shout)))
|
||||
|
|
|
@ -30,6 +30,8 @@ type Query {
|
|||
load_shouts_search(text: String!, limit: Int, offset: Int): [SearchResult]
|
||||
load_shouts_feed(options: LoadShoutsOptions): [Shout]
|
||||
load_shouts_unrated(limit: Int, offset: Int): [Shout]
|
||||
load_shouts_coauthored(limit: Int, offset: Int): [Shout]
|
||||
load_shouts_discussed(limit: Int, offset: Int): [Shout]
|
||||
load_shouts_random_top(options: LoadShoutsOptions): [Shout]
|
||||
load_shouts_random_topic(limit: Int!): CommonResult! # { topic shouts }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user