- POST /v1/in/account/operator/create (계정 생성 + 비밀번호 설정 이메일) - POST /v1/in/account/operator/delete (Soft Delete, 자기 자신 삭제 방지) - POST /v1/in/account/operator/list (페이징 + role/is_active 필터) - POST /v1/in/account/operator/password/reset (비밀번호 초기화 + 세션 무효화) Closes #134
81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SPMS.Domain.Entities;
|
|
using SPMS.Domain.Enums;
|
|
using SPMS.Domain.Interfaces;
|
|
|
|
namespace SPMS.Infrastructure.Persistence.Repositories;
|
|
|
|
public class AdminRepository : Repository<Admin>, IAdminRepository
|
|
{
|
|
public AdminRepository(AppDbContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public async Task<Admin?> GetByEmailAsync(string email)
|
|
{
|
|
return await _dbSet
|
|
.FirstOrDefaultAsync(a => a.Email == email && !a.IsDeleted);
|
|
}
|
|
|
|
public async Task<Admin?> GetByAdminCodeAsync(string adminCode)
|
|
{
|
|
return await _dbSet
|
|
.FirstOrDefaultAsync(a => a.AdminCode == adminCode && !a.IsDeleted);
|
|
}
|
|
|
|
public async Task<Admin?> GetByRefreshTokenAsync(string refreshToken)
|
|
{
|
|
return await _dbSet
|
|
.FirstOrDefaultAsync(a => a.RefreshToken == refreshToken && !a.IsDeleted);
|
|
}
|
|
|
|
public async Task<bool> EmailExistsAsync(string email, long? excludeId = null)
|
|
{
|
|
var query = _dbSet.Where(a => a.Email == email && !a.IsDeleted);
|
|
|
|
if (excludeId.HasValue)
|
|
query = query.Where(a => a.Id != excludeId.Value);
|
|
|
|
return await query.AnyAsync();
|
|
}
|
|
|
|
public async Task<(IReadOnlyList<Admin> Items, int TotalCount)> GetOperatorPagedAsync(
|
|
int page, int size, AdminRole? roleFilter, bool? isActive)
|
|
{
|
|
IQueryable<Admin> query;
|
|
|
|
if (isActive.HasValue)
|
|
{
|
|
// IgnoreQueryFilters로 삭제된 운영자도 조회 가능
|
|
query = _context.Set<Admin>().IgnoreQueryFilters();
|
|
|
|
if (isActive.Value)
|
|
query = query.Where(a => !a.IsDeleted);
|
|
else
|
|
query = query.Where(a => a.IsDeleted);
|
|
}
|
|
else
|
|
{
|
|
// 기본: 글로벌 필터 적용 (활성 운영자만)
|
|
query = _dbSet.AsQueryable();
|
|
}
|
|
|
|
// Super Admin 제외
|
|
query = query.Where(a => a.Role != AdminRole.Super);
|
|
|
|
// Role 필터
|
|
if (roleFilter.HasValue)
|
|
query = query.Where(a => a.Role == roleFilter.Value);
|
|
|
|
var totalCount = await query.CountAsync();
|
|
|
|
var items = await query
|
|
.OrderByDescending(a => a.CreatedAt)
|
|
.Skip((page - 1) * size)
|
|
.Take(size)
|
|
.ToListAsync();
|
|
|
|
return (items, totalCount);
|
|
}
|
|
}
|