## 주요 변경사항 ### 아키텍처 개선 - Clean Architecture 패턴 적용 (Domain, Data, Presentation 레이어 분리) - Use Case 패턴 도입으로 비즈니스 로직 캡슐화 - Repository 패턴으로 데이터 접근 추상화 - 의존성 주입 구조 개선 ### 상태 관리 최적화 - 모든 Controller에서 불필요한 상태 관리 로직 제거 - 페이지네이션 로직 통일 및 간소화 - 에러 처리 로직 개선 (에러 메시지 한글화) - 로딩 상태 관리 최적화 ### Mock 서비스 제거 - MockDataService 완전 제거 - 모든 화면을 실제 API 전용으로 전환 - 불필요한 Mock 관련 코드 정리 ### UI/UX 개선 - Overview 화면 대시보드 기능 강화 - 라이선스 만료 알림 위젯 추가 - 사이드바 네비게이션 개선 - 일관된 UI 컴포넌트 사용 ### 코드 품질 - 중복 코드 제거 및 함수 추출 - 파일별 책임 분리 명확화 - 테스트 코드 업데이트 ## 영향 범위 - 모든 화면의 Controller 리팩토링 - API 통신 레이어 구조 개선 - 에러 처리 및 로깅 시스템 개선 ## 향후 계획 - 단위 테스트 커버리지 확대 - 통합 테스트 시나리오 추가 - 성능 모니터링 도구 통합
68 lines
2.0 KiB
Dart
68 lines
2.0 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
import '../../../data/models/license/license_dto.dart';
|
|
import '../../../data/repositories/license_repository.dart';
|
|
import '../../../core/errors/failures.dart';
|
|
import '../base_usecase.dart';
|
|
|
|
/// 라이선스 생성 UseCase
|
|
@injectable
|
|
class CreateLicenseUseCase implements UseCase<LicenseDto, CreateLicenseParams> {
|
|
final LicenseRepository repository;
|
|
|
|
CreateLicenseUseCase(this.repository);
|
|
|
|
@override
|
|
Future<Either<Failure, LicenseDto>> call(CreateLicenseParams params) async {
|
|
try {
|
|
// 비즈니스 로직: 만료일 검증
|
|
if (params.expiryDate.isBefore(params.startDate)) {
|
|
return Left(ValidationFailure(message: '만료일은 시작일 이후여야 합니다'));
|
|
}
|
|
|
|
// 비즈니스 로직: 최소 라이선스 기간 검증 (30일)
|
|
final duration = params.expiryDate.difference(params.startDate).inDays;
|
|
if (duration < 30) {
|
|
return Left(ValidationFailure(message: '라이선스 기간은 최소 30일 이상이어야 합니다'));
|
|
}
|
|
|
|
final license = await repository.createLicense(params.toMap());
|
|
return Right(license);
|
|
} catch (e) {
|
|
return Left(ServerFailure(message: e.toString()));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 라이선스 생성 파라미터
|
|
class CreateLicenseParams {
|
|
final int equipmentId;
|
|
final int companyId;
|
|
final String licenseType;
|
|
final DateTime startDate;
|
|
final DateTime expiryDate;
|
|
final String? description;
|
|
final double? cost;
|
|
|
|
CreateLicenseParams({
|
|
required this.equipmentId,
|
|
required this.companyId,
|
|
required this.licenseType,
|
|
required this.startDate,
|
|
required this.expiryDate,
|
|
this.description,
|
|
this.cost,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'equipment_id': equipmentId,
|
|
'company_id': companyId,
|
|
'license_type': licenseType,
|
|
'start_date': startDate.toIso8601String(),
|
|
'expiry_date': expiryDate.toIso8601String(),
|
|
'description': description,
|
|
'cost': cost,
|
|
};
|
|
}
|
|
} |