diff options
Diffstat (limited to 'API/Controllers')
| -rw-r--r-- | API/Controllers/UserController.cs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/API/Controllers/UserController.cs b/API/Controllers/UserController.cs index fdb1c44..ceeee33 100644 --- a/API/Controllers/UserController.cs +++ b/API/Controllers/UserController.cs @@ -4,6 +4,9 @@ using API.Service; using AutoMapper; using Microsoft.AspNetCore.Mvc; using Data.Models.DTOs; +using Microsoft.AspNetCore.Authorization; +using Data.Models.Options; +using Microsoft.Extensions.Configuration; namespace API.Controllers { @@ -13,16 +16,23 @@ namespace API.Controllers { private readonly UserService _service; - public UserController(DevHiveContext context, IMapper mapper) + public UserController(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions) { - this._service = new UserService(context, mapper); + this._service = new UserService(context, mapper, jwtOptions); } - //Create [HttpPost] - public async Task<IActionResult> Create([FromBody] UserDTO userDTO) + [Route("login")] + public async Task<IActionResult> Login([FromBody] LoginDTO loginDTO) { - return await this._service.CreateUser(userDTO); + return await this._service.LoginUser(loginDTO); + } + + [HttpPost] + [Route("register")] + public async Task<IActionResult> Register([FromBody] RegisterDTO registerDto) + { + return await this._service.RegisterUser(registerDto); } //Read @@ -34,13 +44,15 @@ namespace API.Controllers //Update [HttpPut] + [Authorize] public async Task<IActionResult> Update(int id, [FromBody] UserDTO userDTO) { return await this._service.UpdateUser(id, userDTO); } //Delete - [HttpDelete] + [HttpDelete] + [Authorize] public async Task<IActionResult> Delete(int id) { return await this._service.DeleteUser(id); |
