schema fix
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from resolvers.auth import login, sign_out, get_user, is_email_free, register, confirm
|
||||
from resolvers.inbox import create_message, delete_message, update_message, get_messages
|
||||
from resolvers.zine import create_shout
|
||||
from resolvers.zine import create_shout, get_shout_by_slug
|
||||
from resolvers.profile import get_user_by_slug, get_current_user
|
||||
|
||||
__all__ = [
|
||||
"login",
|
||||
"register",
|
||||
"get_user",
|
||||
"is_email_free",
|
||||
"confirm",
|
||||
# TODO: "reset_password_code",
|
||||
@@ -14,5 +14,8 @@ __all__ = [
|
||||
"delete_message",
|
||||
"get_messages",
|
||||
"update_messages",
|
||||
"create_shout"
|
||||
"create_shout",
|
||||
"get_current_user",
|
||||
"get_user_by_slug",
|
||||
"get_shout_by_slug"
|
||||
]
|
||||
|
@@ -73,15 +73,6 @@ async def sign_out(_, info: GraphQLResolveInfo):
|
||||
status = await Authorize.revoke(token)
|
||||
return True
|
||||
|
||||
@query.field("getCurrentUser")
|
||||
@login_required
|
||||
async def get_user(_, info):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.id == user_id).first()
|
||||
return { "user": user }
|
||||
|
||||
@query.field("isEmailFree")
|
||||
async def is_email_free(_, info, email):
|
||||
with local_session() as session:
|
||||
|
21
resolvers/profile.py
Normal file
21
resolvers/profile.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from orm import User
|
||||
from orm.base import local_session
|
||||
from resolvers.base import mutation, query, subscription
|
||||
from auth.authenticate import login_required
|
||||
import asyncio
|
||||
|
||||
@query.field("getUserBySlug") # get a public profile
|
||||
async def get_user_by_slug(_, info, slug):
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.slug == slug).first()
|
||||
return { "user": user } # TODO: remove some fields for public
|
||||
|
||||
|
||||
@query.field("getCurrentUser")
|
||||
@login_required
|
||||
async def get_user(_, info):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.id == user_id).first()
|
||||
return { "user": user }
|
@@ -258,24 +258,20 @@ async def update_shout(_, info, id, input):
|
||||
"shout" : shout
|
||||
}
|
||||
|
||||
# TODO: get shout with comments query
|
||||
|
||||
@query.field("getShout") #FIXME: add shout joined with comments
|
||||
async def get_shout(_, info, shout_id):
|
||||
month_ago = datetime.now() - timedelta(days = 30)
|
||||
@query.field("getShoutBySlug") #FIXME: add shout joined with comments
|
||||
async def get_shout_by_slug(_, info, slug):
|
||||
# month_ago = datetime.now() - timedelta(days = 30)
|
||||
with local_session() as session:
|
||||
stmt = select(Comment, func.sum(CommentRating.value).label("rating")).\
|
||||
join(CommentRating).\
|
||||
where(CommentRating.ts > month_ago).\
|
||||
where(Comment.shout == shout_id).\
|
||||
# join(ShoutComment)
|
||||
group_by(Shout.id).\
|
||||
order_by(desc("rating")).\
|
||||
stmt = select(Shout, func.sum(ShoutRating.value).label("rating")).\
|
||||
join(ShoutRating).\
|
||||
# where(ShoutRating.ts > month_ago).\
|
||||
where(Shout.slug == slug).\
|
||||
# TODO: join(Comment) to .comments
|
||||
limit(limit)
|
||||
shouts = []
|
||||
for row in session.execute(stmt):
|
||||
shout = row.Shout
|
||||
shout.rating = row.rating
|
||||
shout.comments
|
||||
# TODO: shout.comments =
|
||||
shouts.append(shout)
|
||||
return shout
|
Reference in New Issue
Block a user