- ServiceRepository: IServiceRepository 구현 (GetByServiceCode, GetByApiKey) - ServiceCodeMiddleware: X-Service-Code 헤더 검증, DB 조회, 서비스 상태 확인 - ApiKeyMiddleware: /v1/in/device/* 경로 X-API-KEY 검증 - ApplicationBuilderExtensions: 미들웨어 파이프라인 12~13번 등록 - DependencyInjection: IServiceRepository DI 등록 Closes #32
26 lines
949 B
C#
26 lines
949 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using SPMS.Domain.Entities;
|
|
using SPMS.Domain.Enums;
|
|
using SPMS.Domain.Interfaces;
|
|
|
|
namespace SPMS.Infrastructure.Persistence.Repositories;
|
|
|
|
public class ServiceRepository : Repository<Service>, IServiceRepository
|
|
{
|
|
public ServiceRepository(AppDbContext context) : base(context) { }
|
|
|
|
public async Task<Service?> GetByServiceCodeAsync(string serviceCode)
|
|
=> await _dbSet.FirstOrDefaultAsync(s => s.ServiceCode == serviceCode);
|
|
|
|
public async Task<Service?> GetByApiKeyAsync(string apiKey)
|
|
=> await _dbSet.FirstOrDefaultAsync(s => s.ApiKey == apiKey);
|
|
|
|
public async Task<Service?> GetByIdWithIpsAsync(long id)
|
|
=> await _dbSet
|
|
.Include(s => s.ServiceIps)
|
|
.FirstOrDefaultAsync(s => s.Id == id);
|
|
|
|
public async Task<IReadOnlyList<Service>> GetByStatusAsync(ServiceStatus status)
|
|
=> await _dbSet.Where(s => s.Status == status).ToListAsync();
|
|
}
|