refactor: Repository 패턴 적용 및 Clean Architecture 완성
## 주요 변경사항 ### 🏗️ 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. 성능 최적화
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/license/license_dto.dart';
|
||||
import '../../../data/repositories/license_repository.dart';
|
||||
import '../../../models/license_model.dart';
|
||||
import '../../repositories/license_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -16,20 +17,57 @@ class UpdateLicenseUseCase implements UseCase<LicenseDto, UpdateLicenseParams> {
|
||||
Future<Either<Failure, LicenseDto>> call(UpdateLicenseParams params) async {
|
||||
try {
|
||||
// 비즈니스 로직: 만료일 검증
|
||||
if (params.expiryDate != null && params.startDate != null) {
|
||||
if (params.expiryDate!.isBefore(params.startDate!)) {
|
||||
return Left(ValidationFailure(message: '만료일은 시작일 이후여야 합니다'));
|
||||
if (params.expiryDate != null && params.purchaseDate != null) {
|
||||
if (params.expiryDate!.isBefore(params.purchaseDate!)) {
|
||||
return Left(ValidationFailure(message: '만료일은 구매일 이후여야 합니다'));
|
||||
}
|
||||
|
||||
// 비즈니스 로직: 최소 라이선스 기간 검증 (30일)
|
||||
final duration = params.expiryDate!.difference(params.startDate!).inDays;
|
||||
final duration = params.expiryDate!.difference(params.purchaseDate!).inDays;
|
||||
if (duration < 30) {
|
||||
return Left(ValidationFailure(message: '라이선스 기간은 최소 30일 이상이어야 합니다'));
|
||||
}
|
||||
}
|
||||
|
||||
final license = await repository.updateLicense(params.id, params.toMap());
|
||||
return Right(license);
|
||||
final license = License(
|
||||
id: params.id,
|
||||
licenseKey: params.licenseKey ?? '',
|
||||
productName: params.productName ?? '',
|
||||
vendor: params.vendor,
|
||||
licenseType: params.licenseType,
|
||||
userCount: params.userCount,
|
||||
purchaseDate: params.purchaseDate ?? DateTime.now(),
|
||||
expiryDate: params.expiryDate ?? DateTime.now(),
|
||||
purchasePrice: params.purchasePrice,
|
||||
companyId: params.companyId ?? 0,
|
||||
branchId: params.branchId,
|
||||
assignedUserId: params.assignedUserId,
|
||||
remark: params.remark,
|
||||
isActive: params.isActive ?? true,
|
||||
);
|
||||
|
||||
final result = await repository.updateLicense(params.id ?? 0, license);
|
||||
return result.map((updatedLicense) => LicenseDto(
|
||||
id: updatedLicense.id ?? 0,
|
||||
licenseKey: updatedLicense.licenseKey,
|
||||
productName: updatedLicense.productName,
|
||||
vendor: updatedLicense.vendor,
|
||||
licenseType: updatedLicense.licenseType,
|
||||
userCount: updatedLicense.userCount,
|
||||
purchaseDate: updatedLicense.purchaseDate,
|
||||
expiryDate: updatedLicense.expiryDate,
|
||||
purchasePrice: updatedLicense.purchasePrice,
|
||||
companyId: updatedLicense.companyId,
|
||||
branchId: updatedLicense.branchId,
|
||||
assignedUserId: updatedLicense.assignedUserId,
|
||||
remark: updatedLicense.remark,
|
||||
isActive: updatedLicense.isActive,
|
||||
createdAt: updatedLicense.createdAt ?? DateTime.now(),
|
||||
updatedAt: updatedLicense.updatedAt ?? DateTime.now(),
|
||||
companyName: updatedLicense.companyName,
|
||||
branchName: updatedLicense.branchName,
|
||||
assignedUserName: updatedLicense.assignedUserName,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
@@ -39,37 +77,34 @@ class UpdateLicenseUseCase implements UseCase<LicenseDto, UpdateLicenseParams> {
|
||||
/// 라이선스 수정 파라미터
|
||||
class UpdateLicenseParams {
|
||||
final int id;
|
||||
final int? equipmentId;
|
||||
final int? companyId;
|
||||
final String? licenseKey;
|
||||
final String? productName;
|
||||
final String? vendor;
|
||||
final String? licenseType;
|
||||
final DateTime? startDate;
|
||||
final int? userCount;
|
||||
final DateTime? purchaseDate;
|
||||
final DateTime? expiryDate;
|
||||
final String? description;
|
||||
final double? cost;
|
||||
final String? status;
|
||||
final double? purchasePrice;
|
||||
final int? companyId;
|
||||
final int? branchId;
|
||||
final int? assignedUserId;
|
||||
final String? remark;
|
||||
final bool? isActive;
|
||||
|
||||
UpdateLicenseParams({
|
||||
required this.id,
|
||||
this.equipmentId,
|
||||
this.companyId,
|
||||
this.licenseKey,
|
||||
this.productName,
|
||||
this.vendor,
|
||||
this.licenseType,
|
||||
this.startDate,
|
||||
this.userCount,
|
||||
this.purchaseDate,
|
||||
this.expiryDate,
|
||||
this.description,
|
||||
this.cost,
|
||||
this.status,
|
||||
this.purchasePrice,
|
||||
this.companyId,
|
||||
this.branchId,
|
||||
this.assignedUserId,
|
||||
this.remark,
|
||||
this.isActive,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
final Map<String, dynamic> data = {};
|
||||
if (equipmentId != null) data['equipment_id'] = equipmentId;
|
||||
if (companyId != null) data['company_id'] = companyId;
|
||||
if (licenseType != null) data['license_type'] = licenseType;
|
||||
if (startDate != null) data['start_date'] = startDate!.toIso8601String();
|
||||
if (expiryDate != null) data['expiry_date'] = expiryDate!.toIso8601String();
|
||||
if (description != null) data['description'] = description;
|
||||
if (cost != null) data['cost'] = cost;
|
||||
if (status != null) data['status'] = status;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user