예제 #1
0
        public async Task <LikePostResponse> LikePostAsync(LikePostRequest request, string userId)
        {
            var entity = new PostLikeEntity
            {
                PostId = request.PostId,
                UserId = userId
            };

            var result = await _postRepository.LikePostAsync(entity);

            if (!result)
            {
                return new LikePostResponse
                       {
                           StatusCode = (int)HttpStatusCode.Unauthorized
                       }
            }
            ;

            var response = new LikePostResponse
            {
                StatusCode = (int)HttpStatusCode.Created
            };

            return(response);
        }
예제 #2
0
        public void Like(int postId, int userId)
        {
            if (_postLikeRepository.Table.Any(x =>
                                              x.PostLikePostIdFk == postId && x.PostLikeUserIdFk == userId))
            {
                throw new PostAlreadyLikedException();
            }

            var like = new PostLikeEntity
            {
                PostLikePostIdFk  = postId,
                PostLikeUserIdFk  = userId,
                PostLikeCreatedAt = System.DateTime.Now
            };

            _postLikeRepository.Insert(like);
            _postLikeRepository.SaveAll();
        }
예제 #3
0
        public async Task <bool> LikePostAsync(PostLikeEntity entity)
        {
            await _dbContext.PostLikes.AddAsync(entity);

            return(await SaveAsync());
        }