Skip to content

Commit

Permalink
Merge pull request #36 from a-sharifov/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
a-sharifov authored Feb 5, 2024
2 parents cfcc74d + 095c0e0 commit e9db298
Show file tree
Hide file tree
Showing 117 changed files with 799 additions and 385 deletions.
23 changes: 22 additions & 1 deletion Eshop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBus.MassTransit", "crs
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "crs\CommonComponents\Common\Common.csproj", "{2739BCFE-F0A1-41E4-87CD-66959E1BB75B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "crs\CommonComponents\Contracts\Contracts.csproj", "{A367D824-7EB8-4448-A7DC-27BF76576B01}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "crs\CommonComponents\Contracts\Contracts.csproj", "{A367D824-7EB8-4448-A7DC-27BF76576B01}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Identity.MessageBus", "crs\Services\Identity\Identity.MessageBus\Identity.MessageBus.csproj", "{9767E75F-8186-4BBE-A81A-E18B1F4687D8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Email.MessageBus", "crs\Services\Email\Email.MessageBus\Email.MessageBus.csproj", "{492C4BC4-B89A-4E5C-B9F0-FC7A03BFE1FB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Idenitty.Grpc", "crs\Services\Identity\Idenitty.Grpc\Idenitty.Grpc.csproj", "{1DEB0D00-7A0F-4F76-85CA-75E2DDA390B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -187,6 +193,18 @@ Global
{A367D824-7EB8-4448-A7DC-27BF76576B01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A367D824-7EB8-4448-A7DC-27BF76576B01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A367D824-7EB8-4448-A7DC-27BF76576B01}.Release|Any CPU.Build.0 = Release|Any CPU
{9767E75F-8186-4BBE-A81A-E18B1F4687D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9767E75F-8186-4BBE-A81A-E18B1F4687D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9767E75F-8186-4BBE-A81A-E18B1F4687D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9767E75F-8186-4BBE-A81A-E18B1F4687D8}.Release|Any CPU.Build.0 = Release|Any CPU
{492C4BC4-B89A-4E5C-B9F0-FC7A03BFE1FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{492C4BC4-B89A-4E5C-B9F0-FC7A03BFE1FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{492C4BC4-B89A-4E5C-B9F0-FC7A03BFE1FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{492C4BC4-B89A-4E5C-B9F0-FC7A03BFE1FB}.Release|Any CPU.Build.0 = Release|Any CPU
{1DEB0D00-7A0F-4F76-85CA-75E2DDA390B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DEB0D00-7A0F-4F76-85CA-75E2DDA390B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DEB0D00-7A0F-4F76-85CA-75E2DDA390B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DEB0D00-7A0F-4F76-85CA-75E2DDA390B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -227,6 +245,9 @@ Global
{8F295CAC-A3B2-41A8-BBFB-B0C5C79BBF91} = {A5847876-AA10-49ED-8C6A-D599FE7348E5}
{2739BCFE-F0A1-41E4-87CD-66959E1BB75B} = {18B99957-5BAF-4D5D-BC24-27EB1B42DB1B}
{A367D824-7EB8-4448-A7DC-27BF76576B01} = {18B99957-5BAF-4D5D-BC24-27EB1B42DB1B}
{9767E75F-8186-4BBE-A81A-E18B1F4687D8} = {1B13E7AE-01B6-4092-9DD0-1D53F6906791}
{492C4BC4-B89A-4E5C-B9F0-FC7A03BFE1FB} = {7CFB86E0-426D-4822-A84E-D2BC5987D187}
{1DEB0D00-7A0F-4F76-85CA-75E2DDA390B5} = {1B13E7AE-01B6-4092-9DD0-1D53F6906791}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {383EFC19-58A6-4418-98E0-23BD0341BA42}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Polly;

namespace Common.App.Extensions;

Expand All @@ -19,10 +20,13 @@ public static IApplicationBuilder MigrateDbContext<TDbContext>(this IApplication
{
using var scope = builder.ApplicationServices.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<TDbContext>();



dbContext.Database.Migrate();
Policy
.Handle<Exception>()
.WaitAndRetry(
retryCount: 3,
_ => TimeSpan.FromSeconds(15))
.Execute(dbContext.Database.Migrate);

return builder;
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion crs/CommonComponents/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly" Version="8.2.1" />
<PackageReference Include="Polly" Version="8.3.0" />
<PackageReference Include="prometheus-net" Version="8.2.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
Expand Down
31 changes: 21 additions & 10 deletions crs/CommonComponents/Common/Domain/Primitives/Enumeration.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
namespace Common.Domain.Primitives;

public abstract class Enumeration<TEnum>(
int value,
string name)

public abstract class Enumeration<TEnum>(int value, string name)
where TEnum : Enumeration<TEnum>
{
public readonly int Value = value;
public readonly string Name = name;
private static readonly Dictionary<int, TEnum> _enumerations = GetEnumerations();

private static readonly Dictionary<int, TEnum> _enumerations = GetEnumerations();

public static TEnum? FromValue(int value) =>
_enumerations.TryGetValue(value, out var enumeration)
_enumerations.TryGetValue(value, out var enumeration)
? enumeration : null;

public static TEnum? FromName(string name) =>
_enumerations.Values.SingleOrDefault(x => x.Name == name);
public static TEnum FromName(string name) =>
_enumerations.Values.Single(x => x.Name == name);

public static IEnumerable<string> GetNames() =>
_enumerations.Values.Select(x => x.Name);

public static bool NameExists(string name) =>
_enumerations.Values.Any(x => x.Name == name);

public static bool ValueExists(int value) =>
_enumerations.ContainsKey(value);

private static Dictionary<int, TEnum> GetEnumerations()
{
var enumerationType = typeof(TEnum);

var fields = enumerationType.GetFields(
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.DeclaredOnly)
.Where(fieldInfo => enumerationType.IsAssignableFrom(fieldInfo.FieldType))
.Select(fieldInfo => (TEnum)fieldInfo.GetValue(default)!);

return fields.ToDictionary(field => field.Value);
}

public static implicit operator int(Enumeration<TEnum> @enum) =>
@enum.Value;

public static implicit operator string(Enumeration<TEnum> @enum) =>
@enum.Name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// Interface for domain event.
/// if you need class. because class can't inherit from record.
/// </summary>
public interface IDomainEvent : INotification, IEvent
public interface IDomainEvent : INotification
{
/// <summary>
/// Gets the id of the event.
Expand Down
5 changes: 0 additions & 5 deletions crs/CommonComponents/Common/Events/IEvent.cs

This file was deleted.

1 change: 0 additions & 1 deletion crs/CommonComponents/Common/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
global using FluentValidation;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.Http;
global using Common.Events;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

option csharp_namespace = "Contracts.Abstractions";

package abstractions;


message NotFound {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//using Contracts.Enumurations;
//using Microsoft.AspNetCore.Authentication;
//using Microsoft.AspNetCore.Mvc;
//using Microsoft.AspNetCore.Mvc.Filters;

//namespace Contracts.Attributes;

//public class RoleBasedAuthorizeFilter(Role role) : IAuthorizationFilter
//{
// private readonly Role role = role;

// public void OnAuthorization(AuthorizationFilterContext context)
// {
// if (!context.HttpContext.User.Identity.IsAuthenticated)
// {
// context.Result = new ChallengeResult();
// return;
// }
// }
//}
29 changes: 24 additions & 5 deletions crs/CommonComponents/Contracts/Contracts.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\EventBus\EventBus.Common\EventBus.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Protobuf Include="Abstractions\Abstractions.proto" GrpcServices="Both" />
<Protobuf Include="Services\Identity\Identity.proto" GrpcServices="Both" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.25.2" />
<PackageReference Include="Grpc.Net.Client" Version="2.60.0" />
<PackageReference Include="Grpc.Tools" Version="2.61.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions crs/CommonComponents/Contracts/Enumurations/Gender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts.Enumurations;

public class Gender(int value, string name) : Enumeration<Gender>(value, name)
{
public static readonly Gender Male = new(0, nameof(Male));
public static readonly Gender Female = new(1, nameof(Female));
public static readonly Gender Undefined = new(2, nameof(Undefined));
}
8 changes: 8 additions & 0 deletions crs/CommonComponents/Contracts/Enumurations/Role.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Contracts.Enumurations;

public class Role(int value, string name)
: Enumeration<Role>(value, name)
{
public static readonly Role User = new(0, nameof(User));
public static readonly Role Admin = new(1, nameof(Admin));
}
2 changes: 2 additions & 0 deletions crs/CommonComponents/Contracts/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global using Common.Domain.Primitives;
global using EventBus.Common.Messages;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Contracts.Services.Identity.Commands;

public sealed record UserCreatedConfirmationEmailSendCommand(
Guid Id,
Guid UserId,
string ConfirmationEmailToken,
string ReturnUrl) : IntegrationCommand(Id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Contracts.Services.Identity.Events;

public sealed record IdentityVerificationConfirmedEvent(
Guid Id,
Guid UserId) : IntegrationEvent(Id);
34 changes: 34 additions & 0 deletions crs/CommonComponents/Contracts/Services/Identity/Identity.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";

option csharp_namespace = "Contracts.Services.Identity";

package identity;

service IdentityService {
rpc GetUser(GetUserRequest) returns (User);
}

message GetUserRequest {
string id = 1;
}

message User {
string user_id = 1;
string email = 2;
string first_name = 3;
string last_name = 4;
bool is_email_confirmed = 5;
Role role = 6;
Gender gender = 7;
}

enum Role {
USER = 0;
ADMIN = 1;
}

enum Gender {
MALE = 0;
FEMALE = 1;
UNDEFINED = 2;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EventBus.Common.Abstractions;

/// <summary>
/// The integration command interface.
/// </summary>
public interface IIntegrationCommand : IMessage
{
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
namespace EventBus.Common.Abstractions;

/// <summary>
/// Inteface for integration event.
/// The integration command interface.
/// </summary>
public interface IIntegrationEvent: IEvent
public interface IIntegrationEvent : IMessage
{
/// <summary>
/// The id event.
/// </summary>
Guid Id { get; }

/// <summary>
/// The creation date of the event.
/// </summary>
DateTime CreatedAt { get; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace EventBus.Common.Abstractions;

/// <summary>
/// The message interface.
/// </summary>
public interface IMessage
{
/// <summary>
/// The id message.
/// </summary>
Guid Id { get; }

/// <summary>
/// The creation date of the message.
/// </summary>
DateTime CreatedAt { get; }
}
Loading

0 comments on commit e9db298

Please sign in to comment.