return user ratings; add getUsersBySlugs
This commit is contained in:
parent
d578072563
commit
e8780cfb86
|
@ -2,7 +2,7 @@ from resolvers.auth import login, sign_out, is_email_free, register, confirm
|
||||||
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
||||||
from resolvers.zine import create_shout, get_shout_by_slug, top_month, top_overall, \
|
from resolvers.zine import create_shout, get_shout_by_slug, top_month, top_overall, \
|
||||||
recent_shouts, top_authors, top_viewed
|
recent_shouts, top_authors, top_viewed
|
||||||
from resolvers.profile import get_user_by_slug, get_current_user, authors_by_slugs
|
from resolvers.profile import get_users_by_slugs, get_current_user
|
||||||
from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \
|
from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \
|
||||||
topics_by_community, topics_by_slugs, topics_all
|
topics_by_community, topics_by_slugs, topics_all
|
||||||
from resolvers.comments import create_comment
|
from resolvers.comments import create_comment
|
||||||
|
@ -21,7 +21,7 @@ __all__ = [
|
||||||
"update_messages",
|
"update_messages",
|
||||||
"create_shout",
|
"create_shout",
|
||||||
"get_current_user",
|
"get_current_user",
|
||||||
"get_user_by_slug",
|
"get_users_by_slugs",
|
||||||
"get_shout_by_slug",
|
"get_shout_by_slug",
|
||||||
"recent_shouts",
|
"recent_shouts",
|
||||||
"top_month",
|
"top_month",
|
||||||
|
@ -36,6 +36,5 @@ __all__ = [
|
||||||
"create_community",
|
"create_community",
|
||||||
"delete_community",
|
"delete_community",
|
||||||
"get_community",
|
"get_community",
|
||||||
"get_communities",
|
"get_communities"
|
||||||
"authors_by_slugs"
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,31 +7,19 @@ from sqlalchemy import func
|
||||||
from sqlalchemy.orm import selectinload
|
from sqlalchemy.orm import selectinload
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
@query.field("getUserBySlug") # get a public profile
|
|
||||||
async def get_user_by_slug(_, info, slug):
|
|
||||||
with local_session() as session:
|
|
||||||
row = session.query(User, func.sum(UserRating.value).label("rating")).\
|
|
||||||
where(User.slug == slug).\
|
|
||||||
join(UserRating, UserRating.user_id == User.id).\
|
|
||||||
group_by(User.id).\
|
|
||||||
first()
|
|
||||||
user = row.User
|
|
||||||
user["rating"] = row.rating
|
|
||||||
return { "user": user } # TODO: remove some fields for public
|
|
||||||
|
|
||||||
@query.field("getCurrentUser")
|
@query.field("getCurrentUser")
|
||||||
@login_required
|
@login_required
|
||||||
async def get_current_user(_, info):
|
async def get_current_user(_, info):
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
return { "user": user }
|
return { "user": user }
|
||||||
|
|
||||||
@query.field("authorsBySlugs")
|
@query.field("getUsersBySlugs")
|
||||||
@login_required
|
async def get_users_by_slugs(_, info, slugs):
|
||||||
async def authors_by_slugs(_, info, slugs):
|
|
||||||
user = info.context["request"].user
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
users = session.query(User).where(User.slug in slugs)
|
users = session.query(User).\
|
||||||
return { "authors": users }
|
options(selectinload(User.ratings)).\
|
||||||
|
filter(User.slug.in_(slugs)).all()
|
||||||
|
return users
|
||||||
|
|
||||||
@query.field("getUserRoles")
|
@query.field("getUserRoles")
|
||||||
async def get_user_roles(_, info, slug):
|
async def get_user_roles(_, info, slug):
|
||||||
|
|
|
@ -353,7 +353,6 @@ async def view_shout(_, info, shout_id):
|
||||||
@query.field("getShoutBySlug")
|
@query.field("getShoutBySlug")
|
||||||
async def get_shout_by_slug(_, info, slug):
|
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]
|
||||||
print(all_fields)
|
|
||||||
selected_fields = set(["authors", "comments", "topics"]).intersection(all_fields)
|
selected_fields = set(["authors", "comments", "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]
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ type Query {
|
||||||
|
|
||||||
# profile
|
# profile
|
||||||
getCurrentUser: UserResult!
|
getCurrentUser: UserResult!
|
||||||
getUserBySlug(slug: String!): UserResult!
|
getUsersBySlugs(slugs: [String]!): [User]!
|
||||||
# rateUser(shout: Int): Int!
|
# rateUser(shout: Int): Int!
|
||||||
getUserRoles(slug: String!): [Role]!
|
getUserRoles(slug: String!): [Role]!
|
||||||
|
|
||||||
|
@ -161,9 +161,6 @@ type Query {
|
||||||
# communities
|
# communities
|
||||||
getCommunity(slug: String): Community!
|
getCommunity(slug: String): Community!
|
||||||
getCommunities: [Community]!
|
getCommunities: [Community]!
|
||||||
|
|
||||||
# my feed
|
|
||||||
authorsBySlugs(slugs: [String]!): [User]!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
############################################ Subscription
|
############################################ Subscription
|
||||||
|
@ -203,7 +200,7 @@ type Role {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rating {
|
type Rating {
|
||||||
createdBy: Int!
|
rater_id: Int!
|
||||||
value: Int!
|
value: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +232,7 @@ type User {
|
||||||
muted: Boolean
|
muted: Boolean
|
||||||
updatedAt: DateTime
|
updatedAt: DateTime
|
||||||
wasOnlineAt: DateTime
|
wasOnlineAt: DateTime
|
||||||
rating: Int
|
ratings: [Rating]
|
||||||
bio: String
|
bio: String
|
||||||
notifications: [Int]
|
notifications: [Int]
|
||||||
topics: [String] # user subscribed topics
|
topics: [String] # user subscribed topics
|
||||||
|
|
Loading…
Reference in New Issue
Block a user