78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
namespace AAIntegration.SimmonsBank.API.Controllers;
|
|
|
|
using AutoMapper;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
using AAIntegration.SimmonsBank.API.Models.Users;
|
|
using AAIntegration.SimmonsBank.API.Services;
|
|
using AAIntegration.SimmonsBank.API.Config;
|
|
using System;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class UsersController : ControllerBase
|
|
{
|
|
private IUserService _userService;
|
|
private IMapper _mapper;
|
|
private readonly AppSettings _appSettings;
|
|
private readonly ILogger<UsersController> _logger;
|
|
|
|
public UsersController(
|
|
IUserService userService,
|
|
IMapper mapper,
|
|
IOptions<AppSettings> appSettings,
|
|
ILogger<UsersController> logger)
|
|
{
|
|
_userService = userService;
|
|
_mapper = mapper;
|
|
_appSettings = appSettings.Value;
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpPost("authenticate")]
|
|
public IActionResult Authenticate(AuthenticateRequest model)
|
|
{
|
|
var response = _userService.Authenticate(model);
|
|
return Ok(response);
|
|
}
|
|
|
|
[HttpPost("register")]
|
|
public IActionResult Register(RegisterRequest model)
|
|
{
|
|
_userService.Register(model);
|
|
return Ok(new { message = "Registration successful" });
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpGet]
|
|
public IActionResult GetAll()
|
|
{
|
|
var users = _userService.GetAll();
|
|
return Ok(users);
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpGet("{id}")]
|
|
public IActionResult GetById(int id)
|
|
{
|
|
var user = _userService.GetById(id);
|
|
return Ok(user);
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpPut("{id}")]
|
|
public IActionResult Update(int id, [FromBody]UserUpdateRequest model)
|
|
{
|
|
_userService.Update(id, model);
|
|
return Ok(new { message = "User updated" });
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpDelete("{id}")]
|
|
public IActionResult Delete(int id)
|
|
{
|
|
_userService.Delete(id);
|
|
return Ok(new { message = "User deleted" });
|
|
}
|
|
} |