Created
September 17, 2022 00:57
-
-
Save benjaminvanrenterghem/6fe3a671b2644942e8ee75dc0707d6fa to your computer and use it in GitHub Desktop.
Endpoint
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
[HttpPost("register")] | |
[Authorize(ApiConfig.AuthorizedFor_Public)] | |
// #1 We maken gebruik van een request dto voor ontvangst van data | |
public async Task<ActionResult> RegisterUser(UserRequestDTO userRequestDTO) { | |
try { | |
// #2 Middels de dependency injected Mediator maken we gebruik van een bestaande IRequest, CreateUserCommand | |
// Deze versturen we op de Pipeline waarna het verzoek afgehandeld wordt. | |
var res = await _mediator.Send( | |
new CreateUserCommand() { | |
ParsedJwtToken = JwtTokenParser.ParseRequest(Request), | |
UserRequestDTO = userRequestDTO | |
} | |
); | |
// #3 Afhankelijk van het resultaat retourneren we status code 200 of 400 | |
return res.Success ? Ok(res) : BadRequest(res); | |
} catch (Exception ex) { | |
return BadRequest(new FallbackResponse(nameof(UserController) + ApiConfig.ExcSeparator + ex.Message)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment