Created
September 21, 2020 07:47
-
-
Save laur3d/afbb960a897165881e8c8f00f5e9ec46 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
[FunctionName("GetCartForSession")] | |
public static async Task<IActionResult> RunAsync( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "cart/{id}")] HttpRequestMessage req, | |
Guid id, | |
[DurableClient] IDurableClient client, | |
ILogger log) | |
{ | |
if (id == Guid.Empty) | |
{ | |
return (ActionResult) new BadRequestObjectResult("The ID is required"); | |
} | |
var entityId = new EntityId(nameof(ShoppingCartEntity), id.ToString()); | |
var stateResponse = await client.ReadEntityStateAsync<ShoppingCartEntity>(entityId); | |
if (!stateResponse.EntityExists) | |
{ | |
return (ActionResult) new NotFoundObjectResult("No cart with this id"); | |
} | |
var response = stateResponse.EntityState.GetCartItems(); | |
return (ActionResult) new OkObjectResult(response.Result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment