diff --git a/resolvers/profile.py b/resolvers/profile.py index 945cb701..6abca175 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -81,6 +81,29 @@ async def user_subscribers(_, info, slug): where(AuthorSubscription.author == slug) return users +@mutation.field("rateUser") +@login_required +async def rate_user(_, info, slug, value): + user = info.context["request"].user + + with local_session() as session: + rating = session.query(UserRating).\ + filter(and_(UserRating.rater == user.slug, UserRating.user == slug)).\ + first() + + if rating: + rating.value = value + session.commit() + return {} + + UserRating.create( + rater = user.slug, + user = slug, + value = value + ) + + return {} + @mutation.field("authorSubscribe") @login_required async def author_subscribe(_, info, slug): diff --git a/schema.graphql b/schema.graphql index c436b5af..b11d01fa 100644 --- a/schema.graphql +++ b/schema.graphql @@ -132,7 +132,7 @@ type Mutation { viewShout(slug: String!): Result! # user profile - # rateUser(value: Int!): Result! + rateUser(slug: String!, value: Int!): Result! # updateOnlineStatus: Result! updateProfile(profile: ProfileInput!): Result! @@ -166,7 +166,6 @@ type Query { # profile getCurrentUser: UserResult! getUsersBySlugs(slugs: [String]!): [User]! - # rateUser(shout: Int): Int! getUserRoles(slug: String!): [Role]! userComments(slug: String!, page: Int!, size: Int!): [Comment]! userSubscriptions(slug: String!): [User]!