Skip to content

Commit

Permalink
feat: clean architecture fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abubakrmirgiyasov committed Apr 9, 2024
1 parent 3ed39c3 commit e320a79
Show file tree
Hide file tree
Showing 189 changed files with 2,593 additions and 2,581 deletions.
21 changes: 14 additions & 7 deletions Mint.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.Web.Infrastructure.Tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.WebApp.Admin.Identity", "src\modules\Identity\Mint.WebApp.Admin.Identity\Mint.WebApp.Admin.Identity.csproj", "{6700AD78-48CC-4C06-AC7E-0780BA195F2D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.WebApp.Extensions", "src\modules\Services\Mint.WebApp.Extensions\Mint.WebApp.Extensions.csproj", "{6190895E-647A-47EA-9378-907FEE9C7453}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.Architecture.Tests", "tests\Mint.Architecture.Tests\Mint.Architecture.Tests.csproj", "{C270E6D2-373C-48CE-B534-D1CD9D3A40A7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.WebApp.Admin.Tests", "src\modules\Admin\Mint.WebApp.Admin.Tests\Mint.WebApp.Admin.Tests.csproj", "{EC4FA327-929A-465E-B2F8-155A1A187A9C}"
Expand All @@ -55,6 +53,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.WebApp.HealthChecker",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.WebApp.Admin.Application", "src\modules\Admin\Mint.WebApp.Admin.Application\Mint.WebApp.Admin.Application.csproj", "{2EE99609-9259-4E94-902C-091C56B2A337}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.WebApp.Identity.Application", "src\modules\Identity\Mint.WebApp.Identity.Application\Mint.WebApp.Identity.Application.csproj", "{A4B2BF08-9621-47D8-AB40-CB0EFCE5BD16}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mint.Application", "src\Mint.Application\Mint.Application.csproj", "{F8224E05-7862-4521-92F9-C050EB1A4B5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -113,10 +115,6 @@ Global
{6700AD78-48CC-4C06-AC7E-0780BA195F2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6700AD78-48CC-4C06-AC7E-0780BA195F2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6700AD78-48CC-4C06-AC7E-0780BA195F2D}.Release|Any CPU.Build.0 = Release|Any CPU
{6190895E-647A-47EA-9378-907FEE9C7453}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6190895E-647A-47EA-9378-907FEE9C7453}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6190895E-647A-47EA-9378-907FEE9C7453}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6190895E-647A-47EA-9378-907FEE9C7453}.Release|Any CPU.Build.0 = Release|Any CPU
{C270E6D2-373C-48CE-B534-D1CD9D3A40A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C270E6D2-373C-48CE-B534-D1CD9D3A40A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C270E6D2-373C-48CE-B534-D1CD9D3A40A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -133,6 +131,14 @@ Global
{2EE99609-9259-4E94-902C-091C56B2A337}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EE99609-9259-4E94-902C-091C56B2A337}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EE99609-9259-4E94-902C-091C56B2A337}.Release|Any CPU.Build.0 = Release|Any CPU
{A4B2BF08-9621-47D8-AB40-CB0EFCE5BD16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4B2BF08-9621-47D8-AB40-CB0EFCE5BD16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4B2BF08-9621-47D8-AB40-CB0EFCE5BD16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4B2BF08-9621-47D8-AB40-CB0EFCE5BD16}.Release|Any CPU.Build.0 = Release|Any CPU
{F8224E05-7862-4521-92F9-C050EB1A4B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8224E05-7862-4521-92F9-C050EB1A4B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8224E05-7862-4521-92F9-C050EB1A4B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8224E05-7862-4521-92F9-C050EB1A4B5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -156,11 +162,12 @@ Global
{04A3D8C5-44BA-4E01-9E33-7FA2BC5CCDBA} = {B4987191-ABF8-472B-9432-C0222120D832}
{306E3BBB-14A8-45E6-BDC4-52822A0F7B32} = {EBC3A9B7-E9B3-4526-A282-E072FEA7B8F1}
{6700AD78-48CC-4C06-AC7E-0780BA195F2D} = {7A823355-1953-4B19-A64F-F7A53AF449A7}
{6190895E-647A-47EA-9378-907FEE9C7453} = {B4987191-ABF8-472B-9432-C0222120D832}
{C270E6D2-373C-48CE-B534-D1CD9D3A40A7} = {EBC3A9B7-E9B3-4526-A282-E072FEA7B8F1}
{EC4FA327-929A-465E-B2F8-155A1A187A9C} = {E02DA575-B073-4084-89A9-2615E37C0C06}
{C5647212-6FC3-44B7-A741-2A47E1DC8EF5} = {B4987191-ABF8-472B-9432-C0222120D832}
{2EE99609-9259-4E94-902C-091C56B2A337} = {E02DA575-B073-4084-89A9-2615E37C0C06}
{A4B2BF08-9621-47D8-AB40-CB0EFCE5BD16} = {7A823355-1953-4B19-A64F-F7A53AF449A7}
{F8224E05-7862-4521-92F9-C050EB1A4B5F} = {326E6240-5F0D-451D-BEC7-81D042DF5321}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E2E3EF17-D76B-4080-B8AA-2FB58CBB21B8}
Expand Down
18 changes: 0 additions & 18 deletions src/Gateway/Mint.WebApp.Gateway/Mint.WebApp.Gateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="AdminApp\**" />
<Compile Remove="ClientApp\**" />
<Content Remove="AdminApp\**" />
<Content Remove="ClientApp\**" />
<EmbeddedResource Remove="AdminApp\**" />
<EmbeddedResource Remove="ClientApp\**" />
<None Remove="AdminApp\**" />
<None Remove="ClientApp\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.3" />
<PackageReference Include="Ocelot" Version="23.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Mint.Domain\Mint.Domain.csproj" />
<ProjectReference Include="..\..\Mint.Infrastructure\Mint.Infrastructure.csproj" />
<ProjectReference Include="..\..\modules\Services\Mint.WebApp.Extensions\Mint.WebApp.Extensions.csproj" />
</ItemGroup>

</Project>
3 changes: 0 additions & 3 deletions src/Gateway/Mint.WebApp.Gateway/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Mint.Infrastructure.Middlewares;
using Mint.WebApp.Services;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
Expand All @@ -10,8 +9,6 @@

var app = builder.Build();

app.UseMiddleware<ExceptionMiddleware>();

app.UseWebSockets();
app.UseOcelot().Wait();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MediatR;

namespace Mint.WebApp.Admin.Application.Common.Messaging;
namespace Mint.Application.Interfaces;

public interface ICommand : IRequest;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Mint.Domain.Models.Email;

namespace Mint.Infrastructure.Services.Interfaces;
namespace Mint.Application.Interfaces;

public interface IEmailService
{
Expand Down
22 changes: 22 additions & 0 deletions src/Mint.Application/Interfaces/IGenericReadRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Linq.Expressions;

namespace Mint.Application.Interfaces;

/// <summary>
/// Общий репозиторий для чтения сущности типа <typeparamref name="T"></typeparamref>.
/// </summary>
/// <typeparam name="T">Тип сущности, с которым работает данный репозиторий.</typeparam>
public interface IGenericReadRepository<T> where T : class
{
Task<List<T>> GetAllAsync(CancellationToken cancellationToken = default);

Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> func, CancellationToken cancellationToken = default);

Task<T?> SingleOrDefaultAsync(Expression<Func<T, bool>> func, CancellationToken cancellationToken = default);

Task<int> CountAsync(CancellationToken cancellationToken = default);

Task<int> CountAsync(Expression<Func<T, bool>> func, CancellationToken cancellationToken = default);

Task<bool> AnyAsync(Expression<Func<T, bool>> func, CancellationToken cancellationToken = default);
}
44 changes: 44 additions & 0 deletions src/Mint.Application/Interfaces/IGenericRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Mint.Application.Interfaces;

/// <summary>
/// Общий репозиторий для сущности типа <typeparamref name="T"></typeparamref>.
/// </summary>
/// <typeparam name="T">Тип сущности, с которым работает данный репозиторий.</typeparam>
public interface IGenericRepository<T> : IGenericReadRepository<T> where T : class
{
/// <summary>
/// Добавляет указанную сущность в базу данных.
/// </summary>
/// <param name="entity">Добавляемая сущность.</param>
Task AddAsync(T entity, CancellationToken cancellationToken = default);

/// <summary>
/// Добавляет указанные сущности в базу данных.
/// </summary>
/// <param name="entities">Добавляемые сущности.</param>
Task AddRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default);

/// <summary>
/// Обновляет указанную сущность в базе данных.
/// </summary>
/// <param name="entity">Обновляемая сущность.</param>
void Update(T entity);

/// <summary>
/// Обновляет указанные сущности в базе данных.
/// </summary>
/// <param name="entities">Обновляемые сущности.</param>
Task UpdateRange(IEnumerable<T> entities, CancellationToken cancellationToken = default);

/// <summary>
/// Удаляет указанную сущность из базы данных.
/// </summary>
/// <param name="entity">Удаляемая сущность.</param>
void Remove(T entity);

/// <summary>
/// Удаляет указанные сущности из базы данных.
/// </summary>
/// <param name="entities">Удаляемые сущности.</param>
Task RemoveRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Mint.Domain.Models.Identity;

namespace Mint.Infrastructure.Services.Interfaces;
namespace Mint.Application.Interfaces;

/// <summary>
/// Interface for Jwt generator & checker class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MediatR;

namespace Mint.WebApp.Admin.Application.Common.Messaging;
namespace Mint.Application.Interfaces;

public interface IQuery : IRequest;

Expand Down
106 changes: 106 additions & 0 deletions src/Mint.Application/Interfaces/IStorageCloudService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Microsoft.AspNetCore.Http;

namespace Mint.Application.Interfaces;

/// <summary>
/// Service for interacting with MinIO storage service.
/// </summary>
public interface IStorageCloudService
{
/// <summary>
/// Retrieves a pre-signed URL for downloading a file from the specified bucket.
/// </summary>
/// <param name="name"></param>
/// <param name="bucket"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string?> GetFileLinkAsync(string name, string bucket, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves an array of pre-signed URLs for downloading multiple files from the specified bucket.
/// </summary>
/// <param name="names"></param>
/// <param name="bucket"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string[]> GetFilesLinkAsync(string[] names, string bucket, CancellationToken cancellationToken = default);

/// <summary>
/// Creates a new bucket with the specified name
/// </summary>
/// <param name="bucket"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> CreateBucketAsync(string bucket, CancellationToken cancellationToken = default);

/// <summary>
/// Uploads a file to the specified bucket.
/// </summary>
/// <param name="file"></param>
/// <param name="name"></param>
/// <param name="bucket"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> UploadFileAsync(IFormFile file, string name, string bucket, CancellationToken cancellationToken = default);

/// <summary>
/// Uploads a file from the provided stream.
/// </summary>
/// <param name="stream"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> UploadFileAsync(Stream stream, CancellationToken cancellationToken = default);

/// <summary>
/// Uploads a file from the provided stream.
/// </summary>
/// <param name="file"></param>
/// <param name="currentFileName"></param>
/// <param name="newFileName"></param>
/// <param name="bucket"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> UpdateFileAsync(IFormFile file, string currentFileName, string newFileName, string bucket, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes a file from the specified bucket.
/// </summary>
/// <param name="name"></param>
/// <param name="bucket"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> DeleteFileAsync(string name, string bucket, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes multiple files from their respective buckets.
/// </summary>
/// <param name="names"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> DeleteFilesAsync(string[] names, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes a bucket with the specified name.
/// </summary>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> DeleteBucketAsync(string name, CancellationToken cancellationToken = default);

/// <summary>
/// Checks if a file with the specified name exists.
/// </summary>
/// <param name="bucket"></param>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> IsFileExists(string bucket, string name, CancellationToken cancellationToken = default);

/// <summary>
/// Checks if a bucket with the specified name exists.
/// </summary>
/// <param name="bucket"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> IsBucketExists(string bucket, CancellationToken cancellationToken = default);
}
21 changes: 21 additions & 0 deletions src/Mint.Application/Interfaces/ITransaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Mint.Application.Interfaces;

/// <summary>
/// Представляет абстракцию над транзакцией базы данных.
/// </summary>
public interface ITransaction
{
/// <summary>
/// Завершает транзакцию с успехом.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task CommitAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Откатывает изменения транзакции.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RollbackAsync(CancellationToken cancellationToken = default);
}
21 changes: 21 additions & 0 deletions src/Mint.Application/Interfaces/IUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Mint.Application.Interfaces;

/// <summary>
/// Единица работы с базой данных Mint.
/// </summary>
public interface IUnitOfWork
{
/// <summary>
/// Асинхронно создает транзакцию базы данных.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns>Объект представляющий созданную транзакцию <see cref="ITransaction"/>.</returns>
Task<ITransaction> BeginTransactionAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Сохраняет изменения.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns>Количество измененных строк в базе данных.</returns>
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MediatR;
using Microsoft.Extensions.Logging;

namespace Mint.Infrastructure.MessageBrokers;
namespace Mint.Application;

public class LoggingBehavior<TRequest, TResponse>(ILogger<LoggingBehavior<TRequest, TResponse>> logger)
: IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
Expand Down
19 changes: 19 additions & 0 deletions src/Mint.Application/Mint.Application.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.32" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Mint.Domain\Mint.Domain.csproj" />
</ItemGroup>

</Project>
18 changes: 0 additions & 18 deletions src/Mint.Domain/Common/CommonExtensions.cs

This file was deleted.

Loading

0 comments on commit e320a79

Please sign in to comment.