コード例 #1
0
        public async Task <IActionResult> Post([FromBody] AttractionLike model)
        {
            if (!await MatchAppUserWithToken((int)model.AppUserId))
            {
                return(Unauthorized());
            }

            if (!await _repo.RecordExist("AppUser", (int)model.AppUserId))
            {
                return(NotFound());
            }

            var attractionFromRepo = await _repo.GetAttraction((int)model.AttractionId);

            if (attractionFromRepo == null)
            {
                return(NotFound());
            }

            var likeRecord = await _repo.GetAttractionLike((int)model.AppUserId, (int)model.AttractionId);

            if (await _repo.AttractionLiked((int)model.AppUserId, (int)model.AttractionId))
            {
                return(BadRequest("既にリアクションされています"));
            }

            _repo.Add(model);
            await _appUserRepo.AddLikeCountToUser((int)attractionFromRepo.AppUserId);

            if (await _repo.SaveAll() > 0)
            {
                return(Created("GetAttractionLike", null));
            }
            return(BadRequest("Failed to post attraction like"));
        }
コード例 #2
0
        public async Task <ActionResult> Get(int id)
        {
            var attractionFromRepo = await _attractionRepo.GetAttraction(id);

            var attraction = _mapper.Map <AttractionForReturnDto>(attractionFromRepo);

            attraction.ReviewPhotos = _mapper.Map <List <PhotoForReturnDto> >(await _attractionRepo.GetAllReviewPhotosForAttraction(id));
            var loggedInUser = await GetLoggedInUserAsync();

            if (loggedInUser != null)
            {
                attraction.isLiked = await _attractionRepo.AttractionLiked(loggedInUser.Id, attraction.Id);

                var currentUserReview = await _attractionRepo.GetAttractionReviewByUser(loggedInUser.Id, attraction.Id);

                if (currentUserReview != null)
                {
                    attraction.currentUsersReviewId = currentUserReview.Id;
                }
            }
            return(Ok(attraction));
        }