diff --git a/Govor.API/Controllers/UsersController.cs b/Govor.API/Controllers/UsersController.cs new file mode 100644 index 0000000..1d958c4 --- /dev/null +++ b/Govor.API/Controllers/UsersController.cs @@ -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 _logger; + private readonly IUsersAdministration _users; + + public UsersController(ILogger logger, IUsersAdministration users) + { + _logger = logger; + _users = users; + } + + [HttpGet] + public async Task AllUsers() + { + _logger.LogInformation("Getting all users by administrator"); + var read = await _users.GetAllUsersAsync(); + + return Ok(read); + } + + [HttpGet("{id:guid}")] + public async Task GetUserById(Guid id) + { + return Ok(id); + } +} \ No newline at end of file diff --git a/Govor.API/Program.cs b/Govor.API/Program.cs index 5e6ff00..ca2d75d 100644 --- a/Govor.API/Program.cs +++ b/Govor.API/Program.cs @@ -1,11 +1,15 @@ using System.Text; using Govor.API.Hubs; 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.Interfaces; using Govor.Core.Infrastructure.Extensions; using Govor.Core.Infrastructure.Validators; using Govor.Core.Models; +using Govor.Core.Repositories.MediasAttachments; +using Govor.Core.Repositories.Messages; using Govor.Core.Repositories.Users; using Govor.Data; using Govor.Data.Repositories; @@ -75,6 +79,11 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped, UserValidator>(); +builder.Services.AddScoped, MessageValidator>(); +builder.Services.AddScoped, MediaAttachmentsValidator>(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddDbContext( options => diff --git a/Govor.API/Services/AdminsStuff/Interfaces/IUsersAdministration.cs b/Govor.API/Services/AdminsStuff/Interfaces/IUsersAdministration.cs new file mode 100644 index 0000000..f08836f --- /dev/null +++ b/Govor.API/Services/AdminsStuff/Interfaces/IUsersAdministration.cs @@ -0,0 +1,8 @@ +using Govor.Core.Models; + +namespace Govor.API.Services.AdminsStuff.Interfaces; + +public interface IUsersAdministration +{ + Task> GetAllUsersAsync(); +} \ No newline at end of file diff --git a/Govor.API/Services/AdminsStuff/UsersService.cs b/Govor.API/Services/AdminsStuff/UsersService.cs new file mode 100644 index 0000000..195ffde --- /dev/null +++ b/Govor.API/Services/AdminsStuff/UsersService.cs @@ -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> GetAllUsersAsync() + { + try + { + var results = await _usersRepository.GetAllAsync(); + return results; + } + catch (NotFoundException ex) + { + return new List(); + } + } +} \ No newline at end of file diff --git a/Govor.Core/Repositories/Users/IUsersReader.cs b/Govor.Core/Repositories/Users/IUsersReader.cs index 472772a..46326fe 100644 --- a/Govor.Core/Repositories/Users/IUsersReader.cs +++ b/Govor.Core/Repositories/Users/IUsersReader.cs @@ -4,7 +4,7 @@ namespace Govor.Core.Repositories.Users; public interface IUsersReader { - public Task> GetAllAsync(); + public Task> GetAllAsync(); public Task FindByIdAsync(Guid id); public Task> FindByRangeIdAsync(IEnumerable ids); public Task FindByUsernameAsync(string username); diff --git a/Govor.Data/Repositories/UsersRepository.cs b/Govor.Data/Repositories/UsersRepository.cs index 843a1d2..dde1f4e 100644 --- a/Govor.Data/Repositories/UsersRepository.cs +++ b/Govor.Data/Repositories/UsersRepository.cs @@ -18,7 +18,7 @@ public class UsersRepository : IUsersRepository _validator = validator; } - public async Task> GetAllAsync() + public async Task> GetAllAsync() { return await _context.Users .AsNoTracking()