using System.Threading.Tasks; using API.Database; using API.Service; using AutoMapper; using Microsoft.AspNetCore.Mvc; using Data.Models.DTOs.Identity; using Microsoft.AspNetCore.Authorization; using Data.Models.Options; namespace API.Controllers { [ApiController] [Route("/api/[controller]")] public class UserController: ControllerBase { private readonly UserService _service; public UserController(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions) { this._service = new UserService(context, mapper, jwtOptions); } [HttpPost] [Route("Login")] public async Task Login([FromBody] LoginDTO loginDTO) { return await this._service.LoginUser(loginDTO); } [HttpPost] [Route("Register")] public async Task Register([FromBody] RegisterDTO registerDto) { return await this._service.RegisterUser(registerDto); } //Read [HttpGet] public async Task GetById(int id) { return await this._service.GetUserById(id); } //Update [HttpPut] [Authorize] public async Task Update(int id, [FromBody] UserDTO userDTO) { return await this._service.UpdateUser(id, userDTO); } //Delete [HttpDelete] [Authorize] public async Task Delete(int id) { return await this._service.DeleteUser(id); } } }