Skip to content

Commit

Permalink
Create controller for users
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryba1986 committed Jul 3, 2022
1 parent 746f8b6 commit 39ffa3a
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/Zeus.Api.Web/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -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<IActionResult> GetUsers()
{
return await SendAsync(new GetUsersQuery());
}

[Authorization(UserRole.Admin)]
[HttpGet]
public async Task<IActionResult> GetUserHistory([FromQuery] GetUserHistoryQuery request)
{
return await SendAsync(request);
}

[HttpGet]
public async Task<IActionResult> GetUserRoleDictionary()
{
return await SendAsync(new GetUserRoleDictionaryQuery());
}

[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> GetUserToken([FromBody] GetUserTokenQuery request)
{
return await SendAsync(request);
}

[HttpPost]
public async Task<IActionResult> GetUserTokenRefresh()
{
return await SendAsync(new GetUserTokenRefreshQuery()
{
UserId = GetUserId()
});
}

[Authorization(UserRole.Admin)]
[HttpPost]
public async Task<IActionResult> CreateUser([FromBody] CreateUserCommand request)
{
request.Update(GetUserId());
return await SendAsync(request);
}

[Authorization(UserRole.Admin)]
[HttpPost]
public async Task<IActionResult> UpdateUser([FromBody] UpdateUserCommand request)
{
request.Update(GetUserId());
return await SendAsync(request);
}

[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> ChangeUserPassword([FromBody] ChangePasswordUserCommand request)
{
return await SendAsync(request);
}
}
}

0 comments on commit 39ffa3a

Please sign in to comment.