mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
6d1c53beeb
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
using Govor.Application.Infrastructure.AdminsStuff;
|
|
using Govor.Contracts.Responses.Admins;
|
|
using Govor.Domain.Models.Users;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Govor.API.Controllers.AdminStuff;
|
|
|
|
|
|
[ApiController]
|
|
[Route("api/admin/[controller]")]
|
|
[Authorize(Roles = "Admin")]
|
|
public class UsersController : Controller
|
|
{
|
|
private readonly ILogger<UsersController> _logger;
|
|
private readonly IUsersAdministration _users;
|
|
|
|
|
|
public UsersController(ILogger<UsersController> logger,
|
|
IUsersAdministration users,
|
|
IInvitationGenerator invitationGenerator)
|
|
{
|
|
_logger = logger;
|
|
_users = users;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> AllUsers()
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation("Getting all users by administrator");
|
|
var read = await _users.GetAllUsersAsync();
|
|
|
|
return Ok(BuildUserDtos(read));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, e.Message);
|
|
return StatusCode(500, e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<IActionResult> GetUserById(Guid id)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation($"Getting user {id} by administrator");
|
|
var read = await _users.GetUserById(id);
|
|
return Ok(BuildUserDtos([read]).First());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, e.Message);
|
|
return StatusCode(500, e.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet("user/{id:guid}/setpassword/{password}")]
|
|
public async Task<IActionResult> SetNewPassword(Guid id, string password)
|
|
{
|
|
try
|
|
{
|
|
await _users.SetPasswordAsync(id, password);
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, ex.Message);
|
|
}
|
|
}
|
|
|
|
private List<UserResponse> BuildUserDtos(IEnumerable<User> users) => users.Select(user => new UserResponse
|
|
{
|
|
Id = user.Id,
|
|
Username = user.Username,
|
|
Description = user.Description,
|
|
WasOnline = user.WasOnline,
|
|
IconId = user.IconId,
|
|
PasswordHash = user.PasswordHash,
|
|
InviteId = user.InviteId,
|
|
CreatedOn = user.CreatedOn,
|
|
IsAdmin = user.Invite?.IsAdmin ?? false,
|
|
}).ToList();
|
|
|
|
} |