-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamoDBEmployeeRepositoryMeta.cs
More file actions
79 lines (74 loc) · 2.5 KB
/
DynamoDBEmployeeRepositoryMeta.cs
File metadata and controls
79 lines (74 loc) · 2.5 KB
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
70
71
72
73
74
75
76
77
78
79
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using AutoFixture;
public partial class DynamoDBEmployeeRepository
{
public const string TableName = "Employees";
public async Task GenerateEmployeesInDeparment(
string department,
int count,
CancellationToken cancellationToken
)
{
var fixture = new Fixture();
for (var i = 0; i < count; i++)
{
var employee = fixture.Create<Employee>() with
{
Department = department,
Metadata = new Metadata(DateTime.UtcNow),
};
await _createEmployee.Send(employee, cancellationToken);
}
}
public async Task<bool> EnsureTableIsCreated(CancellationToken cancellationToken)
{
try
{
await _database.DescribeTableAsync(TableName, cancellationToken);
return true;
}
catch (ResourceNotFoundException)
{
await _database.CreateTableAsync(
new CreateTableRequest()
{
TableName = TableName,
AttributeDefinitions = new List<AttributeDefinition>()
{
new AttributeDefinition()
{
AttributeName = nameof(Employee.Department),
AttributeType = "S",
},
new AttributeDefinition()
{
AttributeName = nameof(Employee.Email),
AttributeType = "S",
},
},
KeySchema = new List<KeySchemaElement>()
{
new KeySchemaElement()
{
AttributeName = nameof(Employee.Department),
KeyType = KeyType.HASH,
},
new KeySchemaElement()
{
AttributeName = nameof(Employee.Email),
KeyType = KeyType.RANGE,
},
},
ProvisionedThroughput = new ProvisionedThroughput()
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 5,
},
},
cancellationToken
);
return false;
}
}
}