/
softailor
/
gridient
Обзор
Документация
Войти
/
softailor
/
gridient
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/Gridient.Infrastructure.Authentication.Local/Controllers/UsersController.cs
49 строк
2 KB
Jenkins
Auto add
18 фев 2026, 10:19
18 фев 2026, 10:19
1e6c4f8
Код
Авторство
О чём код?
using Gridient.Core.Controllers; using Gridient.Core.Models; using Gridient.Infrastructure.Authentication.Local.Features.AuthUsers.Commands; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Gridient.Infrastructure.Authentication.Local.Controllers { [Route("api/[controller]")] [ApiController] [Authorize] public class UsersController(IMediator mediator) : ListsBaseController { private readonly IMediator _mediator = mediator; [HttpPost] [Route(nameof(CreateUser))] public async Task<IActionResult> CreateUser(CreateUserRequest newUser, CancellationToken cancellationToken) { try { var command = new CreateUserCommand(newUser, CurrentUserLogin); var userId = await _mediator.Send(command, cancellationToken); return Ok(new { userId }); } catch (InvalidOperationException ex) { return BadRequest(ex.Message); } } [HttpDelete] [Route(nameof(DeleteUser))] public async Task<IActionResult> DeleteUser(int userId, CancellationToken cancellationToken) { try { var command = new DeleteUserCommand(userId, CurrentUserLogin); await _mediator.Send(command, cancellationToken); return Ok(); } catch (InvalidOperationException ex) { return NotFound(ex.Message); } } } }