@@ -300,7 +300,9 @@ async def review_comment(
300300
301301
302302@comment .patch ("/{uuid}" , response_model = CommentGet )
303- async def update_comment (uuid : UUID , comment_update : CommentUpdate , user = Depends (UnionAuth ())) -> CommentGet :
303+ async def update_comment (uuid : UUID , comment_update : CommentUpdate ,
304+ user = Depends (UnionAuth ())
305+ ) -> CommentGet :
304306 """Позволяет изменить свой неанонимный комментарий"""
305307 comment : Comment = Comment .get (session = db .session , id = uuid ) # Ошибка, если не найден
306308
@@ -319,7 +321,10 @@ async def update_comment(uuid: UUID, comment_update: CommentUpdate, user=Depends
319321 review_status = ReviewStatus .PENDING ,
320322 )
321323
322- return CommentGet .model_validate (updated_comment )
324+ updated_comment = CommentGet .model_validate (updated_comment )
325+ updated_comment .is_liked = comment .has_reaction (user .get ("id" ), Reaction .LIKE )
326+ updated_comment .is_disliked = comment .has_reaction (user .get ("id" ), Reaction .DISLIKE )
327+ return updated_comment
323328
324329
325330@comment .delete ("/{uuid}" , response_model = StatusResponseModel )
@@ -384,11 +389,16 @@ async def like_comment(
384389 )
385390 .first ()
386391 )
392+ comment = CommentGet .model_validate (comment )
393+ comment .is_liked = (reaction == Reaction .LIKE )
394+ comment .is_disliked = (reaction == Reaction .DISLIKE )
387395
388396 if existing_reaction and existing_reaction .reaction != reaction :
389397 new_reaction = CommentReaction .update (session = db .session , id = existing_reaction .uuid , reaction = reaction )
390398 elif not existing_reaction :
391399 CommentReaction .create (session = db .session , user_id = user .get ("id" ), comment_uuid = comment .uuid , reaction = reaction )
392400 else :
401+ comment .is_disliked = False
402+ comment .is_liked = False
393403 CommentReaction .delete (session = db .session , id = existing_reaction .uuid )
394- return CommentGet . model_validate ( comment )
404+ return comment
0 commit comments