Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Modular architecture #47

Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/dotnet-format-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Install Android
run: dotnet workload install android
- name: Run dotnet format
Expand All @@ -25,7 +27,9 @@ jobs:
workspace: "./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln"
- name: Test
run: |
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln -f net6.0
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln -f net7.0
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln -f net8.0
- name: Commit files
if: steps.format.outputs.has-changes == 'true'
uses: EndBug/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dotnet-linux-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Client.sln
- name: Build
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/dotnet-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln
- name: Build
run: dotnet build ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-restore
- name: Test
run: |
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-build --verbosity normal -f net6.0
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-build --verbosity normal -f net7.0
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-build --verbosity normal -f net8.0
2 changes: 2 additions & 0 deletions .github/workflows/dotnet-macos-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Client.sln
- name: Build
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/dotnet-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln
- name: Build
run: dotnet build ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-restore
- name: Test
run: |
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-build --verbosity normal -f net6.0
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-build --verbosity normal -f net7.0
dotnet test ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln --no-build --verbosity normal -f net8.0
1 change: 1 addition & 0 deletions .github/workflows/dotnet-windows-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Client.sln
- name: Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dotnet-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore ./src/CSharp/EasyMicroservices.AuthenticationsMicroservice.sln
- name: Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/nuget-push-public-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ jobs:
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
env:
DOTNET_INSTALL_DIR: /usr/share/dotnet
- name: Restore dependencies
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/nuget-push-public.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ jobs:
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
env:
DOTNET_INSTALL_DIR: /usr/share/dotnet
- name: Restore dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using EasyMicroservices.AuthenticationsMicroservice.Database.Entities;
using EasyMicroservices.AuthenticationsMicroservice.SeedData;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Builders;
using Microsoft.EntityFrameworkCore;

namespace EasyMicroservices.AuthenticationsMicroservice.Database.Builders;

public class AuthenticationDatabaseBuilder
{
public void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserEntity>(model =>
{
model.HasIndex(u => new { u.BusinessUniqueIdentity, u.UserName })
.IsUnique();
model.ToTable("Users");
});

modelBuilder.Entity<RoleServicePermissionEntity>(model =>
{
model.HasKey(u => new { u.RoleId, u.ServicePermissionId });
model.ToTable("RoleServicePermissions");
});

modelBuilder.Entity<UserRoleEntity>(model =>
{
model.HasKey(u => new { u.RoleId, u.UserId });
model.ToTable("UserRoles");
});

modelBuilder.Entity<ServicePermissionEntity>(model =>
{
model.HasIndex(u => u.MicroserviceName);
model.HasIndex(u => u.ServiceName);
model.HasIndex(u => u.MethodName);
model.HasIndex(u => new { u.MicroserviceName, u.ServiceName, u.MethodName }).IsUnique();
model.ToTable("ServicePermissions");
});

modelBuilder.Entity<RoleParentChildEntity>(model =>
{
model.HasKey(u => new { u.ParentId, u.ChildId });

model.HasOne(u => u.Parent)
.WithMany(u => u.Parents)
.HasForeignKey(u => u.ParentId)
.OnDelete(DeleteBehavior.Restrict);

model.HasOne(u => u.Child)
.WithMany(u => u.Children)
.HasForeignKey(u => u.ChildId)
.OnDelete(DeleteBehavior.Restrict);
model.ToTable("RoleParentChildren");
});

modelBuilder.Entity<RoleEntity>(model =>
{
model.ToTable("Roles");
});

modelBuilder.Entity<PersonalAccessTokenEntity>(model =>
{
model.ToTable("PersonalAccessTokens");
});

modelBuilder.Entity<RegisterUserDefaultRoleEntity>(model =>
{
model.ToTable("RegisterUserDefaultRoles");
});

var result = new RelationalCoreModelBuilder().AutoModelCreating(modelBuilder);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EasyMicroservices.AuthenticationsMicroservice.Database.Entities;
using EasyMicroservices.AuthenticationsMicroservice.Database.Builders;
using EasyMicroservices.AuthenticationsMicroservice.Database.Entities;
using EasyMicroservices.AuthenticationsMicroservice.SeedData;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
Expand All @@ -23,47 +24,9 @@ public AuthenticationsContext(IEntityFrameworkCoreDatabaseBuilder builder) : bas

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserEntity>(model =>
{
model.HasIndex(u => new { u.BusinessUniqueIdentity, u.UserName })
.IsUnique();
});

modelBuilder.Entity<RoleServicePermissionEntity>(model =>
{
model.HasKey(u => new { u.RoleId, u.ServicePermissionId });
});

modelBuilder.Entity<UserRoleEntity>(model =>
{
model.HasKey(u => new { u.RoleId, u.UserId });
});

modelBuilder.Entity<ServicePermissionEntity>(model =>
{
model.HasIndex(u => u.MicroserviceName);
model.HasIndex(u => u.ServiceName);
model.HasIndex(u => u.MethodName);
model.HasIndex(u => new { u.MicroserviceName, u.ServiceName, u.MethodName }).IsUnique();
});

modelBuilder.Entity<RoleParentChildEntity>(model =>
{
model.HasKey(u => new { u.ParentId, u.ChildId });

model.HasOne(u => u.Parent)
.WithMany(u => u.Parents)
.HasForeignKey(u => u.ParentId)
.OnDelete(DeleteBehavior.Restrict);

model.HasOne(u => u.Child)
.WithMany(u => u.Children)
.HasForeignKey(u => u.ChildId)
.OnDelete(DeleteBehavior.Restrict);
});

new AuthenticationDatabaseBuilder().OnModelCreating(modelBuilder);
var result = base.AutoModelCreating(modelBuilder);
AllSeedData.Seed(modelBuilder);
AuthenticationsSeedData.Seed(modelBuilder);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.1</Version>
<Description>Authentications Microservice</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>module,database,services,asp,aspnet,auth,authentication,authentications</PackageTags>
<PackageProjectUrl>https://github.com/EasyMicroservices/Cores</PackageProjectUrl>
<LangVersion>latest</LangVersion>
<RootNamespace>EasyMicroservices.AuthenticationsMicroservice</RootNamespace>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace EasyMicroservices.AuthenticationsMicroservice.SeedData
{
public static class AllSeedData
public static class AuthenticationsSeedData
{
public static void Seed(ModelBuilder modelBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.1</Version>
<Description>Authentications Microservice</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>module,domain,services,asp,aspnet,auth,authentication,authentications</PackageTags>
<PackageProjectUrl>https://github.com/EasyMicroservices/Cores</PackageProjectUrl>
<LangVersion>latest</LangVersion>
<RootNamespace>EasyMicroservices.AuthenticationsMicroservice</RootNamespace>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<Folder Include="Contracts\Requests\Filters\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.91" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.95" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.1</Version>
<Description>Authentications Microservice</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>module,logics,asp,aspnet,auth,authentication,authentications</PackageTags>
<PackageProjectUrl>https://github.com/EasyMicroservices/Cores</PackageProjectUrl>
<LangVersion>latest</LangVersion>
<RootNamespace>EasyMicroservices.AuthenticationsMicroservice</RootNamespace>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using EasyMicroservices.AuthenticationsMicroservice.Contracts.Requests;
using EasyMicroservices.AuthenticationsMicroservice.Database.Entities;
using EasyMicroservices.Cores.AspCoreApi;
using EasyMicroservices.Cores.Contracts.Requests;
using EasyMicroservices.Cores.Interfaces;
using EasyMicroservices.ServiceContracts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading.Tasks;

namespace EasyMicroservices.AuthenticationsMicroservice.WebApi.Controllers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace EasyMicroservices.AuthenticationsMicroservice.WebApi.Controllers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace EasyMicroservices.AuthenticationsMicroservice.WebApi.Controllers
{
Expand All @@ -33,7 +36,8 @@ public override async Task<MessageContract<long>> Add(AddUserRequestContract req
var roles = await UnitOfWork.GetLogic<UserRoleEntity>().AddBulk(defaultRoles.Select(x => new UserRoleEntity()
{
RoleId = x.RoleId,
UserId = userId
UserId = userId,
UniqueIdentity = request.UniqueIdentity
}).ToList()).AsCheckedResult();
}
return userId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.0.1</Version>
<Description>Authentications Microservice</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>module,services,asp,aspnet,auth,authentication,authentications</PackageTags>
<PackageProjectUrl>https://github.com/EasyMicroservices/Cores</PackageProjectUrl>
<LangVersion>latest</LangVersion>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.AuthenticationsMicroservice.Logics\EasyMicroservices.AuthenticationsMicroservice.Logics.csproj" />
</ItemGroup>

</Project>
Loading
Loading