Created
October 7, 2020 09:14
-
-
Save zainafzal88/d8c6d40e4571712e7eb92c0e2b578c9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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