From 4f3f4ec066a69a01f1532b35e617f4d517c27d47 Mon Sep 17 00:00:00 2001 From: Artemy <109195690+stalcker2288969@users.noreply.github.com> Date: Wed, 25 Jun 2025 15:16:14 +0700 Subject: [PATCH] Refactor to introduce Govor.Application and Govor.Contracts layers Moved service implementations and interfaces from Govor.API and Govor.Core to new Govor.Application and Govor.Contracts projects. Updated namespaces and references throughout the solution. Added custom exception classes for authentication and invite services. Adjusted dependency injection and project references to use the new structure. This refactor improves separation of concerns and prepares the codebase for better maintainability and scalability. --- .../Controllers/AuthControllerTests.cs | 6 ++++-- .../AdminStuff/InvitationGeneratorTests.cs | 2 +- .../Authentication/AuthServiceTests.cs | 5 +++-- .../Authentication/JwtServiceTests.cs | 2 +- .../Services/LocalStorageServiceTests.cs | 5 +++-- .../UnitTests/Services/PasswordHasherTests.cs | 2 +- .../AdminStuff/InviteUserController.cs | 5 ++--- Govor.API/Controllers/AuthController.cs | 6 ++++-- Govor.API/Controllers/InviteController.cs | 3 +-- .../ConfigurationProgramExtensions.cs | 13 +++++++++--- Govor.API/Govor.API.csproj | 2 ++ Govor.API/Program.cs | 18 +--------------- .../AuthService/LoginUserException.cs | 5 +++++ .../AuthService/UserAlreadyExistException.cs | 5 +++++ .../AuthService/UserNotRegisteredException.cs | 5 +++++ .../InviteLinkInvalidException.cs | 5 +++++ Govor.Application/Govor.Application.csproj | 21 +++++++++++++++++++ .../AdminsStuff/InvitationGenerator.cs | 2 +- .../Interfaces}/AdminsStuff/UsersService.cs | 3 +-- .../Authentication}/IAuthService.cs | 2 +- .../Authentication}/IInvitesService.cs | 0 .../Interfaces/Authentication}/IJwtService.cs | 0 .../Interfaces}/IGroupService.cs | 0 .../Interfaces/IInvitionGenerator.cs | 0 .../Interfaces}/IPasswordHasher.cs | 0 .../Interfaces}/IStorageService.cs | 4 +--- .../Interfaces/IUsersAdministration.cs | 0 .../Services}/AuthService.cs | 17 ++++----------- .../Services}/InvitesService.cs | 5 ++--- .../Services}/JwtOption.cs | 3 +-- .../Services}/JwtService.cs | 4 +--- .../Services/LocalStorageService.cs | 10 +++++---- .../Services/PasswordHasher.cs | 2 +- Govor.Console/Govor.Console.csproj | 1 + Govor.Console/Program.cs | 2 +- .../DTOs/InvitationDto.cs | 2 +- Govor.Contracts/Govor.Contracts.csproj | 13 ++++++++++++ .../Requests/CreateInvitationRequest.cs | 2 +- .../Requests/LoginRequest.cs | 2 +- .../Requests/RegistrationRequest.cs | 3 +-- Govor.sln | 14 +++++++++++++ 41 files changed, 126 insertions(+), 75 deletions(-) create mode 100644 Govor.Application/Exceptions/AuthService/LoginUserException.cs create mode 100644 Govor.Application/Exceptions/AuthService/UserAlreadyExistException.cs create mode 100644 Govor.Application/Exceptions/AuthService/UserNotRegisteredException.cs create mode 100644 Govor.Application/Exceptions/InvitesService/InviteLinkInvalidException.cs create mode 100644 Govor.Application/Govor.Application.csproj rename {Govor.API/Services => Govor.Application/Interfaces}/AdminsStuff/InvitationGenerator.cs (93%) rename {Govor.API/Services => Govor.Application/Interfaces}/AdminsStuff/UsersService.cs (89%) rename {Govor.API/Services/Authentication/Interfaces => Govor.Application/Interfaces/Authentication}/IAuthService.cs (79%) rename {Govor.API/Services/Authentication/Interfaces => Govor.Application/Interfaces/Authentication}/IInvitesService.cs (100%) rename {Govor.API/Services/Authentication/Interfaces => Govor.Application/Interfaces/Authentication}/IJwtService.cs (100%) rename {Govor.API/Services => Govor.Application/Interfaces}/IGroupService.cs (100%) rename {Govor.API/Services/AdminsStuff => Govor.Application}/Interfaces/IInvitionGenerator.cs (100%) rename {Govor.Core/Infrastructure/Extensions => Govor.Application/Interfaces}/IPasswordHasher.cs (100%) rename {Govor.API/Services => Govor.Application/Interfaces}/IStorageService.cs (66%) rename {Govor.API/Services/AdminsStuff => Govor.Application}/Interfaces/IUsersAdministration.cs (100%) rename {Govor.API/Services/Authentication => Govor.Application/Services}/AuthService.cs (83%) rename {Govor.API/Services/Authentication => Govor.Application/Services}/InvitesService.cs (87%) rename {Govor.API/Services/Authentication => Govor.Application/Services}/JwtOption.cs (68%) rename {Govor.API/Services/Authentication => Govor.Application/Services}/JwtService.cs (90%) rename {Govor.API => Govor.Application}/Services/LocalStorageService.cs (87%) rename {Govor.API => Govor.Application}/Services/PasswordHasher.cs (90%) rename {Govor.Core => Govor.Contracts}/DTOs/InvitationDto.cs (91%) create mode 100644 Govor.Contracts/Govor.Contracts.csproj rename {Govor.Core => Govor.Contracts}/Requests/CreateInvitationRequest.cs (84%) rename {Govor.Core => Govor.Contracts}/Requests/LoginRequest.cs (92%) rename {Govor.Core => Govor.Contracts}/Requests/RegistrationRequest.cs (90%) diff --git a/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs index 5de221f..b449ffa 100644 --- a/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs +++ b/Govor.API.Tests/IntegrationTests/Controllers/AuthControllerTests.cs @@ -1,9 +1,11 @@ using AutoFixture; using Govor.API.Controllers; -using Govor.API.Services.Authentication; using Govor.API.Services.Authentication.Interfaces; +using Govor.Application.Exceptions.AuthService; +using Govor.Application.Exceptions.InvitesService; +using Govor.Application.Interfaces.Authentication; +using Govor.Contracts.Requests; using Govor.Core.Models; -using Govor.Core.Requests; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Moq; diff --git a/Govor.API.Tests/UnitTests/Services/AdminStuff/InvitationGeneratorTests.cs b/Govor.API.Tests/UnitTests/Services/AdminStuff/InvitationGeneratorTests.cs index 76ecad5..98c50a1 100644 --- a/Govor.API.Tests/UnitTests/Services/AdminStuff/InvitationGeneratorTests.cs +++ b/Govor.API.Tests/UnitTests/Services/AdminStuff/InvitationGeneratorTests.cs @@ -1,6 +1,6 @@ using AutoFixture; -using Govor.API.Services.AdminsStuff; using Govor.API.Services.AdminsStuff.Interfaces; +using Govor.Application.Interfaces.AdminsStuff; using Govor.Core.Models; using Govor.Core.Repositories.Invaites; using Moq; diff --git a/Govor.API.Tests/UnitTests/Services/Authentication/AuthServiceTests.cs b/Govor.API.Tests/UnitTests/Services/Authentication/AuthServiceTests.cs index dcdf2bc..86d6990 100644 --- a/Govor.API.Tests/UnitTests/Services/Authentication/AuthServiceTests.cs +++ b/Govor.API.Tests/UnitTests/Services/Authentication/AuthServiceTests.cs @@ -1,11 +1,12 @@ using AutoFixture; -using Govor.API.Services.Authentication; using Govor.Core.Infrastructure.Extensions; using Govor.Core.Models; using Govor.Core.Repositories.Users; using Govor.API.Services.Authentication.Interfaces; +using Govor.Application.Exceptions.AuthService; +using Govor.Application.Interfaces.Authentication; +using Govor.Application.Services; using Govor.Core.Repositories.Admins; -using Govor.Core.Repositories.Invaites; using Moq; namespace Govor.API.Tests.UnitTests.Services.Authentication; diff --git a/Govor.API.Tests/UnitTests/Services/Authentication/JwtServiceTests.cs b/Govor.API.Tests/UnitTests/Services/Authentication/JwtServiceTests.cs index 4f3d36e..e33d71e 100644 --- a/Govor.API.Tests/UnitTests/Services/Authentication/JwtServiceTests.cs +++ b/Govor.API.Tests/UnitTests/Services/Authentication/JwtServiceTests.cs @@ -1,7 +1,7 @@ using System.IdentityModel.Tokens.Jwt; using AutoFixture; -using Govor.API.Services.Authentication; using Govor.API.Services.Authentication.Interfaces; +using Govor.Application.Services; using Govor.Core.Models; using Microsoft.Extensions.Options; using Moq; diff --git a/Govor.API.Tests/UnitTests/Services/LocalStorageServiceTests.cs b/Govor.API.Tests/UnitTests/Services/LocalStorageServiceTests.cs index 42bff42..c80da0a 100644 --- a/Govor.API.Tests/UnitTests/Services/LocalStorageServiceTests.cs +++ b/Govor.API.Tests/UnitTests/Services/LocalStorageServiceTests.cs @@ -1,5 +1,6 @@ using AutoFixture; -using Govor.API.Services; +using Govor.Application.Interfaces; +using Govor.Application.Services; using Microsoft.AspNetCore.Hosting; using Moq; @@ -24,7 +25,7 @@ public class LocalStorageServiceTests _webHostEnvironmentMock.Setup(w => w.ContentRootPath).Returns(_tempDirectory); - _service = new LocalStorageService(_webHostEnvironmentMock.Object); + _service = new LocalStorageService(_webHostEnvironmentMock.Object.ContentRootPath); } [TearDown] diff --git a/Govor.API.Tests/UnitTests/Services/PasswordHasherTests.cs b/Govor.API.Tests/UnitTests/Services/PasswordHasherTests.cs index 4326528..d060db5 100644 --- a/Govor.API.Tests/UnitTests/Services/PasswordHasherTests.cs +++ b/Govor.API.Tests/UnitTests/Services/PasswordHasherTests.cs @@ -1,5 +1,5 @@ using AutoFixture; -using Govor.API.Services; +using Govor.Application.Services; using Govor.Core.Infrastructure.Extensions; namespace Govor.API.Tests.UnitTests.Services; diff --git a/Govor.API/Controllers/AdminStuff/InviteUserController.cs b/Govor.API/Controllers/AdminStuff/InviteUserController.cs index 4b8893f..82a3a8a 100644 --- a/Govor.API/Controllers/AdminStuff/InviteUserController.cs +++ b/Govor.API/Controllers/AdminStuff/InviteUserController.cs @@ -1,8 +1,7 @@ -using AutoMapper; using Govor.API.Services.AdminsStuff.Interfaces; -using Govor.Core.DTOs; +using Govor.Contracts.DTOs; +using Govor.Contracts.Requests; using Govor.Core.Repositories.Invaites; -using Govor.Core.Requests; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Govor.API/Controllers/AuthController.cs b/Govor.API/Controllers/AuthController.cs index 295ca12..aff2159 100644 --- a/Govor.API/Controllers/AuthController.cs +++ b/Govor.API/Controllers/AuthController.cs @@ -1,6 +1,8 @@ -using Govor.API.Services.Authentication; using Govor.API.Services.Authentication.Interfaces; -using Govor.Core.Requests; +using Govor.Application.Exceptions.AuthService; +using Govor.Application.Exceptions.InvitesService; +using Govor.Application.Interfaces.Authentication; +using Govor.Contracts.Requests; using Microsoft.AspNetCore.Mvc; namespace Govor.API.Controllers; diff --git a/Govor.API/Controllers/InviteController.cs b/Govor.API/Controllers/InviteController.cs index dc2b00f..0da0c13 100644 --- a/Govor.API/Controllers/InviteController.cs +++ b/Govor.API/Controllers/InviteController.cs @@ -21,8 +21,7 @@ public class InviteController : ControllerBase { var group = _groupService.GetGroupByInvite(code); if (group == null) return NotFound(); - - // Вернуть инфу, которая откроется в MAUI-клиенте + return Ok(new { groupId = group.Id, diff --git a/Govor.API/Extensions/ConfigurationProgramExtensions.cs b/Govor.API/Extensions/ConfigurationProgramExtensions.cs index e05adca..df1a872 100644 --- a/Govor.API/Extensions/ConfigurationProgramExtensions.cs +++ b/Govor.API/Extensions/ConfigurationProgramExtensions.cs @@ -1,8 +1,9 @@ -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.Application.Interfaces; +using Govor.Application.Interfaces.AdminsStuff; +using Govor.Application.Interfaces.Authentication; +using Govor.Application.Services; using Govor.Core.Infrastructure.Extensions; using Govor.Core.Infrastructure.Validators; using Govor.Core.Models; @@ -27,6 +28,12 @@ public static class ConfigurationProgramExtensions services.AddScoped(); services.AddScoped(); services.AddScoped(); + + services.AddScoped(sp => + { + var env = sp.GetRequiredService(); + return new LocalStorageService(env.ContentRootPath); + }); } public static void AddRepositories(this IServiceCollection services) diff --git a/Govor.API/Govor.API.csproj b/Govor.API/Govor.API.csproj index 6a28550..8eb3e48 100644 --- a/Govor.API/Govor.API.csproj +++ b/Govor.API/Govor.API.csproj @@ -22,6 +22,8 @@ + + diff --git a/Govor.API/Program.cs b/Govor.API/Program.cs index 6c736f2..bf1019a 100644 --- a/Govor.API/Program.cs +++ b/Govor.API/Program.cs @@ -1,23 +1,7 @@ -using System.Security.Cryptography; using System.Text; using Govor.API.Extensions; 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.Admins; -using Govor.Core.Repositories.Invaites; -using Govor.Core.Repositories.MediasAttachments; -using Govor.Core.Repositories.Messages; -using Govor.Core.Repositories.Users; -using Govor.Data; -using Govor.Data.Repositories; -using Microsoft.EntityFrameworkCore; +using Govor.Application.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; diff --git a/Govor.Application/Exceptions/AuthService/LoginUserException.cs b/Govor.Application/Exceptions/AuthService/LoginUserException.cs new file mode 100644 index 0000000..7ad1d60 --- /dev/null +++ b/Govor.Application/Exceptions/AuthService/LoginUserException.cs @@ -0,0 +1,5 @@ +using Govor.Core; + +namespace Govor.Application.Exceptions.AuthService; + +public class LoginUserException : GovorCoreException { } \ No newline at end of file diff --git a/Govor.Application/Exceptions/AuthService/UserAlreadyExistException.cs b/Govor.Application/Exceptions/AuthService/UserAlreadyExistException.cs new file mode 100644 index 0000000..14827f5 --- /dev/null +++ b/Govor.Application/Exceptions/AuthService/UserAlreadyExistException.cs @@ -0,0 +1,5 @@ +using Govor.Core; + +namespace Govor.Application.Exceptions.AuthService; + +public class UserAlreadyExistException(string username) : GovorCoreException($"{username} is already exists!") { } \ No newline at end of file diff --git a/Govor.Application/Exceptions/AuthService/UserNotRegisteredException.cs b/Govor.Application/Exceptions/AuthService/UserNotRegisteredException.cs new file mode 100644 index 0000000..51f35b3 --- /dev/null +++ b/Govor.Application/Exceptions/AuthService/UserNotRegisteredException.cs @@ -0,0 +1,5 @@ +using Govor.Core; + +namespace Govor.Application.Exceptions.AuthService; + +public class UserNotRegisteredException(string username) : GovorCoreException($"{username} is not registered!") { } \ No newline at end of file diff --git a/Govor.Application/Exceptions/InvitesService/InviteLinkInvalidException.cs b/Govor.Application/Exceptions/InvitesService/InviteLinkInvalidException.cs new file mode 100644 index 0000000..4180c9d --- /dev/null +++ b/Govor.Application/Exceptions/InvitesService/InviteLinkInvalidException.cs @@ -0,0 +1,5 @@ +using Govor.Core; + +namespace Govor.Application.Exceptions.InvitesService; + +public class InviteLinkInvalidException(string inviteCode) : GovorCoreException($"Invite link invalid: {inviteCode}"); \ No newline at end of file diff --git a/Govor.Application/Govor.Application.csproj b/Govor.Application/Govor.Application.csproj new file mode 100644 index 0000000..24f32c2 --- /dev/null +++ b/Govor.Application/Govor.Application.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/Govor.API/Services/AdminsStuff/InvitationGenerator.cs b/Govor.Application/Interfaces/AdminsStuff/InvitationGenerator.cs similarity index 93% rename from Govor.API/Services/AdminsStuff/InvitationGenerator.cs rename to Govor.Application/Interfaces/AdminsStuff/InvitationGenerator.cs index 1b4dd8c..e744b65 100644 --- a/Govor.API/Services/AdminsStuff/InvitationGenerator.cs +++ b/Govor.Application/Interfaces/AdminsStuff/InvitationGenerator.cs @@ -2,7 +2,7 @@ using Govor.API.Services.AdminsStuff.Interfaces; using Govor.Core.Models; using Govor.Core.Repositories.Invaites; -namespace Govor.API.Services.AdminsStuff; +namespace Govor.Application.Interfaces.AdminsStuff; public class InvitationGenerator(IInvitesRepository repository) : IInvitationGenerator { diff --git a/Govor.API/Services/AdminsStuff/UsersService.cs b/Govor.Application/Interfaces/AdminsStuff/UsersService.cs similarity index 89% rename from Govor.API/Services/AdminsStuff/UsersService.cs rename to Govor.Application/Interfaces/AdminsStuff/UsersService.cs index 195ffde..10f41ec 100644 --- a/Govor.API/Services/AdminsStuff/UsersService.cs +++ b/Govor.Application/Interfaces/AdminsStuff/UsersService.cs @@ -1,10 +1,9 @@ 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; +namespace Govor.Application.Interfaces.AdminsStuff; public class UsersService : IUsersAdministration { diff --git a/Govor.API/Services/Authentication/Interfaces/IAuthService.cs b/Govor.Application/Interfaces/Authentication/IAuthService.cs similarity index 79% rename from Govor.API/Services/Authentication/Interfaces/IAuthService.cs rename to Govor.Application/Interfaces/Authentication/IAuthService.cs index df02845..1f54b69 100644 --- a/Govor.API/Services/Authentication/Interfaces/IAuthService.cs +++ b/Govor.Application/Interfaces/Authentication/IAuthService.cs @@ -1,6 +1,6 @@ using Govor.Core.Models; -namespace Govor.API.Services.Authentication.Interfaces; +namespace Govor.Application.Interfaces.Authentication; public interface IAccountService { diff --git a/Govor.API/Services/Authentication/Interfaces/IInvitesService.cs b/Govor.Application/Interfaces/Authentication/IInvitesService.cs similarity index 100% rename from Govor.API/Services/Authentication/Interfaces/IInvitesService.cs rename to Govor.Application/Interfaces/Authentication/IInvitesService.cs diff --git a/Govor.API/Services/Authentication/Interfaces/IJwtService.cs b/Govor.Application/Interfaces/Authentication/IJwtService.cs similarity index 100% rename from Govor.API/Services/Authentication/Interfaces/IJwtService.cs rename to Govor.Application/Interfaces/Authentication/IJwtService.cs diff --git a/Govor.API/Services/IGroupService.cs b/Govor.Application/Interfaces/IGroupService.cs similarity index 100% rename from Govor.API/Services/IGroupService.cs rename to Govor.Application/Interfaces/IGroupService.cs diff --git a/Govor.API/Services/AdminsStuff/Interfaces/IInvitionGenerator.cs b/Govor.Application/Interfaces/IInvitionGenerator.cs similarity index 100% rename from Govor.API/Services/AdminsStuff/Interfaces/IInvitionGenerator.cs rename to Govor.Application/Interfaces/IInvitionGenerator.cs diff --git a/Govor.Core/Infrastructure/Extensions/IPasswordHasher.cs b/Govor.Application/Interfaces/IPasswordHasher.cs similarity index 100% rename from Govor.Core/Infrastructure/Extensions/IPasswordHasher.cs rename to Govor.Application/Interfaces/IPasswordHasher.cs diff --git a/Govor.API/Services/IStorageService.cs b/Govor.Application/Interfaces/IStorageService.cs similarity index 66% rename from Govor.API/Services/IStorageService.cs rename to Govor.Application/Interfaces/IStorageService.cs index 778eeeb..f648964 100644 --- a/Govor.API/Services/IStorageService.cs +++ b/Govor.Application/Interfaces/IStorageService.cs @@ -1,6 +1,4 @@ -using Microsoft.AspNetCore.Http; // для IFormFile - -namespace Govor.API.Services; +namespace Govor.Application.Interfaces; public interface IStorageService { diff --git a/Govor.API/Services/AdminsStuff/Interfaces/IUsersAdministration.cs b/Govor.Application/Interfaces/IUsersAdministration.cs similarity index 100% rename from Govor.API/Services/AdminsStuff/Interfaces/IUsersAdministration.cs rename to Govor.Application/Interfaces/IUsersAdministration.cs diff --git a/Govor.API/Services/Authentication/AuthService.cs b/Govor.Application/Services/AuthService.cs similarity index 83% rename from Govor.API/Services/Authentication/AuthService.cs rename to Govor.Application/Services/AuthService.cs index 17e4617..673cb06 100644 --- a/Govor.API/Services/Authentication/AuthService.cs +++ b/Govor.Application/Services/AuthService.cs @@ -1,15 +1,12 @@ using Govor.API.Services.Authentication.Interfaces; -using Govor.Core; +using Govor.Application.Exceptions.AuthService; using Govor.Core.Infrastructure.Extensions; using Govor.Core.Models; using Govor.Core.Repositories.Users; -using Govor.API.Services; -using Govor.API.Services.AdminsStuff.Interfaces; +using Govor.Application.Interfaces.Authentication; using Govor.Core.Repositories.Admins; -using Govor.Core.Repositories.Invaites; - -namespace Govor.API.Services.Authentication; +namespace Govor.Application.Services; public class AuthService : IAccountService { @@ -75,10 +72,4 @@ public class AuthService : IAccountService if(invitation.IsAdmin) await _adminsRepository.AddAsync(new Admin() { UserId = user.Id }); } -} - -public class LoginUserException : GovorCoreException { } - -public class UserAlreadyExistException(string username) : GovorCoreException($"{username} is already exists!") { } - -public class UserNotRegisteredException(string username) : GovorCoreException($"{username} is not registered!") { } \ No newline at end of file +} \ No newline at end of file diff --git a/Govor.API/Services/Authentication/InvitesService.cs b/Govor.Application/Services/InvitesService.cs similarity index 87% rename from Govor.API/Services/Authentication/InvitesService.cs rename to Govor.Application/Services/InvitesService.cs index 1f6d806..4942535 100644 --- a/Govor.API/Services/Authentication/InvitesService.cs +++ b/Govor.Application/Services/InvitesService.cs @@ -1,10 +1,10 @@ using Govor.API.Services.Authentication.Interfaces; -using Govor.Core; +using Govor.Application.Exceptions.InvitesService; using Govor.Core.Models; using Govor.Core.Repositories.Invaites; using Govor.Data.Repositories.Exceptions; -namespace Govor.API.Services.Authentication; +namespace Govor.Application.Services; public class InvitesService : IInvitesService { @@ -49,4 +49,3 @@ public class InvitesService : IInvitesService } } -public class InviteLinkInvalidException(string inviteCode) : GovorCoreException($"Invite link invalid: {inviteCode}"); \ No newline at end of file diff --git a/Govor.API/Services/Authentication/JwtOption.cs b/Govor.Application/Services/JwtOption.cs similarity index 68% rename from Govor.API/Services/Authentication/JwtOption.cs rename to Govor.Application/Services/JwtOption.cs index 6a5c91f..144c231 100644 --- a/Govor.API/Services/Authentication/JwtOption.cs +++ b/Govor.Application/Services/JwtOption.cs @@ -1,5 +1,4 @@ -namespace Govor.API.Services.Authentication; - +namespace Govor.Application.Services; public class JwtOption { public string SecretKeу {get; set;} diff --git a/Govor.API/Services/Authentication/JwtService.cs b/Govor.Application/Services/JwtService.cs similarity index 90% rename from Govor.API/Services/Authentication/JwtService.cs rename to Govor.Application/Services/JwtService.cs index 18d04d9..f4787ee 100644 --- a/Govor.API/Services/Authentication/JwtService.cs +++ b/Govor.Application/Services/JwtService.cs @@ -3,12 +3,10 @@ using System.Security.Claims; using System.Text; using Govor.API.Services.Authentication.Interfaces; using Govor.Core.Models; -using Govor.Core.Repositories.Admins; -using Govor.Core.Repositories.Invaites; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; -namespace Govor.API.Services.Authentication; +namespace Govor.Application.Services; public class JwtService : IJwtService { diff --git a/Govor.API/Services/LocalStorageService.cs b/Govor.Application/Services/LocalStorageService.cs similarity index 87% rename from Govor.API/Services/LocalStorageService.cs rename to Govor.Application/Services/LocalStorageService.cs index 21d4f85..2b7e1fc 100644 --- a/Govor.API/Services/LocalStorageService.cs +++ b/Govor.Application/Services/LocalStorageService.cs @@ -1,12 +1,14 @@ -namespace Govor.API.Services; +using Govor.Application.Interfaces; +using Microsoft.AspNetCore.Hosting; +namespace Govor.Application.Services; public class LocalStorageService : IStorageService { private readonly string _storagePath; - - public LocalStorageService(IWebHostEnvironment hostingEnvironment) + + public LocalStorageService(string contentRootPath) { - _storagePath = Path.Combine(hostingEnvironment.ContentRootPath, "uploads"); + _storagePath = Path.Combine(contentRootPath, "uploads"); if (!Directory.Exists(_storagePath)) { diff --git a/Govor.API/Services/PasswordHasher.cs b/Govor.Application/Services/PasswordHasher.cs similarity index 90% rename from Govor.API/Services/PasswordHasher.cs rename to Govor.Application/Services/PasswordHasher.cs index 4976236..ec83d71 100644 --- a/Govor.API/Services/PasswordHasher.cs +++ b/Govor.Application/Services/PasswordHasher.cs @@ -1,6 +1,6 @@ using Govor.Core.Infrastructure.Extensions; -namespace Govor.API.Services; +namespace Govor.Application.Services; public class PasswordHasher : IPasswordHasher { diff --git a/Govor.Console/Govor.Console.csproj b/Govor.Console/Govor.Console.csproj index e3a0a72..49d4e74 100644 --- a/Govor.Console/Govor.Console.csproj +++ b/Govor.Console/Govor.Console.csproj @@ -15,6 +15,7 @@ + diff --git a/Govor.Console/Program.cs b/Govor.Console/Program.cs index 8ff42f0..126420e 100644 --- a/Govor.Console/Program.cs +++ b/Govor.Console/Program.cs @@ -2,7 +2,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Net.Http.Json; using System.Text.Json; -using Govor.Core.Requests; +using Govor.Contracts.Requests; /*==================================== diff --git a/Govor.Core/DTOs/InvitationDto.cs b/Govor.Contracts/DTOs/InvitationDto.cs similarity index 91% rename from Govor.Core/DTOs/InvitationDto.cs rename to Govor.Contracts/DTOs/InvitationDto.cs index fd58a6c..3cc7838 100644 --- a/Govor.Core/DTOs/InvitationDto.cs +++ b/Govor.Contracts/DTOs/InvitationDto.cs @@ -1,4 +1,4 @@ -namespace Govor.Core.DTOs; +namespace Govor.Contracts.DTOs; public class InvitationDto { diff --git a/Govor.Contracts/Govor.Contracts.csproj b/Govor.Contracts/Govor.Contracts.csproj new file mode 100644 index 0000000..4f3150c --- /dev/null +++ b/Govor.Contracts/Govor.Contracts.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/Govor.Core/Requests/CreateInvitationRequest.cs b/Govor.Contracts/Requests/CreateInvitationRequest.cs similarity index 84% rename from Govor.Core/Requests/CreateInvitationRequest.cs rename to Govor.Contracts/Requests/CreateInvitationRequest.cs index 861b460..11f6a4c 100644 --- a/Govor.Core/Requests/CreateInvitationRequest.cs +++ b/Govor.Contracts/Requests/CreateInvitationRequest.cs @@ -1,4 +1,4 @@ -namespace Govor.Core.Requests; +namespace Govor.Contracts.Requests; public class CreateInvitationRequest { diff --git a/Govor.Core/Requests/LoginRequest.cs b/Govor.Contracts/Requests/LoginRequest.cs similarity index 92% rename from Govor.Core/Requests/LoginRequest.cs rename to Govor.Contracts/Requests/LoginRequest.cs index 2779aa8..f36455e 100644 --- a/Govor.Core/Requests/LoginRequest.cs +++ b/Govor.Contracts/Requests/LoginRequest.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations; using Govor.Core.Infrastructure.Validators; -namespace Govor.Core.Requests; +namespace Govor.Contracts.Requests; public class LoginRequest { diff --git a/Govor.Core/Requests/RegistrationRequest.cs b/Govor.Contracts/Requests/RegistrationRequest.cs similarity index 90% rename from Govor.Core/Requests/RegistrationRequest.cs rename to Govor.Contracts/Requests/RegistrationRequest.cs index 40c7290..9a85a0d 100644 --- a/Govor.Core/Requests/RegistrationRequest.cs +++ b/Govor.Contracts/Requests/RegistrationRequest.cs @@ -1,8 +1,7 @@ using System.ComponentModel.DataAnnotations; using Govor.Core.Infrastructure.Validators; -using Govor.Core.Models; -namespace Govor.Core.Requests; +namespace Govor.Contracts.Requests; public record RegistrationRequest { diff --git a/Govor.sln b/Govor.sln index 20e5835..2a9769a 100644 --- a/Govor.sln +++ b/Govor.sln @@ -14,6 +14,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4ED5259A EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{114F53C1-B0AB-4BA0-9E36-0E811D1B3776}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Govor.Contracts", "Govor.Contracts\Govor.Contracts.csproj", "{4E94907F-BE20-42A6-AB15-637850FEAD11}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Govor.Application", "Govor.Application\Govor.Application.csproj", "{FC5EDCA8-FD58-4078-8FB1-2BDBB2F6CA3E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -40,6 +44,14 @@ Global {F4535DC3-BDFB-4EB2-B259-F92B6BBB535B}.Debug|Any CPU.Build.0 = Debug|Any CPU {F4535DC3-BDFB-4EB2-B259-F92B6BBB535B}.Release|Any CPU.ActiveCfg = Release|Any CPU {F4535DC3-BDFB-4EB2-B259-F92B6BBB535B}.Release|Any CPU.Build.0 = Release|Any CPU + {4E94907F-BE20-42A6-AB15-637850FEAD11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E94907F-BE20-42A6-AB15-637850FEAD11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E94907F-BE20-42A6-AB15-637850FEAD11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E94907F-BE20-42A6-AB15-637850FEAD11}.Release|Any CPU.Build.0 = Release|Any CPU + {FC5EDCA8-FD58-4078-8FB1-2BDBB2F6CA3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC5EDCA8-FD58-4078-8FB1-2BDBB2F6CA3E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC5EDCA8-FD58-4078-8FB1-2BDBB2F6CA3E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC5EDCA8-FD58-4078-8FB1-2BDBB2F6CA3E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {15031CBD-F319-4755-BA91-B86F20BD8E37} = {4ED5259A-6FB4-4D89-8E6B-4778DC68F7D4} @@ -47,5 +59,7 @@ Global {F4535DC3-BDFB-4EB2-B259-F92B6BBB535B} = {114F53C1-B0AB-4BA0-9E36-0E811D1B3776} {F7BB1EC7-63D6-4525-ADE4-E4AC937E219D} = {114F53C1-B0AB-4BA0-9E36-0E811D1B3776} {E4EDB179-7EB5-468D-9C1F-0CBE2E5E459E} = {114F53C1-B0AB-4BA0-9E36-0E811D1B3776} + {4E94907F-BE20-42A6-AB15-637850FEAD11} = {114F53C1-B0AB-4BA0-9E36-0E811D1B3776} + {FC5EDCA8-FD58-4078-8FB1-2BDBB2F6CA3E} = {114F53C1-B0AB-4BA0-9E36-0E811D1B3776} EndGlobalSection EndGlobal