user slug as rater in shout ratings

This commit is contained in:
knst-kotov 2022-01-11 16:33:25 +03:00
parent 7452c66598
commit 5341bb80a5
3 changed files with 18 additions and 4 deletions

View File

@ -49,7 +49,9 @@ class ShoutRatingStorage:
@staticmethod @staticmethod
def init(session): def init(session):
ShoutRatingStorage.ratings = session.query(ShoutRating).all() #TODO use user slug as rater
ShoutRatingStorage.ratings = session.query(ShoutRating.shout, ShoutRating.value, User.slug.label("rater")).\
join(User).all()
@staticmethod @staticmethod
async def get_total_rating(shout_slug): async def get_total_rating(shout_slug):

View File

@ -297,7 +297,8 @@ async def update_shout(_, info, input):
@login_required @login_required
async def rate_shout(_, info, slug, value): async def rate_shout(_, info, slug, value):
auth = info.context["request"].auth auth = info.context["request"].auth
user_id = auth.user_id user = info.context["request"].user
user_id = user.id
with local_session() as session: with local_session() as session:
rating = session.query(ShoutRating).\ rating = session.query(ShoutRating).\
@ -313,7 +314,13 @@ async def rate_shout(_, info, slug, value):
value = value value = value
) )
await ShoutRatingStorage.update_rating(rating) rating_dict = {
"shout" : shout,
"value" : value,
"rater" : user.slug
}
await ShoutRatingStorage.update_rating(rating_dict)
return {"error" : ""} return {"error" : ""}

View File

@ -218,6 +218,11 @@ type Rating {
value: Int! value: Int!
} }
type ShoutRating {
rater: String!
value: Int!
}
type Notification { type Notification {
kind: String! # unique primary key kind: String! # unique primary key
template: String! template: String!
@ -302,7 +307,7 @@ type Shout {
body: String! body: String!
createdAt: DateTime! createdAt: DateTime!
authors: [User!]! authors: [User!]!
ratings: [Rating] ratings: [ShoutRating]
visibleFor: [User] visibleFor: [User]
community: Int community: Int
cover: String cover: String