-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathMoviesRepository.cs
69 lines (63 loc) · 2.07 KB
/
MoviesRepository.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using System.Threading.Tasks;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.Model;
using Models;
namespace SqsReader.Dynamo
{
public class MoviesRepository : IMoviesRepository
{
private const string TableName = "Movies";
private readonly IDatabaseClient _client;
private readonly IDynamoDBContext _context;
private readonly DynamoDBOperationConfig _operationConfig;
public MoviesRepository(IDatabaseClient client, IDynamoDBContext context)
{
_client = client;
_context = context;
_operationConfig = new DynamoDBOperationConfig
{
OverrideTableName = TableName
};
}
public async Task CreateTableAsync()
{
var request = new CreateTableRequest
{
TableName = TableName,
KeySchema = new List<KeySchemaElement>
{
new KeySchemaElement
{
AttributeName = "Title",
KeyType = "HASH"
}
},
AttributeDefinitions = new List<AttributeDefinition>
{
new AttributeDefinition
{
AttributeName = "Title",
AttributeType = "S"
}
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 5
},
StreamSpecification = new StreamSpecification
{
StreamEnabled = true,
StreamViewType = StreamViewType.NEW_AND_OLD_IMAGES
}
};
await _client.CreateTableAsync(request);
}
public async Task SaveMovieAsync(Movie movie)
{
await _context.SaveAsync(movie, _operationConfig);
}
}
}