mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Admin stuff init
UserController
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
using Govor.API.Services.AdminsStuff.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Govor.API.Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
[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)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_users = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> AllUsers()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Getting all users by administrator");
|
||||||
|
var read = await _users.GetAllUsersAsync();
|
||||||
|
|
||||||
|
return Ok(read);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:guid}")]
|
||||||
|
public async Task<IActionResult> GetUserById(Guid id)
|
||||||
|
{
|
||||||
|
return Ok(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Govor.API.Hubs;
|
using Govor.API.Hubs;
|
||||||
using Govor.API.Services;
|
using Govor.API.Services;
|
||||||
|
using Govor.API.Services.AdminsStuff;
|
||||||
|
using Govor.API.Services.AdminsStuff.Interfaces;
|
||||||
using Govor.API.Services.Authentication;
|
using Govor.API.Services.Authentication;
|
||||||
using Govor.API.Services.Authentication.Interfaces;
|
using Govor.API.Services.Authentication.Interfaces;
|
||||||
using Govor.Core.Infrastructure.Extensions;
|
using Govor.Core.Infrastructure.Extensions;
|
||||||
using Govor.Core.Infrastructure.Validators;
|
using Govor.Core.Infrastructure.Validators;
|
||||||
using Govor.Core.Models;
|
using Govor.Core.Models;
|
||||||
|
using Govor.Core.Repositories.MediasAttachments;
|
||||||
|
using Govor.Core.Repositories.Messages;
|
||||||
using Govor.Core.Repositories.Users;
|
using Govor.Core.Repositories.Users;
|
||||||
using Govor.Data;
|
using Govor.Data;
|
||||||
using Govor.Data.Repositories;
|
using Govor.Data.Repositories;
|
||||||
@@ -75,6 +79,11 @@ builder.Services.AddScoped<IJwtService, JwtService>();
|
|||||||
builder.Services.AddScoped<IAccountService, AuthService>();
|
builder.Services.AddScoped<IAccountService, AuthService>();
|
||||||
builder.Services.AddScoped<IUsersRepository, UsersRepository>();
|
builder.Services.AddScoped<IUsersRepository, UsersRepository>();
|
||||||
builder.Services.AddScoped<IObjectValidator<User>, UserValidator>();
|
builder.Services.AddScoped<IObjectValidator<User>, UserValidator>();
|
||||||
|
builder.Services.AddScoped<IObjectValidator<Message>, MessageValidator>();
|
||||||
|
builder.Services.AddScoped<IObjectValidator<MediaAttachments>, MediaAttachmentsValidator>();
|
||||||
|
builder.Services.AddScoped<IMessagesRepository, MessagesRepository>();
|
||||||
|
builder.Services.AddScoped<IMediaAttachmentsRepository, MediaAttachmentsRepository>();
|
||||||
|
builder.Services.AddScoped<IUsersAdministration, UsersService>();
|
||||||
|
|
||||||
builder.Services.AddDbContext<GovorDbContext>(
|
builder.Services.AddDbContext<GovorDbContext>(
|
||||||
options =>
|
options =>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Govor.Core.Models;
|
||||||
|
|
||||||
|
namespace Govor.API.Services.AdminsStuff.Interfaces;
|
||||||
|
|
||||||
|
public interface IUsersAdministration
|
||||||
|
{
|
||||||
|
Task<List<User>> GetAllUsersAsync();
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using Govor.API.Services.AdminsStuff.Interfaces;
|
||||||
|
using Govor.Core.Models;
|
||||||
|
using Govor.Core.Repositories.Users;
|
||||||
|
using Govor.Data.Repositories;
|
||||||
|
using Govor.Data.Repositories.Exceptions;
|
||||||
|
|
||||||
|
namespace Govor.API.Services.AdminsStuff;
|
||||||
|
|
||||||
|
public class UsersService : IUsersAdministration
|
||||||
|
{
|
||||||
|
private readonly IUsersRepository _usersRepository;
|
||||||
|
|
||||||
|
public UsersService(IUsersRepository usersRepository)
|
||||||
|
{
|
||||||
|
_usersRepository = usersRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<User>> GetAllUsersAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var results = await _usersRepository.GetAllAsync();
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
catch (NotFoundException ex)
|
||||||
|
{
|
||||||
|
return new List<User>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ namespace Govor.Core.Repositories.Users;
|
|||||||
|
|
||||||
public interface IUsersReader
|
public interface IUsersReader
|
||||||
{
|
{
|
||||||
public Task<IEnumerable<User>> GetAllAsync();
|
public Task<List<User>> GetAllAsync();
|
||||||
public Task<User> FindByIdAsync(Guid id);
|
public Task<User> FindByIdAsync(Guid id);
|
||||||
public Task<List<User>> FindByRangeIdAsync(IEnumerable<Guid> ids);
|
public Task<List<User>> FindByRangeIdAsync(IEnumerable<Guid> ids);
|
||||||
public Task<User> FindByUsernameAsync(string username);
|
public Task<User> FindByUsernameAsync(string username);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class UsersRepository : IUsersRepository
|
|||||||
_validator = validator;
|
_validator = validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<User>> GetAllAsync()
|
public async Task<List<User>> GetAllAsync()
|
||||||
{
|
{
|
||||||
return await _context.Users
|
return await _context.Users
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
|
|||||||
Reference in New Issue
Block a user