public async Task AddPhotoComment(PhotoComment comment) { logWriter.LogInformation($"{nameof(AddPhotoComment)}({nameof(comment.PhotoId)} = '{comment.PhotoId}', {nameof(comment.UserId)} = '{comment.UserId}', {nameof(comment.Text)} = '{comment.Text}')"); var photo = await photoRepository.GetPhotoById(comment.PhotoId, Guid.Empty); var scoreDelta = scoreCalculator.GetCommentScore(comment); var putItemRequest = new PutItemRequest() { TableName = tableName, Item = Mappers.PhotoComment.ToDbItem(comment) }; try { await dynamoDbCore.PutItem(putItemRequest); await UpdateCommentCountAndScore(photo, 1, scoreDelta); } catch (Exception ex) { logWriter.LogError(ex, $"{nameof(AddPhotoComment)}({nameof(comment.PhotoId)} = '{comment.PhotoId}', {nameof(comment.UserId)} = '{comment.UserId}', {nameof(comment.Text)} = '{comment.Text}'):\n{ex.ToString()}"); throw; } }
public async Task <PhotoModel> CreatePhoto(PhotoModel photo) { photo.Score = scoreCalculator.GetPhotoScore(photo); logWriter.LogInformation($"{nameof(CreatePhoto)}({nameof(photo.Filename)} = '{photo.Filename}')"); try { var item = Mappers.PhotoModel.ToDbItem(photo); var request = new PutItemRequest(tableName, item); BatchWriteItemRequest hashtagsRequests = GetHashtagsRequests(photo.RawText, photo.Hashtags, photo, HashtagUpdateMode.CreateOnly); await dynamoDbCore.PutItem(request); if (hashtagsRequests != null) { await dynamoDbCore.BatchWriteItem(hashtagsRequests); } logWriter.LogInformation($"Photo record created for '{photo.Filename}'"); return(photo); } catch (Exception ex) { logWriter.LogError(ex, $"Error in {nameof(CreatePhoto)}(photo.Id = '{photo.PhotoId}'):\n{ex.ToString()}"); throw new Exception("Error when creating photo.", ex); } }
private async Task AddLikeRecord(UserId userId, PhotoId photoId) { logWriter.LogInformation($"{nameof(AddLikeRecord)}({nameof(userId)} = '{userId}', {nameof(photoId)} = '{photoId}')"); var photo = await photoRepository.GetPhotoById(photoId, Guid.Empty); var newLikeCount = photo.LikeCount + 1; var putItemRequest = new PutItemRequest() { TableName = tableName, Item = Mappers.PhotoLike.ToDbItem(new PhotoLikeRecord { UserId = userId, PhotoId = photoId, CreatedTime = DateTimeOffset.UtcNow }), }; try { await dynamoDbCore.PutItem(putItemRequest); await UpdateLikeCount(photo, newLikeCount); } catch (Exception ex) { logWriter.LogError(ex, $"Error in {nameof(AddLikeRecord)}({nameof(userId)} = '{userId}', {nameof(photoId)} = '{photoId}'):\n{ex.ToString()}"); throw; } }
public Task SetSettings(string settingsDomain, SettingsModel settings) { PutItemRequest request = new PutItemRequest { TableName = tableName, Item = Mappers.Settings.ToDbItem(settings) }; return(dynamoDbCore.PutItem(request)); }
public async Task <UserModel> CreateUser(UserModel user) { logWriter.LogInformation($"{nameof(CreateUser)}({nameof(user.Id)} = '{user.Id}', {nameof(user.Name)} = '{user.Name}', {nameof(user.Email)} = '{user.Email}')"); try { var item = Mappers.UserModel.ToDbItem(user); var request = new PutItemRequest(tableName, item); await dynamoDbCore.PutItem(request); logWriter.LogInformation($"User record created for '{user.Email}'"); return(user); } catch (Exception ex) { logWriter.LogError(ex, $"Error in {nameof(CreateUser)}({nameof(user.Email)} = '{user.Email}'):\n{ex.ToString()}"); throw new Exception("Error when creating user.", ex); } }
private async Task AddLikeRecord(UserId userId, PhotoId photoId) { logWriter.LogInformation($"{nameof(AddLikeRecord)}({nameof(userId)} = '{userId}', {nameof(photoId)} = '{photoId}')"); var photo = await photoRepository.GetPhotoById(photoId, Guid.Empty); if (photo.PhotoIsLikedByCurrentUser) { return; } PhotoLikeRecord likeRecord = new PhotoLikeRecord { UserId = userId, PhotoId = photoId, CreatedTime = DateTimeOffset.UtcNow }; var scoreDelta = scoreCalculator.GetLikeScore(likeRecord); var putItemRequest = new PutItemRequest() { TableName = tableName, Item = Mappers.PhotoLike.ToDbItem(likeRecord), }; try { await dynamoDbCore.PutItem(putItemRequest); await UpdateLikeCountAndScore(photo, 1, scoreDelta); } catch (Exception ex) { logWriter.LogError(ex, $"Error in {nameof(AddLikeRecord)}({nameof(userId)} = '{userId}', {nameof(photoId)} = '{photoId}'):\n{ex.ToString()}"); throw; } }