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:
51
lib/domain/repositories/auth_repository.dart
Normal file
51
lib/domain/repositories/auth_repository.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../core/errors/failures.dart';
|
||||
import '../../data/models/auth/auth_user.dart';
|
||||
import '../../data/models/auth/login_request.dart';
|
||||
import '../../data/models/auth/login_response.dart';
|
||||
import '../../data/models/auth/token_response.dart';
|
||||
import '../../data/models/auth/refresh_token_request.dart';
|
||||
|
||||
/// 인증 Repository 인터페이스
|
||||
/// 사용자 로그인, 로그아웃, 토큰 관리 등 인증 관련 기능을 담당
|
||||
abstract class AuthRepository {
|
||||
/// 사용자 로그인
|
||||
/// [loginRequest] 로그인 요청 데이터 (사용자명, 비밀번호)
|
||||
/// Returns: 로그인 응답 (토큰, 사용자 정보)
|
||||
Future<Either<Failure, LoginResponse>> login(LoginRequest loginRequest);
|
||||
|
||||
/// 사용자 로그아웃
|
||||
/// 서버에 로그아웃 요청을 보내고 세션을 종료
|
||||
/// Returns: 로그아웃 성공/실패 여부
|
||||
Future<Either<Failure, void>> logout();
|
||||
|
||||
/// 액세스 토큰 갱신
|
||||
/// [refreshRequest] 리프레시 토큰 요청 데이터
|
||||
/// Returns: 새로운 토큰 정보
|
||||
Future<Either<Failure, TokenResponse>> refreshToken(RefreshTokenRequest refreshRequest);
|
||||
|
||||
/// 현재 인증된 사용자 정보 조회
|
||||
/// Returns: 현재 사용자 정보
|
||||
Future<Either<Failure, AuthUser>> getCurrentUser();
|
||||
|
||||
/// 인증 상태 확인
|
||||
/// 현재 사용자가 인증되어 있는지 확인
|
||||
/// Returns: 인증 여부 (true: 인증됨, false: 미인증)
|
||||
Future<Either<Failure, bool>> isAuthenticated();
|
||||
|
||||
/// 비밀번호 변경
|
||||
/// [currentPassword] 현재 비밀번호
|
||||
/// [newPassword] 새 비밀번호
|
||||
/// Returns: 비밀번호 변경 성공/실패 여부
|
||||
Future<Either<Failure, void>> changePassword(String currentPassword, String newPassword);
|
||||
|
||||
/// 비밀번호 재설정 요청
|
||||
/// [email] 비밀번호 재설정을 요청할 이메일 주소
|
||||
/// Returns: 비밀번호 재설정 요청 성공/실패 여부
|
||||
Future<Either<Failure, void>> requestPasswordReset(String email);
|
||||
|
||||
/// 세션 유효성 검증
|
||||
/// 현재 저장된 토큰이 유효한지 서버에서 검증
|
||||
/// Returns: 세션 유효성 여부
|
||||
Future<Either<Failure, bool>> validateSession();
|
||||
}
|
||||
96
lib/domain/repositories/company_repository.dart
Normal file
96
lib/domain/repositories/company_repository.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../core/errors/failures.dart';
|
||||
import '../../models/company_model.dart';
|
||||
import '../../data/models/common/paginated_response.dart';
|
||||
|
||||
/// 회사 관리 Repository 인터페이스
|
||||
/// 회사 및 지점 정보 관리를 위한 CRUD 기능을 담당
|
||||
abstract class CompanyRepository {
|
||||
/// 회사 목록 조회
|
||||
/// [page] 페이지 번호 (기본값: 1)
|
||||
/// [limit] 페이지당 항목 수 (기본값: 20)
|
||||
/// [search] 검색어 (회사명, 담당자명 등)
|
||||
/// [companyType] 회사 유형 필터 (고객사, 파트너사)
|
||||
/// [sortBy] 정렬 기준 ('name', 'createdAt' 등)
|
||||
/// [sortOrder] 정렬 순서 ('asc', 'desc')
|
||||
/// Returns: 페이지네이션된 회사 목록
|
||||
Future<Either<Failure, PaginatedResponse<Company>>> getCompanies({
|
||||
int? page,
|
||||
int? limit,
|
||||
String? search,
|
||||
CompanyType? companyType,
|
||||
String? sortBy,
|
||||
String? sortOrder,
|
||||
});
|
||||
|
||||
/// 회사 상세 정보 조회
|
||||
/// [id] 회사 고유 식별자
|
||||
/// Returns: 지점 정보를 포함한 회사 상세 정보
|
||||
Future<Either<Failure, Company>> getCompanyById(int id);
|
||||
|
||||
/// 회사 생성
|
||||
/// [company] 생성할 회사 정보
|
||||
/// Returns: 생성된 회사 정보 (ID 포함)
|
||||
Future<Either<Failure, Company>> createCompany(Company company);
|
||||
|
||||
/// 회사 정보 수정
|
||||
/// [id] 수정할 회사 고유 식별자
|
||||
/// [company] 수정할 회사 정보
|
||||
/// Returns: 수정된 회사 정보
|
||||
Future<Either<Failure, Company>> updateCompany(int id, Company company);
|
||||
|
||||
/// 회사 삭제
|
||||
/// [id] 삭제할 회사 고유 식별자
|
||||
/// Returns: 삭제 성공/실패 여부
|
||||
Future<Either<Failure, void>> deleteCompany(int id);
|
||||
|
||||
/// 회사 상태 토글 (활성화/비활성화)
|
||||
/// [id] 상태를 변경할 회사 고유 식별자
|
||||
/// Returns: 상태 변경된 회사 정보
|
||||
Future<Either<Failure, Company>> toggleCompanyStatus(int id);
|
||||
|
||||
/// 지점 생성
|
||||
/// [companyId] 지점을 추가할 회사 ID
|
||||
/// [branch] 생성할 지점 정보
|
||||
/// Returns: 생성된 지점 정보 (ID 포함)
|
||||
Future<Either<Failure, Branch>> createBranch(int companyId, Branch branch);
|
||||
|
||||
/// 지점 정보 수정
|
||||
/// [companyId] 회사 ID
|
||||
/// [branchId] 수정할 지점 ID
|
||||
/// [branch] 수정할 지점 정보
|
||||
/// Returns: 수정된 지점 정보
|
||||
Future<Either<Failure, Branch>> updateBranch(int companyId, int branchId, Branch branch);
|
||||
|
||||
/// 지점 삭제
|
||||
/// [companyId] 회사 ID
|
||||
/// [branchId] 삭제할 지점 ID
|
||||
/// Returns: 삭제 성공/실패 여부
|
||||
Future<Either<Failure, void>> deleteBranch(int companyId, int branchId);
|
||||
|
||||
/// 회사명으로 검색 (자동완성용)
|
||||
/// [query] 검색 쿼리
|
||||
/// [limit] 결과 제한 수 (기본값: 10)
|
||||
/// Returns: 일치하는 회사명 목록
|
||||
Future<Either<Failure, List<String>>> searchCompanyNames(String query, {int? limit});
|
||||
|
||||
/// 회사 유형별 개수 통계
|
||||
/// Returns: 회사 유형별 개수 (고객사, 파트너사)
|
||||
Future<Either<Failure, Map<CompanyType, int>>> getCompanyCountByType();
|
||||
|
||||
/// 회사에 연결된 사용자 존재 여부 확인
|
||||
/// [companyId] 확인할 회사 ID
|
||||
/// Returns: 연결된 사용자 존재 여부 (삭제 가능 여부 판단용)
|
||||
Future<Either<Failure, bool>> hasLinkedUsers(int companyId);
|
||||
|
||||
/// 회사에 연결된 장비 존재 여부 확인
|
||||
/// [companyId] 확인할 회사 ID
|
||||
/// Returns: 연결된 장비 존재 여부 (삭제 가능 여부 판단용)
|
||||
Future<Either<Failure, bool>> hasLinkedEquipment(int companyId);
|
||||
|
||||
/// 중복 회사명 체크
|
||||
/// [name] 체크할 회사명
|
||||
/// [excludeId] 체크에서 제외할 회사 ID (수정 시 현재 회사 제외용)
|
||||
/// Returns: 중복 여부 (true: 중복됨, false: 중복되지 않음)
|
||||
Future<Either<Failure, bool>> isDuplicateCompanyName(String name, {int? excludeId});
|
||||
}
|
||||
101
lib/domain/repositories/license_repository.dart
Normal file
101
lib/domain/repositories/license_repository.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../core/errors/failures.dart';
|
||||
import '../../models/license_model.dart';
|
||||
import '../../data/models/common/paginated_response.dart';
|
||||
import '../../data/models/dashboard/license_expiry_summary.dart';
|
||||
|
||||
/// 라이선스 관리 Repository 인터페이스
|
||||
/// 장비 라이선스 및 유지보수 계약 정보 관리를 담당
|
||||
abstract class LicenseRepository {
|
||||
/// 라이선스 목록 조회
|
||||
/// [page] 페이지 번호 (기본값: 1)
|
||||
/// [limit] 페이지당 항목 수 (기본값: 20)
|
||||
/// [search] 검색어 (라이선스명, 회사명, 장비명 등)
|
||||
/// [companyId] 회사 ID 필터
|
||||
/// [equipmentType] 장비 유형 필터
|
||||
/// [expiryStatus] 만료 상태 필터 ('expired', 'expiring', 'active')
|
||||
/// [sortBy] 정렬 기준 ('name', 'expiryDate', 'createdAt' 등)
|
||||
/// [sortOrder] 정렬 순서 ('asc', 'desc')
|
||||
/// Returns: 페이지네이션된 라이선스 목록
|
||||
Future<Either<Failure, PaginatedResponse<License>>> getLicenses({
|
||||
int? page,
|
||||
int? limit,
|
||||
String? search,
|
||||
int? companyId,
|
||||
String? equipmentType,
|
||||
String? expiryStatus,
|
||||
String? sortBy,
|
||||
String? sortOrder,
|
||||
});
|
||||
|
||||
/// 라이선스 상세 정보 조회
|
||||
/// [id] 라이선스 고유 식별자
|
||||
/// Returns: 라이선스 상세 정보 (회사, 장비 정보 포함)
|
||||
Future<Either<Failure, License>> getLicenseById(int id);
|
||||
|
||||
/// 라이선스 생성
|
||||
/// [license] 생성할 라이선스 정보
|
||||
/// Returns: 생성된 라이선스 정보 (ID 포함)
|
||||
Future<Either<Failure, License>> createLicense(License license);
|
||||
|
||||
/// 라이선스 정보 수정
|
||||
/// [id] 수정할 라이선스 고유 식별자
|
||||
/// [license] 수정할 라이선스 정보
|
||||
/// Returns: 수정된 라이선스 정보
|
||||
Future<Either<Failure, License>> updateLicense(int id, License license);
|
||||
|
||||
/// 라이선스 삭제
|
||||
/// [id] 삭제할 라이선스 고유 식별자
|
||||
/// Returns: 삭제 성공/실패 여부
|
||||
Future<Either<Failure, void>> deleteLicense(int id);
|
||||
|
||||
/// 만료 예정 라이선스 조회
|
||||
/// [days] 앞으로 N일 내 만료 예정 (기본값: 30일)
|
||||
/// [companyId] 회사 ID 필터 (선택적)
|
||||
/// Returns: 만료 예정 라이선스 목록
|
||||
Future<Either<Failure, List<License>>> getExpiringLicenses({int days = 30, int? companyId});
|
||||
|
||||
/// 만료된 라이선스 조회
|
||||
/// [companyId] 회사 ID 필터 (선택적)
|
||||
/// Returns: 이미 만료된 라이선스 목록
|
||||
Future<Either<Failure, List<License>>> getExpiredLicenses({int? companyId});
|
||||
|
||||
/// 라이선스 만료 요약 정보 조회
|
||||
/// 대시보드용 30일/60일/90일 내 만료 예정 요약 정보
|
||||
/// Returns: 만료 예정 요약 정보
|
||||
Future<Either<Failure, LicenseExpirySummary>> getLicenseExpirySummary();
|
||||
|
||||
/// 라이선스 갱신
|
||||
/// [id] 갱신할 라이선스 ID
|
||||
/// [newExpiryDate] 새로운 만료일
|
||||
/// [renewalCost] 갱신 비용 (선택적)
|
||||
/// [renewalNote] 갱신 비고 (선택적)
|
||||
/// Returns: 갱신된 라이선스 정보
|
||||
Future<Either<Failure, License>> renewLicense(
|
||||
int id,
|
||||
DateTime newExpiryDate,
|
||||
{double? renewalCost, String? renewalNote}
|
||||
);
|
||||
|
||||
/// 회사별 라이선스 통계
|
||||
/// [companyId] 회사 ID
|
||||
/// Returns: 해당 회사의 라이선스 통계 정보 (전체, 활성, 만료, 만료예정)
|
||||
Future<Either<Failure, Map<String, int>>> getLicenseStatsByCompany(int companyId);
|
||||
|
||||
/// 라이선스 유형별 통계
|
||||
/// Returns: 라이선스 유형별 개수 (소프트웨어, 하드웨어 등)
|
||||
Future<Either<Failure, Map<String, int>>> getLicenseCountByType();
|
||||
|
||||
/// 라이선스 만료일 사전 알림 설정
|
||||
/// [licenseId] 라이선스 ID
|
||||
/// [notifyDays] 만료 N일 전 알림 (기본값: 30일)
|
||||
/// Returns: 알림 설정 성공/실패 여부
|
||||
Future<Either<Failure, void>> setExpiryNotification(int licenseId, {int notifyDays = 30});
|
||||
|
||||
/// 라이선스 검색 (자동완성용)
|
||||
/// [query] 검색 쿼리
|
||||
/// [companyId] 회사 ID 필터 (선택적)
|
||||
/// [limit] 결과 제한 수 (기본값: 10)
|
||||
/// Returns: 일치하는 라이선스 목록
|
||||
Future<Either<Failure, List<License>>> searchLicenses(String query, {int? companyId, int? limit});
|
||||
}
|
||||
96
lib/domain/repositories/user_repository.dart
Normal file
96
lib/domain/repositories/user_repository.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../core/errors/failures.dart';
|
||||
import '../../models/user_model.dart';
|
||||
import '../../data/models/common/paginated_response.dart';
|
||||
|
||||
/// 사용자 관리 Repository 인터페이스
|
||||
/// 사용자 계정 생성, 수정, 삭제 및 권한 관리를 담당
|
||||
abstract class UserRepository {
|
||||
/// 사용자 목록 조회
|
||||
/// [page] 페이지 번호 (기본값: 1)
|
||||
/// [limit] 페이지당 항목 수 (기본값: 20)
|
||||
/// [search] 검색어 (사용자명, 이메일, 회사명 등)
|
||||
/// [role] 역할 필터 ('S': 관리자, 'M': 멤버)
|
||||
/// [companyId] 회사 ID 필터
|
||||
/// [isActive] 활성화 상태 필터
|
||||
/// [sortBy] 정렬 기준 ('name', 'createdAt', 'role' 등)
|
||||
/// [sortOrder] 정렬 순서 ('asc', 'desc')
|
||||
/// Returns: 페이지네이션된 사용자 목록
|
||||
Future<Either<Failure, PaginatedResponse<User>>> getUsers({
|
||||
int? page,
|
||||
int? limit,
|
||||
String? search,
|
||||
String? role,
|
||||
int? companyId,
|
||||
bool? isActive,
|
||||
String? sortBy,
|
||||
String? sortOrder,
|
||||
});
|
||||
|
||||
/// 사용자 상세 정보 조회
|
||||
/// [id] 사용자 고유 식별자
|
||||
/// Returns: 사용자 상세 정보 (회사, 지점 정보 포함)
|
||||
Future<Either<Failure, User>> getUserById(int id);
|
||||
|
||||
/// 사용자 계정 생성
|
||||
/// [user] 생성할 사용자 정보
|
||||
/// [password] 초기 비밀번호
|
||||
/// Returns: 생성된 사용자 정보 (ID 포함)
|
||||
Future<Either<Failure, User>> createUser(User user, String password);
|
||||
|
||||
/// 사용자 정보 수정
|
||||
/// [id] 수정할 사용자 고유 식별자
|
||||
/// [user] 수정할 사용자 정보
|
||||
/// Returns: 수정된 사용자 정보
|
||||
Future<Either<Failure, User>> updateUser(int id, User user);
|
||||
|
||||
/// 사용자 삭제
|
||||
/// [id] 삭제할 사용자 고유 식별자
|
||||
/// Returns: 삭제 성공/실패 여부
|
||||
Future<Either<Failure, void>> deleteUser(int id);
|
||||
|
||||
/// 사용자 상태 토글 (활성화/비활성화)
|
||||
/// [id] 상태를 변경할 사용자 고유 식별자
|
||||
/// Returns: 상태 변경된 사용자 정보
|
||||
Future<Either<Failure, User>> toggleUserStatus(int id);
|
||||
|
||||
/// 사용자 비밀번호 재설정
|
||||
/// [id] 비밀번호를 재설정할 사용자 ID
|
||||
/// [newPassword] 새 비밀번호
|
||||
/// Returns: 재설정 성공/실패 여부
|
||||
Future<Either<Failure, void>> resetPassword(int id, String newPassword);
|
||||
|
||||
/// 사용자 역할 변경
|
||||
/// [id] 역할을 변경할 사용자 ID
|
||||
/// [newRole] 새 역할 ('S': 관리자, 'M': 멤버)
|
||||
/// Returns: 역할 변경된 사용자 정보
|
||||
Future<Either<Failure, User>> changeUserRole(int id, String newRole);
|
||||
|
||||
/// 사용자명(이메일) 중복 체크
|
||||
/// [username] 체크할 사용자명(이메일)
|
||||
/// [excludeId] 체크에서 제외할 사용자 ID (수정 시 현재 사용자 제외용)
|
||||
/// Returns: 중복 여부 (true: 중복됨, false: 중복되지 않음)
|
||||
Future<Either<Failure, bool>> isDuplicateUsername(String username, {int? excludeId});
|
||||
|
||||
/// 회사별 사용자 목록 조회
|
||||
/// [companyId] 회사 ID
|
||||
/// [includeInactive] 비활성화 사용자 포함 여부
|
||||
/// Returns: 해당 회사의 사용자 목록
|
||||
Future<Either<Failure, List<User>>> getUsersByCompany(int companyId, {bool includeInactive = false});
|
||||
|
||||
/// 역할별 사용자 수 통계
|
||||
/// Returns: 역할별 사용자 수 (관리자, 멤버)
|
||||
Future<Either<Failure, Map<String, int>>> getUserCountByRole();
|
||||
|
||||
/// 사용자 검색 (자동완성용)
|
||||
/// [query] 검색 쿼리
|
||||
/// [companyId] 회사 ID 필터 (선택적)
|
||||
/// [limit] 결과 제한 수 (기본값: 10)
|
||||
/// Returns: 일치하는 사용자 정보 목록
|
||||
Future<Either<Failure, List<User>>> searchUsers(String query, {int? companyId, int? limit});
|
||||
|
||||
/// 사용자 마지막 로그인 시간 업데이트
|
||||
/// [id] 사용자 ID
|
||||
/// Returns: 업데이트 성공/실패 여부
|
||||
Future<Either<Failure, void>> updateLastLoginTime(int id);
|
||||
}
|
||||
112
lib/domain/repositories/warehouse_location_repository.dart
Normal file
112
lib/domain/repositories/warehouse_location_repository.dart
Normal file
@@ -0,0 +1,112 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../core/errors/failures.dart';
|
||||
import '../../models/warehouse_location_model.dart';
|
||||
import '../../data/models/common/paginated_response.dart';
|
||||
|
||||
/// 창고 위치 관리 Repository 인터페이스
|
||||
/// 장비 입고지 및 창고 위치 정보 관리를 담당
|
||||
abstract class WarehouseLocationRepository {
|
||||
/// 창고 위치 목록 조회
|
||||
/// [page] 페이지 번호 (기본값: 1)
|
||||
/// [limit] 페이지당 항목 수 (기본값: 20)
|
||||
/// [search] 검색어 (창고명, 주소, 담당자명 등)
|
||||
/// [locationType] 위치 유형 필터 ('창고', '사무실', '출고지' 등)
|
||||
/// [isActive] 활성화 상태 필터
|
||||
/// [hasEquipment] 장비 보유 여부 필터
|
||||
/// [sortBy] 정렬 기준 ('name', 'createdAt', 'locationType' 등)
|
||||
/// [sortOrder] 정렬 순서 ('asc', 'desc')
|
||||
/// Returns: 페이지네이션된 창고 위치 목록
|
||||
Future<Either<Failure, PaginatedResponse<WarehouseLocation>>> getWarehouseLocations({
|
||||
int? page,
|
||||
int? limit,
|
||||
String? search,
|
||||
String? locationType,
|
||||
bool? isActive,
|
||||
bool? hasEquipment,
|
||||
String? sortBy,
|
||||
String? sortOrder,
|
||||
});
|
||||
|
||||
/// 창고 위치 상세 정보 조회
|
||||
/// [id] 창고 위치 고유 식별자
|
||||
/// Returns: 창고 위치 상세 정보 (보관 중인 장비 정보 포함)
|
||||
Future<Either<Failure, WarehouseLocation>> getWarehouseLocationById(int id);
|
||||
|
||||
/// 창고 위치 생성
|
||||
/// [warehouseLocation] 생성할 창고 위치 정보
|
||||
/// Returns: 생성된 창고 위치 정보 (ID 포함)
|
||||
Future<Either<Failure, WarehouseLocation>> createWarehouseLocation(WarehouseLocation warehouseLocation);
|
||||
|
||||
/// 창고 위치 정보 수정
|
||||
/// [id] 수정할 창고 위치 고유 식별자
|
||||
/// [warehouseLocation] 수정할 창고 위치 정보
|
||||
/// Returns: 수정된 창고 위치 정보
|
||||
Future<Either<Failure, WarehouseLocation>> updateWarehouseLocation(int id, WarehouseLocation warehouseLocation);
|
||||
|
||||
/// 창고 위치 삭제
|
||||
/// [id] 삭제할 창고 위치 고유 식별자
|
||||
/// Returns: 삭제 성공/실패 여부
|
||||
Future<Either<Failure, void>> deleteWarehouseLocation(int id);
|
||||
|
||||
/// 창고 위치 상태 토글 (활성화/비활성화)
|
||||
/// [id] 상태를 변경할 창고 위치 고유 식별자
|
||||
/// Returns: 상태 변경된 창고 위치 정보
|
||||
Future<Either<Failure, WarehouseLocation>> toggleWarehouseLocationStatus(int id);
|
||||
|
||||
/// 창고에 장비가 있는지 확인
|
||||
/// [id] 확인할 창고 위치 ID
|
||||
/// Returns: 장비 보유 여부 (삭제 가능 여부 판단용)
|
||||
Future<Either<Failure, bool>> hasEquipment(int id);
|
||||
|
||||
/// 창고별 장비 수량 조회
|
||||
/// [id] 창고 위치 ID
|
||||
/// Returns: 해당 창고에 보관 중인 장비 수량
|
||||
Future<Either<Failure, int>> getEquipmentCount(int id);
|
||||
|
||||
/// 창고별 장비 목록 조회
|
||||
/// [warehouseId] 창고 위치 ID
|
||||
/// [page] 페이지 번호
|
||||
/// [limit] 페이지당 항목 수
|
||||
/// Returns: 해당 창고에 보관 중인 장비 목록
|
||||
Future<Either<Failure, PaginatedResponse<dynamic>>> getEquipmentByWarehouse(
|
||||
int warehouseId, {
|
||||
int? page,
|
||||
int? limit,
|
||||
});
|
||||
|
||||
/// 창고 사용률 통계
|
||||
/// Returns: 창고별 사용률 (전체 용량 대비 사용 중인 용량)
|
||||
Future<Either<Failure, Map<int, double>>> getWarehouseUtilization();
|
||||
|
||||
/// 창고 유형별 통계
|
||||
/// Returns: 창고 유형별 개수 ('창고', '사무실', '출고지' 등)
|
||||
Future<Either<Failure, Map<String, int>>> getWarehouseCountByType();
|
||||
|
||||
/// 창고명 중복 체크
|
||||
/// [name] 체크할 창고명
|
||||
/// [excludeId] 체크에서 제외할 창고 ID (수정 시 현재 창고 제외용)
|
||||
/// Returns: 중복 여부 (true: 중복됨, false: 중복되지 않음)
|
||||
Future<Either<Failure, bool>> isDuplicateWarehouseName(String name, {int? excludeId});
|
||||
|
||||
/// 창고 검색 (자동완성용)
|
||||
/// [query] 검색 쿼리
|
||||
/// [limit] 결과 제한 수 (기본값: 10)
|
||||
/// Returns: 일치하는 창고 위치 목록
|
||||
Future<Either<Failure, List<WarehouseLocation>>> searchWarehouseLocations(String query, {int? limit});
|
||||
|
||||
/// 활성 창고 위치 목록 조회 (드롭다운용)
|
||||
/// 장비 등록 시 선택 가능한 활성 상태의 창고 위치만 조회
|
||||
/// Returns: 활성화된 창고 위치 목록
|
||||
Future<Either<Failure, List<WarehouseLocation>>> getActiveWarehouseLocations();
|
||||
|
||||
/// 창고 용량 및 사용량 업데이트
|
||||
/// [id] 창고 위치 ID
|
||||
/// [totalCapacity] 전체 용량
|
||||
/// [usedCapacity] 사용 중인 용량
|
||||
/// Returns: 업데이트된 창고 위치 정보
|
||||
Future<Either<Failure, WarehouseLocation>> updateWarehouseCapacity(
|
||||
int id,
|
||||
int totalCapacity,
|
||||
int usedCapacity,
|
||||
);
|
||||
}
|
||||
@@ -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