public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "accounts")] HttpRequestMessage req, ILogger log, CancellationToken token) { var securityToken = JwtTokenUtils.GetSecurityToken(req); var objectId = JwtTokenUtils.GetObjectId(securityToken); var accounts = await _mediator.Send( new GetAccountQuery { UserId = objectId }, token); return(new OkObjectResult(accounts)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "accounts")] HttpRequestMessage req, ILogger log, CancellationToken token) { var jwtSecurityToken = JwtTokenUtils.GetSecurityToken(req); var objectId = JwtTokenUtils.GetObjectId(jwtSecurityToken); try { await _mediator.Send(new CloseAccountsCommand { UserId = objectId }, token); return(new OkResult()); } catch (ValidationException ex) { log.LogError("Validations Errors {errors}", ex.Errors); return(new BadRequestObjectResult(ex)); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "put", Route = "accounts")] HttpRequestMessage req, ILogger log, CancellationToken token) { var jwtSecurityToken = JwtTokenUtils.GetSecurityToken(req); var objectId = JwtTokenUtils.GetObjectId(jwtSecurityToken); var command = await req.Content.ReadAsAsync <UpdateAccountCommand>(token); command.UserId = objectId; try { var id = await _mediator.Send(command, token); log.LogInformation("Updated account with id {id}", id); return(new OkResult()); } catch (ValidationException ex) { log.LogError("Validations Errors {errors}", ex.Errors); return(new BadRequestObjectResult(ex)); } }