-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersController.cs
More file actions
75 lines (67 loc) · 2.97 KB
/
UsersController.cs
File metadata and controls
75 lines (67 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using ECommerceAPI.Application.CustomAttributes;
using ECommerceAPI.Application.Enums;
using ECommerceAPI.Application.Features.Commands.AppUser.AssignRoleToUser;
using ECommerceAPI.Application.Features.Commands.AppUser.CreateUser;
using ECommerceAPI.Application.Features.Commands.AppUser.UpdatePassword;
using ECommerceAPI.Application.Features.Queries.AppUser;
using ECommerceAPI.Application.Features.Queries.AppUser.GetAllUsers;
using ECommerceAPI.Application.Features.Queries.AppUser.GetUserRoles;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace ECommerceAPI.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UsersController : ControllerBase
{
readonly IMediator _mediator;
public UsersController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet("[action]")]
[Authorize(AuthenticationSchemes = "Admin")]
public async Task<IActionResult> Me()
{
var response = await _mediator.Send(new GetMeQueryRequest());
return Ok(response);
}
[HttpPost]
public async Task<IActionResult> CreateUser(CreateUserCommandRequest createUserCommandRequest)
{
var response = await _mediator.Send(createUserCommandRequest);
return Ok(response);
}
[HttpPost("update-password")]
public async Task<IActionResult> UpdatePassword([FromBody] UpdatePasswordCommandRequest updatePasswordCommandRequest)
{
var response = await _mediator.Send(updatePasswordCommandRequest);
return Ok(response);
}
[HttpGet]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get All Users", Menu = "Users")]
public async Task<IActionResult> GetUsers([FromQuery] GetAllUsersQueryRequest getAllUsersQueryRequest)
{
var response = await _mediator.Send(getAllUsersQueryRequest);
return Ok(response);
}
[HttpGet("get-user-roles/{UserId}")]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(ActionType = ActionType.Reading, Definition = "Get User Roles", Menu = "Users")]
public async Task<IActionResult> GetUserRoles([FromRoute] GetUserRolesQueryRequest getUserRolesQueryRequest)
{
var response = await _mediator.Send(getUserRolesQueryRequest);
return Ok(response);
}
[HttpPost("assign-role-to-user")]
[Authorize(AuthenticationSchemes = "Admin")]
[AuthorizeDefinition(ActionType = ActionType.Writing, Definition = "Assign Role To User", Menu = "Users")]
public async Task<IActionResult> AssignRoleToUser(AssignRoleToUserCommandRequest assignRoleToUserCommandRequest)
{
var response = await _mediator.Send(assignRoleToUserCommandRequest);
return Ok(response);
}
}
}