This commit is contained in:
knst-kotov
2021-09-05 11:56:15 +03:00
parent aaca27ba88
commit d5c654eace
6 changed files with 26 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
from resolvers.auth import login, sign_out, get_user, is_email_free, register, confirm
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.zine import create_shout, get_shout_by_slug
from resolvers.profile import get_user_by_slug, get_current_user

View File

@@ -6,16 +6,16 @@ import asyncio
@query.field("getUserBySlug") # get a public profile
async def get_user_by_slug(_, info, slug):
with local_session() as session:
with local_session() as session:
user = session.query(User).filter(User.slug == slug).first()
return { "user": user } # TODO: remove some fields for public
return { "user": user } # TODO: remove some fields for public
@query.field("getCurrentUser")
@login_required
async def get_user(_, info):
async def get_current_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 }
return { "user": user }

View File

@@ -260,13 +260,10 @@ async def update_shout(_, info, id, input):
@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(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):
@@ -274,4 +271,4 @@ async def get_shout_by_slug(_, info, slug):
shout.rating = row.rating
# TODO: shout.comments =
shouts.append(shout)
return shout
return shout