From 0f6b2fec88bb311b9ef5d4d6390c760b62901910 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 2 Feb 2025 01:06:36 +0100 Subject: [PATCH] DBContext & repository --- .../AuthorityContext.cs | 9 +++ DotBased.AspNet.Authority.EFCore/DI.cs | 6 ++ .../DotBased.AspNet.Authority.EFCore.csproj | 1 + .../Repositories/UserRepository.cs | 58 +++++++++++++++++++ .../Repositories/IUserRepository.cs | 2 +- .../Validators/UserValidator.cs | 2 +- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 DotBased.AspNet.Authority.EFCore/Repositories/UserRepository.cs diff --git a/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs b/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs index fc470a6..5463940 100644 --- a/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs +++ b/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs @@ -9,4 +9,13 @@ public class AuthorityContext : DbContext public DbSet Groups { get; set; } public DbSet Roles { get; set; } public DbSet Users { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().ToTable("authority_attributes"); + modelBuilder.Entity().ToTable("authority_groups"); + modelBuilder.Entity().ToTable("authority_roles"); + modelBuilder.Entity().ToTable("authority_users"); + base.OnModelCreating(modelBuilder); + } } \ No newline at end of file diff --git a/DotBased.AspNet.Authority.EFCore/DI.cs b/DotBased.AspNet.Authority.EFCore/DI.cs index f5baba7..999df24 100644 --- a/DotBased.AspNet.Authority.EFCore/DI.cs +++ b/DotBased.AspNet.Authority.EFCore/DI.cs @@ -1,3 +1,5 @@ +using DotBased.AspNet.Authority.EFCore.Repositories; +using DotBased.AspNet.Authority.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -8,6 +10,10 @@ public static class DI public static IServiceCollection AddAuthorityContext(this IServiceCollection services, Action options) { services.AddDbContextFactory(options); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); return services; } } \ No newline at end of file diff --git a/DotBased.AspNet.Authority.EFCore/DotBased.AspNet.Authority.EFCore.csproj b/DotBased.AspNet.Authority.EFCore/DotBased.AspNet.Authority.EFCore.csproj index 56e1802..64df6fe 100644 --- a/DotBased.AspNet.Authority.EFCore/DotBased.AspNet.Authority.EFCore.csproj +++ b/DotBased.AspNet.Authority.EFCore/DotBased.AspNet.Authority.EFCore.csproj @@ -12,6 +12,7 @@ + diff --git a/DotBased.AspNet.Authority.EFCore/Repositories/UserRepository.cs b/DotBased.AspNet.Authority.EFCore/Repositories/UserRepository.cs new file mode 100644 index 0000000..9e1542f --- /dev/null +++ b/DotBased.AspNet.Authority.EFCore/Repositories/UserRepository.cs @@ -0,0 +1,58 @@ +using DotBased.AspNet.Authority.Models.Authority; +using DotBased.AspNet.Authority.Repositories; + +namespace DotBased.AspNet.Authority.EFCore.Repositories; + +public class UserRepository : IUserRepository +{ + public Task> GetAuthorityUsersAsync(int limit = 20, int offset = 0, string search = "", + CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task> GetAuthorityUserByIdAsync(string id, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task> CreateUserAsync(AuthorityUser user, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task> UpdateUserAsync(AuthorityUser user, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task DeleteUserAsync(AuthorityUser user, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task> GetUserByEmailAsync(string email, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task SetVersionAsync(AuthorityUser user, long version, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task> GetVersionAsync(AuthorityUser user, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task SetSecurityVersionAsync(AuthorityUser user, long version, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } + + public Task> GetSecurityVersionAsync(AuthorityUser user, CancellationToken? cancellationToken = null) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Repositories/IUserRepository.cs b/DotBased.AspNet.Authority/Repositories/IUserRepository.cs index ca15430..c84448a 100755 --- a/DotBased.AspNet.Authority/Repositories/IUserRepository.cs +++ b/DotBased.AspNet.Authority/Repositories/IUserRepository.cs @@ -9,7 +9,7 @@ public interface IUserRepository public Task> CreateUserAsync(AuthorityUser user, CancellationToken? cancellationToken = null); public Task> UpdateUserAsync(AuthorityUser user, CancellationToken? cancellationToken = null); public Task DeleteUserAsync(AuthorityUser user, CancellationToken? cancellationToken = null); - public Task> GetAuthorityUserByEmailAsync(string email, CancellationToken? cancellationToken = null); + public Task> GetUserByEmailAsync(string email, CancellationToken? cancellationToken = null); public Task SetVersionAsync(AuthorityUser user, long version, CancellationToken? cancellationToken = null); public Task> GetVersionAsync(AuthorityUser user, CancellationToken? cancellationToken = null); public Task SetSecurityVersionAsync(AuthorityUser user, long version, CancellationToken? cancellationToken = null); diff --git a/DotBased.AspNet.Authority/Validators/UserValidator.cs b/DotBased.AspNet.Authority/Validators/UserValidator.cs index 1b914bc..cb60dce 100755 --- a/DotBased.AspNet.Authority/Validators/UserValidator.cs +++ b/DotBased.AspNet.Authority/Validators/UserValidator.cs @@ -25,7 +25,7 @@ public class UserValidator : IUserValidator } else { - var userEmailResult = await manager.UserRepository.GetAuthorityUserByEmailAsync(user.EmailAddress); + var userEmailResult = await manager.UserRepository.GetUserByEmailAsync(user.EmailAddress); if (userEmailResult != null) { errors.Add(new ValidationError(ValidatorId, $"{ValidationBase}.EmailExists",