[성현모] AccountDB Core로 이동

This commit is contained in:
SHM
2025-07-24 16:54:43 +09:00
parent c6fc5328df
commit bb9ed413a7
20 changed files with 151 additions and 173 deletions

View File

@ -20,7 +20,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebApi.Library.DBContext\WebApi.Library.DBContext.csproj" />
<ProjectReference Include="..\WebApi.Library\WebApi.Library.csproj" />
</ItemGroup>
@ -28,6 +27,9 @@
<Reference Include="SystemX.Core">
<HintPath>..\..\DLL\SystemX.Core.dll</HintPath>
</Reference>
<Reference Include="SystemX.Core.DB">
<HintPath>..\..\DLL\SystemX.Core.DB.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@ -1,5 +1,4 @@
using AuthApi.Services;
using Azure.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;

View File

@ -1,14 +1,9 @@
using AuthApi.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.IdentityModel.Tokens;
using System;
using System.ComponentModel;
using System.Text;
using SystemX.Core.Services;
using WebApi.Library.Config;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Context;
string configDir = @"../../Config";
string configFileName = "WebApi.AuthApi.Config.json";

View File

@ -2,12 +2,9 @@
using SystemX.Core.Services;
using SystemX.Core;
using WebApi.Library.Config;
using SystemX.Core.Config.Model;
using System.Data;
using SystemX.Core.DB;
using Microsoft.EntityFrameworkCore;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Context;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Tables;
namespace AuthApi.Services
{
@ -45,25 +42,25 @@ namespace AuthApi.Services
{
if (context is not null)
{
var user = await context.TUsers.AsNoTracking().Where(x => x.CUserId.ToLower() == registerModel.UserID.ToLower()).ToListAsync();
var user = await context.tUsers.AsNoTracking().Where(x => x.cUserID.ToLower() == registerModel.UserID.ToLower()).ToListAsync();
if (user?.Count <= 0)
{
string auid = Guid.NewGuid().ToString();
//user
TUser newUser = new TUser
tUser newUser = new tUser
{
CAuid = auid,
CUserId = registerModel.UserID,
CPasswordHashed = registerModel.Password,
CCreateDateTime = DateTime.Now,
CLastLoginDateTime = new DateTime()
cAuid = auid,
cUserID = registerModel.UserID,
cPasswordHashed = registerModel.Password,
cCreateDateTime = DateTime.Now,
cLastLoginDateTime = new DateTime()
};
//role
TRole newUserRole = new TRole
tRole newUserRole = new tRole
{
CAuid = auid,
CRoleId = Convert.ToByte(registerModel.Role),
CRoleName = registerModel.Role.ToString()
cAuid = auid,
cRoleID = Convert.ToByte(registerModel.Role),
cRoleName = registerModel.Role.ToString()
};
using (var transaction = await context.CreateTransactionAsync())
@ -119,29 +116,29 @@ namespace AuthApi.Services
using (var transaction = await context.CreateTransactionAsync(IsolationLevel.ReadUncommitted))
{
//select user
var selectUser = await context.TUsers.AsNoTracking().FirstOrDefaultAsync(x => x.CUserId.ToLower() == loginModel!.UserID!.ToLower());
var selectUser = await context.tUsers.AsNoTracking().FirstOrDefaultAsync(x => x.cUserID.ToLower() == loginModel!.UserID!.ToLower());
if (selectUser is not null)
{
if (selectUser.CPasswordHashed == loginModel?.Password)
if (selectUser.cPasswordHashed == loginModel?.Password)
{
//select role
var selectRole = await context.TRoles.FindAsync(selectUser.CAuid);
var selectRole = await context.tRoles.FindAsync(selectUser.cAuid);
if (selectRole != null)
{
response.Role = (UserRole)Enum.Parse(typeof(UserRole), selectRole.CRoleId.ToString());
response.RoleName = selectRole.CRoleName;
response.Role = (UserRole)Enum.Parse(typeof(UserRole), selectRole.cRoleID.ToString());
response.RoleName = selectRole.cRoleName;
}
Session.Add(response);
if (selectUser.CState == (byte)UserState.Active)
if (selectUser.cState == (byte)UserState.Active)
{
response.EC = ERROR_CODE.EC_OK;
}
else if (selectUser.CState == (byte)UserState.Inactive)
else if (selectUser.cState == (byte)UserState.Inactive)
{
response.EC = ERROR_CODE.EC_USER_LOGIN_INAVTIVE;
}
else if (selectUser.CState == (byte)UserState.Block)
else if (selectUser.cState == (byte)UserState.Block)
{
response.EC = ERROR_CODE.EC_USER_LOGIN_BLOCKED;
}
@ -185,7 +182,7 @@ namespace AuthApi.Services
{
if (context is not null)
{
var selectUser = await context.TUsers.AsNoTracking().FirstOrDefaultAsync(x => x.CUserId.ToLower() == loginModel!.UserID!.ToLower());
var selectUser = await context.tUsers.AsNoTracking().FirstOrDefaultAsync(x => x.cUserID.ToLower() == loginModel!.UserID!.ToLower());
if (selectUser is not null)
{
using (var transaction = await context.CreateTransactionAsync())
@ -193,24 +190,24 @@ namespace AuthApi.Services
try
{
//user info
selectUser.CLastLoginDateTime = DateTime.Now;
selectUser.cLastLoginDateTime = DateTime.Now;
context.Update(selectUser);
//refresh token
var findRefreshToken = await context.TRefreshTokens.AsNoTracking().FirstOrDefaultAsync(x => x.CAuid == selectUser.CAuid);
var findRefreshToken = await context.tRefreshTokens.AsNoTracking().FirstOrDefaultAsync(x => x.cAuid == selectUser.cAuid);
//null이면(없으면) add
if (findRefreshToken == null)
{
await context.AddAsync(new TRefreshToken
await context.AddAsync(new tRefreshToken
{
CAuid = selectUser.CAuid,
CRefreshToken = $"{RefreshToken}"
cAuid = selectUser.cAuid,
cRefreshToken= $"{RefreshToken}"
});
}
//있으면 update
else
{
findRefreshToken.CRefreshToken = $"{RefreshToken}";
findRefreshToken.cRefreshToken = $"{RefreshToken}";
context.Update(findRefreshToken);
}
@ -264,10 +261,10 @@ namespace AuthApi.Services
return response;
}
private AccountDbContext? GetAccountDBContext(DbContextProvider provider, int dbID)
private AccountDBContext? GetAccountDBContext(DbContextProvider provider, int dbID)
{
var connectionString = _configService?.GetConfig()?.DataBase?.Find(x => x.DBID == dbID);
return provider?.GetDBContext<AccountDbContext>($"{connectionString?.DBName}");
return provider?.GetDBContext<AccountDBContext>($"{connectionString?.DBName}");
}
}
}

View File

@ -1,80 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using WebApi.Library.DBContext.DB.DBContext.AccountDB.Tables;
namespace WebApi.Library.DBContext.DB.DBContext.AccountDB.Context;
public partial class AccountDbContext : DbContext
{
public AccountDbContext()
{
}
public AccountDbContext(DbContextOptions<AccountDbContext> options)
: base(options)
{
}
public virtual DbSet<TRefreshToken> TRefreshTokens { get; set; }
public virtual DbSet<TRole> TRoles { get; set; }
public virtual DbSet<TUser> TUsers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TRefreshToken>(entity =>
{
entity.HasKey(e => e.CAuid).HasName("PK__tRefresh__FBF0855465EB95AB");
entity.ToTable("tRefreshToken");
entity.Property(e => e.CAuid)
.HasMaxLength(250)
.HasColumnName("cAuid");
entity.Property(e => e.CRefreshToken)
.HasMaxLength(1000)
.HasColumnName("cRefreshToken");
});
modelBuilder.Entity<TRole>(entity =>
{
entity.HasKey(e => e.CAuid).HasName("PK__tRole__FBF085540BB887D7");
entity.ToTable("tRole");
entity.Property(e => e.CAuid)
.HasMaxLength(250)
.HasColumnName("cAuid");
entity.Property(e => e.CRoleId).HasColumnName("cRoleID");
entity.Property(e => e.CRoleName)
.HasMaxLength(20)
.HasColumnName("cRoleName");
});
modelBuilder.Entity<TUser>(entity =>
{
entity.HasKey(e => e.CUserId).HasName("PK__tUser__A75DC19A721265FF");
entity.ToTable("tUser");
entity.Property(e => e.CUserId)
.HasMaxLength(50)
.HasColumnName("cUserID");
entity.Property(e => e.CAuid)
.HasMaxLength(250)
.HasColumnName("cAuid");
entity.Property(e => e.CCreateDateTime).HasColumnName("cCreateDateTime");
entity.Property(e => e.CLastLoginDateTime).HasColumnName("cLastLoginDateTime");
entity.Property(e => e.CPasswordHashed)
.HasMaxLength(250)
.HasColumnName("cPasswordHashed");
entity.Property(e => e.CState).HasColumnName("cState");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
namespace WebApi.Library.DBContext.DB.DBContext.AccountDB.Tables;
public partial class TRefreshToken
{
public string CAuid { get; set; } = null!;
public string CRefreshToken { get; set; } = null!;
}

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
namespace WebApi.Library.DBContext.DB.DBContext.AccountDB.Tables;
public partial class TRole
{
public string CAuid { get; set; } = null!;
public byte CRoleId { get; set; }
public string CRoleName { get; set; } = null!;
}

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
namespace WebApi.Library.DBContext.DB.DBContext.AccountDB.Tables;
public partial class TUser
{
public string CUserId { get; set; } = null!;
public string CAuid { get; set; } = null!;
public string CPasswordHashed { get; set; } = null!;
public byte CState { get; set; }
public DateTime CCreateDateTime { get; set; }
public DateTime? CLastLoginDateTime { get; set; }
}

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -14,6 +14,11 @@
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
</ItemGroup>
<ItemGroup>
<Reference Include="SystemX.Core">
<HintPath>..\..\DLL\SystemX.Core.dll</HintPath>

View File

@ -7,8 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthApi", "AuthApi\AuthApi.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi.Library", "WebApi.Library\WebApi.Library.csproj", "{1B109CFE-B860-4125-8F2B-06D95DE85E91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi.Library.DBContext", "WebApi.Library.DBContext\WebApi.Library.DBContext.csproj", "{92599205-8D5B-4630-B669-AA390193BC9E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{C8D5274F-AC00-46C7-1F8D-E88E81087A52}"
ProjectSection(SolutionItems) = preProject
..\Config\WebApi.AuthApi.Config.json = ..\Config\WebApi.AuthApi.Config.json
@ -28,10 +26,6 @@ Global
{1B109CFE-B860-4125-8F2B-06D95DE85E91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B109CFE-B860-4125-8F2B-06D95DE85E91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B109CFE-B860-4125-8F2B-06D95DE85E91}.Release|Any CPU.Build.0 = Release|Any CPU
{92599205-8D5B-4630-B669-AA390193BC9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92599205-8D5B-4630-B669-AA390193BC9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92599205-8D5B-4630-B669-AA390193BC9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92599205-8D5B-4630-B669-AA390193BC9E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE