## 주요 변경사항 ### 🏗️ Architecture - Repository 패턴 전면 도입 (인터페이스/구현체 분리) - Domain Layer에 Repository 인터페이스 정의 - Data Layer에 Repository 구현체 배치 - UseCase 의존성을 Service에서 Repository로 전환 ### 📦 Dependency Injection - GetIt 기반 DI Container 재구성 (lib/injection_container.dart) - Repository 인터페이스와 구현체 등록 - Service와 Repository 공존 (마이그레이션 기간) ### 🔄 Migration Status 완료: - License 모듈 (6개 UseCase) - Warehouse Location 모듈 (5개 UseCase) 진행중: - Auth 모듈 (2/5 UseCase) - Company 모듈 (1/6 UseCase) 대기: - User 모듈 (7개 UseCase) - Equipment 모듈 (4개 UseCase) ### 🎯 Controller 통합 - 중복 Controller 제거 (with_usecase 버전) - 단일 Controller로 통합 - UseCase 패턴 직접 적용 ### 🧹 코드 정리 - 임시 파일 제거 (test_*.md, task.md) - Node.js 아티팩트 제거 (package.json) - 불필요한 테스트 파일 정리 ### ✅ 테스트 개선 - Real API 중심 테스트 구조 - Mock 제거, 실제 API 엔드포인트 사용 - 통합 테스트 프레임워크 강화 ## 기술적 영향 - 의존성 역전 원칙 적용 - 레이어 간 결합도 감소 - 테스트 용이성 향상 - 확장성 및 유지보수성 개선 ## 다음 단계 1. User/Equipment 모듈 Repository 마이그레이션 2. Service Layer 점진적 제거 3. 캐싱 전략 구현 4. 성능 최적화
112 lines
3.7 KiB
Dart
112 lines
3.7 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
import '../../../data/models/license/license_dto.dart';
|
|
import '../../repositories/license_repository.dart';
|
|
import '../../../core/errors/failures.dart';
|
|
import '../base_usecase.dart';
|
|
|
|
/// 라이선스 만료일 체크 UseCase
|
|
@injectable
|
|
class CheckLicenseExpiryUseCase implements UseCase<LicenseExpiryResult, CheckLicenseExpiryParams> {
|
|
final LicenseRepository repository;
|
|
|
|
CheckLicenseExpiryUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, LicenseExpiryResult>> call(CheckLicenseExpiryParams params) async {
|
|
try {
|
|
// 모든 라이선스 조회
|
|
final allLicensesResult = await repository.getLicenses(
|
|
page: 1,
|
|
limit: 10000, // 모든 라이선스 조회
|
|
);
|
|
|
|
return allLicensesResult.fold(
|
|
(failure) => Left(failure),
|
|
(paginatedResponse) {
|
|
final now = DateTime.now();
|
|
final expiring30Days = <LicenseDto>[];
|
|
final expiring60Days = <LicenseDto>[];
|
|
final expiring90Days = <LicenseDto>[];
|
|
final expired = <LicenseDto>[];
|
|
|
|
for (final license in paginatedResponse.items) {
|
|
final licenseDto = LicenseDto(
|
|
id: license.id ?? 0,
|
|
licenseKey: license.licenseKey,
|
|
productName: license.productName,
|
|
vendor: license.vendor,
|
|
licenseType: license.licenseType,
|
|
userCount: license.userCount,
|
|
purchaseDate: license.purchaseDate,
|
|
expiryDate: license.expiryDate,
|
|
purchasePrice: license.purchasePrice,
|
|
companyId: license.companyId,
|
|
branchId: license.branchId,
|
|
assignedUserId: license.assignedUserId,
|
|
remark: license.remark,
|
|
isActive: license.isActive ?? true,
|
|
createdAt: license.createdAt ?? DateTime.now(),
|
|
updatedAt: license.updatedAt ?? DateTime.now(),
|
|
companyName: license.companyName,
|
|
branchName: license.branchName,
|
|
assignedUserName: license.assignedUserName,
|
|
);
|
|
|
|
if (licenseDto.expiryDate == null) continue;
|
|
|
|
final daysUntilExpiry = licenseDto.expiryDate!.difference(now).inDays;
|
|
|
|
if (daysUntilExpiry < 0) {
|
|
expired.add(licenseDto);
|
|
} else if (daysUntilExpiry <= 30) {
|
|
expiring30Days.add(licenseDto);
|
|
} else if (daysUntilExpiry <= 60) {
|
|
expiring60Days.add(licenseDto);
|
|
} else if (daysUntilExpiry <= 90) {
|
|
expiring90Days.add(licenseDto);
|
|
}
|
|
}
|
|
|
|
return Right(LicenseExpiryResult(
|
|
expiring30Days: expiring30Days,
|
|
expiring60Days: expiring60Days,
|
|
expiring90Days: expiring90Days,
|
|
expired: expired,
|
|
));
|
|
},
|
|
);
|
|
} catch (e) {
|
|
return Left(ServerFailure(message: e.toString()));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 라이선스 만료일 체크 파라미터
|
|
class CheckLicenseExpiryParams {
|
|
final int? companyId;
|
|
final String? equipmentType;
|
|
|
|
CheckLicenseExpiryParams({
|
|
this.companyId,
|
|
this.equipmentType,
|
|
});
|
|
}
|
|
|
|
/// 라이선스 만료일 체크 결과
|
|
class LicenseExpiryResult {
|
|
final List<LicenseDto> expiring30Days;
|
|
final List<LicenseDto> expiring60Days;
|
|
final List<LicenseDto> expiring90Days;
|
|
final List<LicenseDto> expired;
|
|
|
|
LicenseExpiryResult({
|
|
required this.expiring30Days,
|
|
required this.expiring60Days,
|
|
required this.expiring90Days,
|
|
required this.expired,
|
|
});
|
|
|
|
int get totalExpiring => expiring30Days.length + expiring60Days.length + expiring90Days.length;
|
|
int get totalExpired => expired.length;
|
|
} |