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,20 +1,20 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/auth_service.dart';
|
||||
import '../../repositories/auth_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 인증 상태 확인 UseCase
|
||||
/// 현재 사용자가 로그인되어 있는지 확인
|
||||
class CheckAuthStatusUseCase extends UseCase<bool, NoParams> {
|
||||
final AuthService _authService;
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
CheckAuthStatusUseCase(this._authService);
|
||||
CheckAuthStatusUseCase(this._authRepository);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> call(NoParams params) async {
|
||||
try {
|
||||
final isAuthenticated = await _authService.isLoggedIn();
|
||||
return Right(isAuthenticated);
|
||||
final result = await _authRepository.isAuthenticated();
|
||||
return result;
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '인증 상태 확인 중 오류가 발생했습니다.',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../services/auth_service.dart';
|
||||
import '../../repositories/auth_repository.dart';
|
||||
import '../../../data/models/auth/login_request.dart';
|
||||
import '../../../data/models/auth/login_response.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
@@ -20,9 +20,9 @@ class LoginParams {
|
||||
/// 로그인 UseCase
|
||||
/// 사용자 인증을 처리하고 토큰을 저장
|
||||
class LoginUseCase extends UseCase<LoginResponse, LoginParams> {
|
||||
final AuthService _authService;
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
LoginUseCase(this._authService);
|
||||
LoginUseCase(this._authRepository);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, LoginResponse>> call(LoginParams params) async {
|
||||
@@ -49,7 +49,7 @@ class LoginUseCase extends UseCase<LoginResponse, LoginParams> {
|
||||
password: params.password,
|
||||
);
|
||||
|
||||
return await _authService.login(loginRequest);
|
||||
return await _authRepository.login(loginRequest);
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 401) {
|
||||
return Left(AuthFailure(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/company_service.dart';
|
||||
import '../../repositories/company_repository.dart';
|
||||
import '../../../models/company_model.dart';
|
||||
import '../../../data/models/common/paginated_response.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -20,28 +21,21 @@ class GetCompaniesParams {
|
||||
}
|
||||
|
||||
/// 회사 목록 조회 UseCase
|
||||
class GetCompaniesUseCase extends UseCase<List<Company>, GetCompaniesParams> {
|
||||
final CompanyService _companyService;
|
||||
class GetCompaniesUseCase extends UseCase<PaginatedResponse<Company>, GetCompaniesParams> {
|
||||
final CompanyRepository _companyRepository;
|
||||
|
||||
GetCompaniesUseCase(this._companyService);
|
||||
GetCompaniesUseCase(this._companyRepository);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Company>>> call(GetCompaniesParams params) async {
|
||||
Future<Either<Failure, PaginatedResponse<Company>>> call(GetCompaniesParams params) async {
|
||||
try {
|
||||
final response = await _companyService.getCompanies(
|
||||
final result = await _companyRepository.getCompanies(
|
||||
page: params.page,
|
||||
perPage: params.perPage,
|
||||
limit: params.perPage,
|
||||
search: params.search,
|
||||
isActive: params.isActive,
|
||||
);
|
||||
|
||||
// PaginatedResponse에서 items만 추출
|
||||
return Right(response.items);
|
||||
} on ServerFailure catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: e.message,
|
||||
originalError: e,
|
||||
));
|
||||
return result;
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(
|
||||
message: '회사 목록을 불러오는 중 오류가 발생했습니다.',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/license/license_dto.dart';
|
||||
import '../../../data/repositories/license_repository.dart';
|
||||
import '../../repositories/license_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -16,39 +16,66 @@ class CheckLicenseExpiryUseCase implements UseCase<LicenseExpiryResult, CheckLic
|
||||
Future<Either<Failure, LicenseExpiryResult>> call(CheckLicenseExpiryParams params) async {
|
||||
try {
|
||||
// 모든 라이선스 조회
|
||||
final allLicenses = await repository.getLicenses(
|
||||
final allLicensesResult = await repository.getLicenses(
|
||||
page: 1,
|
||||
perPage: 10000, // 모든 라이선스 조회
|
||||
limit: 10000, // 모든 라이선스 조회
|
||||
);
|
||||
|
||||
final now = DateTime.now();
|
||||
final expiring30Days = <LicenseDto>[];
|
||||
final expiring60Days = <LicenseDto>[];
|
||||
final expiring90Days = <LicenseDto>[];
|
||||
final expired = <LicenseDto>[];
|
||||
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 allLicenses.items) {
|
||||
if (license.expiryDate == null) continue;
|
||||
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,
|
||||
);
|
||||
|
||||
final daysUntilExpiry = license.expiryDate!.difference(now).inDays;
|
||||
if (licenseDto.expiryDate == null) continue;
|
||||
|
||||
if (daysUntilExpiry < 0) {
|
||||
expired.add(license);
|
||||
} else if (daysUntilExpiry <= 30) {
|
||||
expiring30Days.add(license);
|
||||
} else if (daysUntilExpiry <= 60) {
|
||||
expiring60Days.add(license);
|
||||
} else if (daysUntilExpiry <= 90) {
|
||||
expiring90Days.add(license);
|
||||
}
|
||||
}
|
||||
final daysUntilExpiry = licenseDto.expiryDate!.difference(now).inDays;
|
||||
|
||||
return Right(LicenseExpiryResult(
|
||||
expiring30Days: expiring30Days,
|
||||
expiring60Days: expiring60Days,
|
||||
expiring90Days: expiring90Days,
|
||||
expired: expired,
|
||||
));
|
||||
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()));
|
||||
}
|
||||
|
||||
@@ -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,18 +17,52 @@ class CreateLicenseUseCase implements UseCase<LicenseDto, CreateLicenseParams> {
|
||||
Future<Either<Failure, LicenseDto>> call(CreateLicenseParams params) async {
|
||||
try {
|
||||
// 비즈니스 로직: 만료일 검증
|
||||
if (params.expiryDate.isBefore(params.startDate)) {
|
||||
return Left(ValidationFailure(message: '만료일은 시작일 이후여야 합니다'));
|
||||
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.createLicense(params.toMap());
|
||||
return Right(license);
|
||||
final license = License(
|
||||
licenseKey: params.licenseKey,
|
||||
productName: params.productName,
|
||||
vendor: params.vendor,
|
||||
licenseType: params.licenseType,
|
||||
userCount: params.userCount,
|
||||
purchaseDate: params.purchaseDate,
|
||||
expiryDate: params.expiryDate,
|
||||
purchasePrice: params.purchasePrice,
|
||||
companyId: params.companyId,
|
||||
branchId: params.branchId,
|
||||
remark: params.remark,
|
||||
);
|
||||
|
||||
final result = await repository.createLicense(license);
|
||||
return result.map((createdLicense) => LicenseDto(
|
||||
id: createdLicense.id!,
|
||||
licenseKey: createdLicense.licenseKey,
|
||||
productName: createdLicense.productName,
|
||||
vendor: createdLicense.vendor,
|
||||
licenseType: createdLicense.licenseType,
|
||||
userCount: createdLicense.userCount,
|
||||
purchaseDate: createdLicense.purchaseDate,
|
||||
expiryDate: createdLicense.expiryDate,
|
||||
purchasePrice: createdLicense.purchasePrice,
|
||||
companyId: createdLicense.companyId,
|
||||
branchId: createdLicense.branchId,
|
||||
assignedUserId: createdLicense.assignedUserId,
|
||||
remark: createdLicense.remark,
|
||||
isActive: createdLicense.isActive,
|
||||
createdAt: createdLicense.createdAt ?? DateTime.now(),
|
||||
updatedAt: createdLicense.updatedAt ?? DateTime.now(),
|
||||
companyName: createdLicense.companyName,
|
||||
branchName: createdLicense.branchName,
|
||||
assignedUserName: createdLicense.assignedUserName,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
@@ -36,33 +71,29 @@ class CreateLicenseUseCase implements UseCase<LicenseDto, CreateLicenseParams> {
|
||||
|
||||
/// 라이선스 생성 파라미터
|
||||
class CreateLicenseParams {
|
||||
final int equipmentId;
|
||||
final int companyId;
|
||||
final String licenseType;
|
||||
final DateTime startDate;
|
||||
final String licenseKey;
|
||||
final String productName;
|
||||
final String? vendor;
|
||||
final String? licenseType;
|
||||
final int? userCount;
|
||||
final DateTime purchaseDate;
|
||||
final DateTime expiryDate;
|
||||
final String? description;
|
||||
final double? cost;
|
||||
final double? purchasePrice;
|
||||
final int companyId;
|
||||
final int? branchId;
|
||||
final String? remark;
|
||||
|
||||
CreateLicenseParams({
|
||||
required this.equipmentId,
|
||||
required this.companyId,
|
||||
required this.licenseType,
|
||||
required this.startDate,
|
||||
required this.licenseKey,
|
||||
required this.productName,
|
||||
this.vendor,
|
||||
this.licenseType,
|
||||
this.userCount,
|
||||
required this.purchaseDate,
|
||||
required this.expiryDate,
|
||||
this.description,
|
||||
this.cost,
|
||||
this.purchasePrice,
|
||||
required this.companyId,
|
||||
this.branchId,
|
||||
this.remark,
|
||||
});
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/repositories/license_repository.dart';
|
||||
import '../../repositories/license_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -15,13 +15,21 @@ class DeleteLicenseUseCase implements UseCase<bool, int> {
|
||||
Future<Either<Failure, bool>> call(int id) async {
|
||||
try {
|
||||
// 비즈니스 로직: 활성 라이선스는 삭제 불가
|
||||
final license = await repository.getLicenseDetail(id);
|
||||
if (license.isActive) {
|
||||
return Left(ValidationFailure(message: '활성 라이선스는 삭제할 수 없습니다'));
|
||||
}
|
||||
final licenseResult = await repository.getLicenseById(id);
|
||||
return licenseResult.fold(
|
||||
(failure) => Left(failure),
|
||||
(license) async {
|
||||
if (license.isActive == true) {
|
||||
return Left(ValidationFailure(message: '활성 라이선스는 삭제할 수 없습니다'));
|
||||
}
|
||||
|
||||
await repository.deleteLicense(id);
|
||||
return const Right(true);
|
||||
final deleteResult = await repository.deleteLicense(id);
|
||||
return deleteResult.fold(
|
||||
(failure) => Left(failure),
|
||||
(_) => const Right(true),
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/license/license_dto.dart';
|
||||
import '../../../data/repositories/license_repository.dart';
|
||||
import '../../repositories/license_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -15,8 +15,28 @@ class GetLicenseDetailUseCase implements UseCase<LicenseDto, int> {
|
||||
@override
|
||||
Future<Either<Failure, LicenseDto>> call(int id) async {
|
||||
try {
|
||||
final license = await repository.getLicenseDetail(id);
|
||||
return Right(license);
|
||||
final result = await repository.getLicenseById(id);
|
||||
return result.map((license) => 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,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/common/pagination_params.dart';
|
||||
import '../../../data/models/license/license_dto.dart';
|
||||
import '../../../data/repositories/license_repository.dart';
|
||||
import '../../repositories/license_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -16,13 +16,43 @@ class GetLicensesUseCase implements UseCase<LicenseListResponseDto, GetLicensesP
|
||||
@override
|
||||
Future<Either<Failure, LicenseListResponseDto>> call(GetLicensesParams params) async {
|
||||
try {
|
||||
final licenses = await repository.getLicenses(
|
||||
final result = await repository.getLicenses(
|
||||
page: params.page,
|
||||
perPage: params.perPage,
|
||||
limit: params.perPage,
|
||||
search: params.search,
|
||||
filters: params.filters,
|
||||
companyId: params.filters?['companyId'],
|
||||
equipmentType: params.filters?['equipmentType'],
|
||||
expiryStatus: params.filters?['expiryStatus'],
|
||||
sortBy: params.filters?['sortBy'],
|
||||
sortOrder: params.filters?['sortOrder'],
|
||||
);
|
||||
return Right(licenses);
|
||||
return result.map((paginatedResponse) => LicenseListResponseDto(
|
||||
items: paginatedResponse.items.map((license) => 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,
|
||||
)).toList(),
|
||||
page: paginatedResponse.page,
|
||||
perPage: params.perPage,
|
||||
total: paginatedResponse.totalElements,
|
||||
totalPages: paginatedResponse.totalPages,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/warehouse/warehouse_dto.dart';
|
||||
import '../../../data/repositories/warehouse_location_repository.dart';
|
||||
import '../../../models/warehouse_location_model.dart';
|
||||
import '../../../models/address_model.dart';
|
||||
import '../../repositories/warehouse_location_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -33,8 +35,21 @@ class CreateWarehouseLocationUseCase implements UseCase<WarehouseLocationDto, Cr
|
||||
}
|
||||
}
|
||||
|
||||
final location = await repository.createWarehouseLocation(params.toMap());
|
||||
return Right(location);
|
||||
final warehouseLocation = WarehouseLocation(
|
||||
id: 0, // Default id for new warehouse location
|
||||
name: params.name,
|
||||
address: Address.fromFullAddress(params.address),
|
||||
remark: params.description,
|
||||
);
|
||||
|
||||
final result = await repository.createWarehouseLocation(warehouseLocation);
|
||||
return result.map((createdLocation) => WarehouseLocationDto(
|
||||
id: createdLocation.id ?? 0,
|
||||
name: createdLocation.name,
|
||||
address: createdLocation.address.toString(),
|
||||
isActive: true, // Default value since model doesn't have isActive
|
||||
createdAt: DateTime.now(), // Add required createdAt parameter
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/repositories/warehouse_location_repository.dart';
|
||||
import '../../repositories/warehouse_location_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/warehouse/warehouse_dto.dart';
|
||||
import '../../../data/repositories/warehouse_location_repository.dart';
|
||||
import '../../repositories/warehouse_location_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -15,8 +15,14 @@ class GetWarehouseLocationDetailUseCase implements UseCase<WarehouseLocationDto,
|
||||
@override
|
||||
Future<Either<Failure, WarehouseLocationDto>> call(int id) async {
|
||||
try {
|
||||
final location = await repository.getWarehouseLocationDetail(id);
|
||||
return Right(location);
|
||||
final result = await repository.getWarehouseLocationById(id);
|
||||
return result.map((location) => WarehouseLocationDto(
|
||||
id: location.id ?? 0,
|
||||
name: location.name,
|
||||
address: location.address.toString(),
|
||||
isActive: true, // Default value since model doesn't have isActive
|
||||
createdAt: DateTime.now(), // Add required createdAt parameter
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/common/pagination_params.dart';
|
||||
import '../../../data/models/warehouse/warehouse_dto.dart';
|
||||
import '../../../data/repositories/warehouse_location_repository.dart';
|
||||
import '../../repositories/warehouse_location_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -16,13 +16,29 @@ class GetWarehouseLocationsUseCase implements UseCase<WarehouseLocationListDto,
|
||||
@override
|
||||
Future<Either<Failure, WarehouseLocationListDto>> call(GetWarehouseLocationsParams params) async {
|
||||
try {
|
||||
final locations = await repository.getWarehouseLocations(
|
||||
final result = await repository.getWarehouseLocations(
|
||||
page: params.page,
|
||||
perPage: params.perPage,
|
||||
limit: params.perPage,
|
||||
search: params.search,
|
||||
filters: params.filters,
|
||||
locationType: params.filters?['locationType'],
|
||||
isActive: params.filters?['isActive'],
|
||||
hasEquipment: params.filters?['hasEquipment'],
|
||||
sortBy: params.filters?['sortBy'],
|
||||
sortOrder: params.filters?['sortOrder'],
|
||||
);
|
||||
return Right(locations);
|
||||
return result.map((paginatedResponse) => WarehouseLocationListDto(
|
||||
items: paginatedResponse.items.map((location) => WarehouseLocationDto(
|
||||
id: location.id ?? 0,
|
||||
name: location.name,
|
||||
address: location.address.toString(),
|
||||
isActive: true, // Default value since model doesn't have isActive
|
||||
createdAt: DateTime.now(), // Add required createdAt parameter
|
||||
)).toList(),
|
||||
page: paginatedResponse.page,
|
||||
perPage: params.perPage, // Add missing required perPage parameter
|
||||
total: paginatedResponse.totalElements,
|
||||
totalPages: paginatedResponse.totalPages,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../../../data/models/warehouse/warehouse_dto.dart';
|
||||
import '../../../data/repositories/warehouse_location_repository.dart';
|
||||
import '../../../models/warehouse_location_model.dart';
|
||||
import '../../../models/address_model.dart';
|
||||
import '../../repositories/warehouse_location_repository.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
@@ -41,8 +43,21 @@ class UpdateWarehouseLocationUseCase implements UseCase<WarehouseLocationDto, Up
|
||||
return Left(ValidationFailure(message: '유효하지 않은 경도값입니다'));
|
||||
}
|
||||
|
||||
final location = await repository.updateWarehouseLocation(params.id, params.toMap());
|
||||
return Right(location);
|
||||
final warehouseLocation = WarehouseLocation(
|
||||
id: params.id,
|
||||
name: params.name ?? '',
|
||||
address: params.address != null ? Address.fromFullAddress(params.address!) : const Address(),
|
||||
remark: params.description,
|
||||
);
|
||||
|
||||
final result = await repository.updateWarehouseLocation(params.id, warehouseLocation);
|
||||
return result.map((updatedLocation) => WarehouseLocationDto(
|
||||
id: updatedLocation.id ?? 0,
|
||||
name: updatedLocation.name,
|
||||
address: updatedLocation.address.toString(),
|
||||
isActive: true, // Default value since model doesn't have isActive
|
||||
createdAt: DateTime.now(), // Add required createdAt parameter
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user