Example #1
0
        public async Task <ActionResult <LikeResponse> > GetQuestionaryLikes(int id)
        {
            var count = await _likeRepository.GetLikes(id);

            var likeResponse = new LikeResponse {
                LikeCnt = count
            };

            return(likeResponse);
        }
Example #2
0
        public async void LikeUser()
        {
            RaiseAnimation("Like");
            LikeResponse response = await Client.GetAsync <LikeResponse>("like/" + _currentRec.Id).ConfigureAwait(false);

            if (response.Match)
            {
                RaiseOnMatch();
            }
            else
            {
                NextRecommendation();
            }
        }
        public async Task <ActionResult <LikeResponse> > LikeImagePost(int imagePostId)
        {
            _logger.LogInformation("Received image post like request.");
            _logger.LogInformation("Image post id: {0}", imagePostId);

            User currentUser = _currentUserService.GetCurrentUser(HttpContext);

            _logger.LogInformation("Requesting user email: {0}", currentUser.Email);

            try
            {
                Like createdLike = await _likeService.LikeImagePost(imagePostId, currentUser.Email);

                createdLike.User = currentUser;

                LikeResponse likeResponse = _mapper.Map <LikeResponse>(createdLike);

                // Publish event.
                _logger.LogInformation("Publishing like notification.");
                await _notificationService.Publish(new LikeNotification(likeResponse));

                _logger.LogInformation("Successfully created like by '{0}' on image post with id {1}.", createdLike.UserEmail, createdLike.ImagePostId);

                return(Ok(likeResponse));
            }
            catch (DuplicateLikeException)
            {
                _logger.LogError("User '{0}' cannot like an image post with id {1} more than once.", currentUser.Email, imagePostId);
                return(BadRequest());
            }
            catch (OwnImagePostLikeException)
            {
                _logger.LogError("User '{0}' cannot like their own image post with id {1}.", currentUser.Email, imagePostId);
                return(BadRequest());
            }
            catch (EntityNotFoundException <int> )
            {
                _logger.LogError("Image post with id {0} does not exist.", imagePostId);
                return(BadRequest());
            }
            catch (EntityNotFoundException <string> )
            {
                _logger.LogError("User with email '{0}' does not exist.", currentUser.Email);
                return(BadRequest());
            }
        }
Example #4
0
        public async Task <LikeResponse> like(string id_to_like)
        {
            // Given the ID of the user to like,
            var url = API.AppendPathSegments(new string[] { "like", id_to_like });

            // GET /like/{id} HTTP/1.1
            HttpResponseMessage response = await rest.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                LikeResponse json = await RestHelpers.responseToObject <LikeResponse>(response);

                return(json);
            }

            return(null);
        }
Example #5
0
        public async Task <LikeResponse> superlike(string id_to_like)
        {
            // Given the ID of the user to like,
            var url = API.AppendPathSegments(new string[] { "like", id_to_like, "super" });

            dynamic payload = new JObject();

            // POST /like/{id}/super HTTP/1.1
            // Why the superlike is a POST and like is GET, we'll never know!
            HttpResponseMessage response = await rest.PostAsync(url, RestHelpers.preparePayload(payload));

            if (response.IsSuccessStatusCode)
            {
                LikeResponse json = await RestHelpers.responseToObject <LikeResponse>(response);

                return(json);
            }

            return(null);
        }
Example #6
0
    public async Task <ObjectResult <LikeResponse> > Like(int quizId, int userId)
    {
        var quiz = await _quizRepository.GetQuiz(quizId);

        if (quiz == null)
        {
            return(new ObjectResult <LikeResponse> {
                Errors = new[] { "Quiz with given id was not found" }
            });
        }

        Like like;

        if ((like = await _likeRepository.GetLike(quizId, userId)) != null)
        {
            return(new ObjectResult <LikeResponse> {
                Found = true, Success = true, Object = _mapper.Map <LikeResponse>(like)
            });
        }

        var likeModel = new LikeResponse
        {
            QuizId = quizId,
            UserId = userId
        };

        like = _mapper.Map <Like>(likeModel);

        _likeRepository.Add(like);

        if (await _likeRepository.SaveChangesAsync())
        {
            return(new ObjectResult <LikeResponse> {
                Found = true, Success = true, Object = likeModel
            });
        }

        return(new ObjectResult <LikeResponse> {
            Found = true, Errors = new[] { "No rows were affected" }
        });
    }
 public static LikeResponse Translate(Like entity) =>
 LikeResponse.Create(
     articleId: entity.ArticleId,
     count: entity.Count
     );
 public LikeNotification(LikeResponse likeResponse)
 {
     LikeResponse = likeResponse;
 }