Skip to content

Instantly share code, notes, and snippets.

@zainafzal88
Created October 7, 2020 09:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zainafzal88/d8c6d40e4571712e7eb92c0e2b578c9a to your computer and use it in GitHub Desktop.
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