Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export $(grep -v '^#' .env | xargs)
case "$1" in
up)
echo "Starting all services..."
docker-compose -f docker/docker-compose.yml up --build --exit-code-from migration-runner --remove-orphans
docker-compose -f docker/docker-compose.yml up -d
sudo docker compose -f docker/docker-compose.yml up --build --exit-code-from migration-runner --remove-orphans
sudo docker compose -f docker/docker-compose.yml up -d
;;
down)
echo "Stopping all services..."
docker-compose -f docker/docker-compose.yml down
sudo docker compose -f docker/docker-compose.yml down
;;
logs)
if [ -z "$2" ]; then
Expand All @@ -67,13 +67,13 @@ case "$1" in
exit 1
fi
echo "Following logs for $2..."
docker-compose -f docker/docker-compose.yml logs -f $2
sudo docker compose -f docker/docker-compose.yml logs -f $2
;;
prune)
read -p "Are you sure you want to remove all containers, networks, and volumes? This action is irreversible. [y/N] " confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
echo "Pruning the environment..."
docker-compose -f docker/docker-compose.yml down -v --remove-orphans
sudo docker compose -f docker/docker-compose.yml down -v --remove-orphans
else
echo "Prune operation cancelled."
fi
Expand Down
2 changes: 1 addition & 1 deletion src/IdentityService/Api/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Application.UseCases.UserRegistration;
using Application.UseCases.UserLogin;
using Api.DTOs;
using Application.Interfaces;
using IdentityService.Application.Contracts;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down
7 changes: 4 additions & 3 deletions src/IdentityService/Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Api.Extensions;
using Api.Filters;
using Api.Services;
using Application.Contracts;
using IdentityService.Application.Contracts;
using Hangfire;
using Hangfire.PostgreSql;
using Infrastructure.Persistence;
Expand All @@ -16,6 +16,7 @@
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Infrastructure;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -28,11 +29,11 @@
builder.Services.AddDbContext<IdentityDbContext>(options =>
options.UseNpgsql(connectionString));

builder.Services.AddInfrastructure();

// ۳. ثبت سرویس‌های دامنه (Domain Services)
builder.Services.AddScoped<IPasswordHasher, PasswordHasher>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<IJournalRepository, JournalRepository>();
builder.Services.AddScoped<IJournalAnalyzer, JournalAnalyzer>();
builder.Services.AddSingleton<IJwtTokenGenerator, JwtTokenGenerator>();
builder.Services.AddScoped<IOutboxPublisherService, OutboxPublisherService>();

Expand Down
2 changes: 1 addition & 1 deletion src/IdentityService/Api/Services/IdentityGrpcService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Api/Services/IdentityGrpcService.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using Application.UseCases.UserLogin;
using Application.UseCases.UserRegistration;
using Grpc.Core;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Application/Interfaces/IJournalAnalyzer.cs

namespace Application.Interfaces;
namespace IdentityService.Application.Contracts;

/// <summary>
/// رابط (Interface) برای تحلیل ژورنال‌ها
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Core.Entities;

namespace Application.Interfaces;
namespace IdentityService.Application.Contracts;

/// <summary>
/// رابط (Interface) برای دسترسی به داده‌های ژورنال‌ها
Expand Down
18 changes: 4 additions & 14 deletions src/IdentityService/Application/Contracts/IJwtTokenGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// مسیر: src/IdentityService/Application/Interfaces/IJwtTokenGenerator.cs
// src/IdentityService/Application/Contracts/IJwtTokenGenerator.cs
using Core.Entities;

namespace Application.Interfaces;
namespace IdentityService.Application.Contracts;

/// <summary>
/// رابط (Interface) برای تولید JWT Token
/// این Interface در لایه Application تعریف شده تا از وابستگی به Infrastructure جلوگیری شود.
/// </summary>
public interface IJwtTokenGenerator
{
/// <summary>
/// تولید JWT Token برای کاربر
/// </summary>
/// <param name="userId">شناسه کاربر</param>
/// <param name="username">نام کاربری</param>
/// <returns>JWT Token به صورت رشته</returns>
string GenerateToken(Guid userId, string username);
string GenerateToken(User user);
}

20 changes: 3 additions & 17 deletions src/IdentityService/Application/Contracts/IPasswordHasher.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
// مسیر: src/IdentityService/Application/Interfaces/IPasswordHasher.cs
// src/IdentityService/Application/Contracts/IPasswordHasher.cs
namespace IdentityService.Application.Contracts;

namespace Application.Interfaces;

/// <summary>
/// رابط (Interface) برای سرویس هش کردن و تأیید رمز عبور
/// این Interface در لایه Application تعریف شده تا از وابستگی به Infrastructure جلوگیری شود.
/// </summary>
public interface IPasswordHasher
{
/// <summary>
/// رمز عبور را هش می‌کند و رشته هش شده را برمی‌گرداند
/// </summary>
string HashPassword(string password);

/// <summary>
/// رمز عبور را با هش ذخیره شده مقایسه می‌کند
/// </summary>
/// <returns>true اگر رمز عبور صحیح باشد، در غیر این صورت false</returns>
bool VerifyPassword(string password, string passwordHash);
bool VerifyPassword(string hashedPasswordWithSalt, string password);
}

4 changes: 2 additions & 2 deletions src/IdentityService/Application/Contracts/IUserRepository.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// مسیر: src/IdentityService/Application/Interfaces/IUserRepository.cs
// مسیر: src/IdentityService/Application/Contracts/IUserRepository.cs

using Core.Entities;

namespace Application.Interfaces;
namespace IdentityService.Application.Contracts;

/// <summary>
/// رابط (Interface) برای دسترسی به داده‌های کاربران
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Application/UseCases/Journals/CreateJournal/CreateJournalCommandHandler.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using Core.Entities;
using Hangfire;
using MediatR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Application/UseCases/Journals/GetJournals/GetJournalsQueryHandler.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using MediatR;

namespace Application.UseCases.Journals.GetJournals;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Application/UseCases/UserLogin/LoginUserCommandHandler.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using MediatR;

namespace Application.UseCases.UserLogin;
Expand Down Expand Up @@ -44,7 +44,7 @@ public async Task<LoginUserResult> Handle(LoginUserCommand request, Cancellation
}

// تولید JWT Token
var token = _jwtTokenGenerator.GenerateToken(user.Id, user.Username);
var token = _jwtTokenGenerator.GenerateToken(user);

// برگرداندن نتیجه
return new LoginUserResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Application/UseCases/UserRegistration/RegisterUserCommandHandler.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using Core.Entities;
using MediatR;
using System.Text.Json;
Expand Down
30 changes: 15 additions & 15 deletions src/IdentityService/IdentityService.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "Api\Api.csproj", "{A
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityService.UnitTests", "Tests\IdentityService.UnitTests\IdentityService.UnitTests.csproj", "{8FFA98D6-D093-4723-9A59-D1462AB44549}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityService.IntegrationTests", "Tests\IdentityService.IntegrationTests\IdentityService.IntegrationTests.csproj", "{B93CDA45-D676-4A4A-93B8-7D1164C3C314}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityService.UnitTests", "Tests\IdentityService.UnitTests\IdentityService.UnitTests.csproj", "{6C393D8C-544F-4C48-AA58-5F40C85A72F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -75,18 +75,6 @@ Global
{AABAC28C-142F-4B37-9154-4E735BC7FFCA}.Release|x64.Build.0 = Release|Any CPU
{AABAC28C-142F-4B37-9154-4E735BC7FFCA}.Release|x86.ActiveCfg = Release|Any CPU
{AABAC28C-142F-4B37-9154-4E735BC7FFCA}.Release|x86.Build.0 = Release|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Debug|x64.ActiveCfg = Debug|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Debug|x64.Build.0 = Debug|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Debug|x86.ActiveCfg = Debug|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Debug|x86.Build.0 = Debug|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Release|Any CPU.Build.0 = Release|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Release|x64.ActiveCfg = Release|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Release|x64.Build.0 = Release|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Release|x86.ActiveCfg = Release|Any CPU
{8FFA98D6-D093-4723-9A59-D1462AB44549}.Release|x86.Build.0 = Release|Any CPU
{B93CDA45-D676-4A4A-93B8-7D1164C3C314}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B93CDA45-D676-4A4A-93B8-7D1164C3C314}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B93CDA45-D676-4A4A-93B8-7D1164C3C314}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -99,12 +87,24 @@ Global
{B93CDA45-D676-4A4A-93B8-7D1164C3C314}.Release|x64.Build.0 = Release|Any CPU
{B93CDA45-D676-4A4A-93B8-7D1164C3C314}.Release|x86.ActiveCfg = Release|Any CPU
{B93CDA45-D676-4A4A-93B8-7D1164C3C314}.Release|x86.Build.0 = Release|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Debug|x64.ActiveCfg = Debug|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Debug|x64.Build.0 = Debug|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Debug|x86.ActiveCfg = Debug|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Debug|x86.Build.0 = Debug|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Release|Any CPU.Build.0 = Release|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Release|x64.ActiveCfg = Release|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Release|x64.Build.0 = Release|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Release|x86.ActiveCfg = Release|Any CPU
{6C393D8C-544F-4C48-AA58-5F40C85A72F9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8FFA98D6-D093-4723-9A59-D1462AB44549} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
{B93CDA45-D676-4A4A-93B8-7D1164C3C314} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
{6C393D8C-544F-4C48-AA58-5F40C85A72F9} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions src/IdentityService/Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// مسیر: src/IdentityService/Infrastructure/DependencyInjection.cs
using IdentityService.Application.Contracts;
using Infrastructure.Repositories;
using Infrastructure.Services;
using Microsoft.Extensions.DependencyInjection;

namespace Infrastructure;

public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
{
services.AddScoped<IJournalRepository, JournalRepository>();
services.AddScoped<IJournalAnalyzer, JournalAnalyzer>();
return services;
}
}
4 changes: 4 additions & 0 deletions src/IdentityService/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<using Include="IdentityService.Application.Contracts" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Infrastructure/Repositories/JournalRepository.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using Core.Entities;
using Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Infrastructure/Repositories/UserRepository.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using Core.Entities;
using Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Infrastructure/Services/JournalAnalyzer.cs

using Application.Interfaces;
using IdentityService.Application.Contracts;
using Microsoft.Extensions.Logging;

namespace Infrastructure.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Infrastructure/Services/JwtTokenGenerator.cs

using Application.Contracts;
using IdentityService.Application.Contracts;
using Core.Entities;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// مسیر: src/IdentityService/Infrastructure/Services/PasswordHasher.cs

using Application.Contracts;
using IdentityService.Application.Contracts;

namespace Infrastructure.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Configuration;
using Testcontainers.PostgreSql;
using Testcontainers.RabbitMq;
using Xunit;
Expand Down Expand Up @@ -50,7 +51,7 @@
{
// Replace connection strings
services.AddSingleton<IConfiguration>(new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>

Check warning on line 54 in src/IdentityService/Tests/IdentityService.IntegrationTests/Flows/RegistrationFlowTests.cs

View workflow job for this annotation

GitHub Actions / run-tests

Argument of type 'Dictionary<string, string>' cannot be used for parameter 'initialData' of type 'IEnumerable<KeyValuePair<string, string?>>' in 'IConfigurationBuilder MemoryConfigurationBuilderExtensions.AddInMemoryCollection(IConfigurationBuilder configurationBuilder, IEnumerable<KeyValuePair<string, string?>>? initialData)' due to differences in the nullability of reference types.
{
["ConnectionStrings:DefaultConnection"] = _fixture.DbContainer.GetConnectionString(),
["RabbitMq:HostName"] = _fixture.BrokerContainer.Hostname,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading