public async Task <ActionResult <IEnumerable <LikeDto> > > GetUserLikes([FromQuery] LikesParams likesParams) { likesParams.UserId = User.GetuserId(); var users = await _likesRepository.GetUserLikes(likesParams); Response.AddPaginationHeader(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages); return(Ok(users)); }
public async Task <ActionResult> AddLike(string username) { var sourceUserId = User.GetuserId(); var likedUser = await _userRepository.GetUserByUsernameAsync(username); var sourceUser = await _likesRepository.GetUserWithLikes(sourceUserId); if (likedUser == null) { return(NotFound()); } if (sourceUser.UserName == username) { return(BadRequest("You cannot like yourself")); } var userLike = await _likesRepository.GetUserLike(sourceUserId, likedUser.Id); if (userLike != null) { return(BadRequest("You already like this user")); } userLike = new UserLike { SourceUserId = sourceUserId, LikedUserId = likedUser.Id }; sourceUser.LikedUsers.Add(userLike); if (await _userRepository.SaveAllAsync()) { return(Ok()); } return(BadRequest("Failed to like user")); }