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.
This commit is contained in:
Artemy
2025-06-25 15:16:14 +07:00
parent 5693190b1c
commit 4f3f4ec066
41 changed files with 126 additions and 75 deletions
@@ -0,0 +1,26 @@
using Govor.API.Services.AdminsStuff.Interfaces;
using Govor.Core.Models;
using Govor.Core.Repositories.Invaites;
namespace Govor.Application.Interfaces.AdminsStuff;
public class InvitationGenerator(IInvitesRepository repository) : IInvitationGenerator
{
public async Task<string> GenerateInvitationCode(DateTime time, int maxUsers, bool isAdmin, string description = "")
{
Invitation newInvitation = new Invitation()
{
Id = Guid.NewGuid(),
Description = description,
MaxParticipants = maxUsers,
DateCreated = DateTime.UtcNow,
EndDate = time.ToUniversalTime(),
Code = Guid.NewGuid().ToString("N"),
IsAdmin = isAdmin
};
await repository.AddAsync(newInvitation);
return newInvitation.Code;
}
}
@@ -0,0 +1,29 @@
using Govor.API.Services.AdminsStuff.Interfaces;
using Govor.Core.Models;
using Govor.Core.Repositories.Users;
using Govor.Data.Repositories.Exceptions;
namespace Govor.Application.Interfaces.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>();
}
}
}
@@ -0,0 +1,9 @@
using Govor.Core.Models;
namespace Govor.Application.Interfaces.Authentication;
public interface IAccountService
{
public Task<string> RegistrationAsync(string name, string password, Invitation invitation);
public Task<string> LoginAsync(string name, string password);
}
@@ -0,0 +1,9 @@
using Govor.Core.Models;
namespace Govor.API.Services.Authentication.Interfaces;
public interface IInvitesService
{
public Task<string> GetRole(User user);
public Invitation Validate(string inviteCode);
}
@@ -0,0 +1,8 @@
using Govor.Core.Models;
namespace Govor.API.Services.Authentication.Interfaces;
public interface IJwtService
{
string GenerateJwtToken(User user);
}
@@ -0,0 +1,8 @@
using Govor.Core.Models;
namespace Govor.API.Services;
public interface IGroupService
{
ChatGroup GetGroupByInvite(string code);
}
@@ -0,0 +1,6 @@
namespace Govor.API.Services.AdminsStuff.Interfaces;
public interface IInvitationGenerator
{
public Task<string> GenerateInvitationCode(DateTime time, int maxUsers, bool isAdmin, string description = "");
}
@@ -0,0 +1,7 @@
namespace Govor.Core.Infrastructure.Extensions;
public interface IPasswordHasher
{
string Hash(string password);
bool Verify(string hashedPassword, string providedPassword);
}
@@ -0,0 +1,8 @@
namespace Govor.Application.Interfaces;
public interface IStorageService
{
Task<string> SaveAsync(byte[] data, string fileName);
Task<Stream> LoadAsync(string url);
Task RemoveAsync(string url);
}
@@ -0,0 +1,8 @@
using Govor.Core.Models;
namespace Govor.API.Services.AdminsStuff.Interfaces;
public interface IUsersAdministration
{
Task<List<User>> GetAllUsersAsync();
}