Esempio n. 1
0
            static async Task <(DynamoDbScoreDataV1 data, string hash)> GetAsync(
                IAmazonDynamoDB client,
                string tableName,
                Guid ownerId,
                Guid scoreId)
            {
                var partitionKey = ScoreDatabaseUtils.ConvertToPartitionKey(ownerId);
                var score        = ScoreDatabaseUtils.ConvertToBase64(scoreId);

                var request = new GetItemRequest()
                {
                    TableName = tableName,
                    Key       = new Dictionary <string, AttributeValue>()
                    {
                        [DynamoDbScorePropertyNames.PartitionKey] = new AttributeValue(partitionKey),
                        [DynamoDbScorePropertyNames.SortKey]      =
                            new AttributeValue(ScoreDatabaseConstant.ScoreIdMainPrefix + score),
                    },
                };
                var response = await client.GetItemAsync(request);

                var data = response.Item[DynamoDbScorePropertyNames.Data];

                if (data is null)
                {
                    throw new InvalidOperationException("not found.");
                }


                DynamoDbScoreDataV1.TryMapFromAttributeValue(data, out var result);
                var hash = response.Item[DynamoDbScorePropertyNames.DataHash].S;

                return(result, hash);
            }
Esempio n. 2
0
 public static ScoreData Create(DynamoDbScoreDataV1 data)
 {
     return(new ScoreData()
     {
         Title = data.Title,
         DescriptionHash = data.DescriptionHash,
         Pages = data.Page.Select(x => new ScorePage()
         {
             Id = x.Id,
             Page = x.Page,
             ItemId = ScoreDatabaseUtils.ConvertToGuid(x.ItemId),
             ObjectName = x.ObjectName,
         }).ToArray(),
         Annotations = data.Annotations.Select(x => new ScoreAnnotation()
         {
             Id = x.Id,
             ContentHash = x.ContentHash,
         }).ToArray(),
     });
 }