public void MapPhotoLikeRequestToPhotoLikeEntity(PhotoLikeRequest source, out PhotoLike destination) { destination = new PhotoLike() { LikerId = source.UserId, PhotoId = source.PhotoId }; }
private async Task <PhotoLikeEntity> GetLikeFromDatabaseAsync(PhotoLikeRequest request) { var likeFromRepo = await _photoLikeRepo.GetSinglePhotoLikeAsync(request.PhotoId, request.UserId); if (likeFromRepo is not null) { return(likeFromRepo); } throw new NotFoundException("You haven't liked this photo."); }
private async Task <IAsyncResult> CheckIfPhotoExistAsync(PhotoLikeRequest request) { var photoFromRepo = await _photoRepo.GetSinglePhotoAsync(request.PhotoId); if (photoFromRepo is not null) { return(Task.CompletedTask); } throw new NotFoundException("Photo you wanted to unlike doesn't exist."); }
private async Task <bool> DoesPhotoExistsAsync(PhotoLikeRequest request) { var photoFromRepo = await _photoRepo.GetSinglePhotoAsync(request.PhotoId); if (photoFromRepo is not null) { return(true); } return(false); }
private async Task <bool> IsAlreadyLikedAsync(PhotoLikeRequest request) { var likeFromRepo = await _photoLikeRepo.GetSinglePhotoLikeAsync(request.PhotoId, request.UserId); if (likeFromRepo is not null) { return(true); } return(false); }
public async Task <IActionResult> GetSingleLike([FromQuery] PhotoLikeRequest photoLike, CancellationToken cancellationToken) { var query = new GetSinglePhotoLikeQuery { Like = photoLike }; var doesExist = await _mediator.Send(query); return(Ok(doesExist)); }
private async Task <Unit> AddToDatabaseAsync(PhotoLikeRequest request, CancellationToken cancellationToken) { PhotoLikeEntity photoLike; _mapper.MapPhotoLikeRequestToPhotoLikeEntity(request, out photoLike); await _photoLikeRepo.AddAsync(photoLike, cancellationToken); if (await _photoLikeRepo.SaveAllAsync()) { return(await Task.FromResult(Unit.Value)); } throw new DatabaseException("Error occured while updating database"); }
private async Task <IAsyncResult> ValidateAsync(PhotoLikeRequest request) { var isAlreadyLiked = await IsAlreadyLikedAsync(request); var doesPhotoExistTask = DoesPhotoExistsAsync(request); if (isAlreadyLiked) { throw new DatabaseException("You've already liked this photo."); } if (await doesPhotoExistTask) { return(Task.CompletedTask); } throw new NotFoundException("Photo you wanted to like, doesn't exist."); }
private async Task <PhotoLikeEntity> GetFromDatabase(PhotoLikeRequest like) { var likeFromRepo = await _photoLikeRepo.GetSinglePhotoLikeAsync(like.PhotoId, like.UserId); return(likeFromRepo); }