From 39ffa3acce20f66fe3bc3f9b9321fc50c80cc182 Mon Sep 17 00:00:00 2001 From: Maciej Rybarczyk Date: Sun, 3 Jul 2022 20:45:30 +0200 Subject: [PATCH] Create controller for users --- .../Controllers/UserController.cs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/Zeus.Api.Web/Controllers/UserController.cs diff --git a/src/Zeus.Api.Web/Controllers/UserController.cs b/src/Zeus.Api.Web/Controllers/UserController.cs new file mode 100644 index 0000000..3c532b3 --- /dev/null +++ b/src/Zeus.Api.Web/Controllers/UserController.cs @@ -0,0 +1,77 @@ +using System.Threading.Tasks; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Zeus.Api.Web.Attributes; +using Zeus.Enums.Users; +using Zeus.Models.Users.Commands; +using Zeus.Models.Users.Queries; + +namespace Zeus.Api.Web.Controllers +{ + public sealed class UserController : BaseController + { + public UserController(IMediator mediator) : base(mediator) + { + } + + [Authorization(UserRole.Admin)] + [HttpGet] + public async Task GetUsers() + { + return await SendAsync(new GetUsersQuery()); + } + + [Authorization(UserRole.Admin)] + [HttpGet] + public async Task GetUserHistory([FromQuery] GetUserHistoryQuery request) + { + return await SendAsync(request); + } + + [HttpGet] + public async Task GetUserRoleDictionary() + { + return await SendAsync(new GetUserRoleDictionaryQuery()); + } + + [AllowAnonymous] + [HttpPost] + public async Task GetUserToken([FromBody] GetUserTokenQuery request) + { + return await SendAsync(request); + } + + [HttpPost] + public async Task GetUserTokenRefresh() + { + return await SendAsync(new GetUserTokenRefreshQuery() + { + UserId = GetUserId() + }); + } + + [Authorization(UserRole.Admin)] + [HttpPost] + public async Task CreateUser([FromBody] CreateUserCommand request) + { + request.Update(GetUserId()); + return await SendAsync(request); + } + + [Authorization(UserRole.Admin)] + [HttpPost] + public async Task UpdateUser([FromBody] UpdateUserCommand request) + { + request.Update(GetUserId()); + return await SendAsync(request); + } + + [AllowAnonymous] + [HttpPost] + public async Task ChangeUserPassword([FromBody] ChangePasswordUserCommand request) + { + return await SendAsync(request); + } + } +}