Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private const string TableName = "comments";
private readonly IAmazonDynamoDB _amazonDynamoDb;
public CommentsController(IAmazonDynamoDB amazonDynammoDb)
{
_amazonDynamoDb = amazonDynammoDb;
}
[HttpGet]
public async Task<ScanResponse> GetComments()
{
var request = new ScanRequest
{
TableName = TableName
};
var response = await _amazonDynamoDb.ScanAsync(request);
return response;
}
[HttpGet("{url}")]
public async Task<ActionResult<string>> Get(string url)
{
var request = new GetItemRequest
{
TableName = TableName,
Key = new Dictionary<string, AttributeValue>
{
{
"postId",
new AttributeValue
{
S = url
}
}
}
};
var response = await _amazonDynamoDb.GetItemAsync(request);
return response.Item["username"].S;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment