Exemplo n.º 1
0
        public async Task <IActionResult> GetPhotoDetails(Guid photoId)
        {
            logger.LogInformation($"{nameof(GetPhotoDetails)}({nameof(photoId)} = '{photoId}')");
            PhotoModel photo = await photosService.GetPhoto(photoId, GetCurrentUserId());

            return(Json(photoModelConverter.ToPublic(photo)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetPhoto(int id)
        {
            var photoFromRepo = await _photosService.GetPhoto(id);

            var photo = _photosService.MapPhotoForReturn(photoFromRepo);

            return(Ok(photo));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetPhoto(int id)
        {
            var photoFromRepo = await _photoService.GetPhoto(id);

            if (photoFromRepo == null)
            {
                return(NotFound("Photo Not Found!"));
            }
            return(Ok(photoFromRepo));
        }
Exemplo n.º 4
0
 private void CachePhotos(IList <PhotoDto> photos)
 {
     foreach (var id in photos.Take(10).Select(x => x.Id))
     {
         _photosService.GetPhoto(Priority.Speculative, id);
     }
 }
Exemplo n.º 5
0
        private static async Task UpdatePhotoData(IPhotosService photoService, PhotoId photoId, IEnumerable <Size> imageSizes)
        {
            var photoFromDb = await photoService.GetPhoto(photoId, Guid.Empty);

            photoFromDb.State = PhotoState.PhotoAvailable;
            photoFromDb.Sizes = imageSizes;
            await photoService.UpdatePhoto(photoFromDb);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> GetPhoto(int photoId)
        {
            var photo = await _service.GetPhoto(photoId);

            if (photo is null)
            {
                return(NotFound($"Could not find the photo '{photoId}'."));
            }

            return(Ok(_mapper.To <PhotoToReturnDto>(photo)));
        }
        public async Task <IActionResult> PhotoDetails(Guid photoId)
        {
            logger.LogInformation($"{nameof(PhotoDetails)}({nameof(photoId)} = '{photoId}')");
            var        userId = GetCurrentUserId();
            PhotoModel photo  = await photosService.GetPhoto(photoId, userId);

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

            bool photoIsOwnedByCurrentUser = userId == photo.UserId;

            logger.LogInformation($"{nameof(userId)} = '{userId}', {nameof(photo.UserId)} = '{photo.UserId}'. Photo {(photoIsOwnedByCurrentUser ? "is" : "is NOT")} owned by current user.");

            // If the state is not PhotoAvailable, show it only if it's owned by the current user
            if (photo.State != PhotoState.PhotoAvailable && !photoIsOwnedByCurrentUser)
            {
                return(NotFound());
            }

            return(base.View(photoModelConverter.ToPublic(photo, userId.Equals(Guid.Empty) ? null : (Guid?)userId)));
        }
Exemplo n.º 8
0
 public async Task <IActionResult> GetPhoto(int id)
 {
     return(Ok(await _photosService.GetPhoto(id)));
 }