## 주요 변경사항 ### 아키텍처 개선 - Clean Architecture 패턴 적용 (Domain, Data, Presentation 레이어 분리) - Use Case 패턴 도입으로 비즈니스 로직 캡슐화 - Repository 패턴으로 데이터 접근 추상화 - 의존성 주입 구조 개선 ### 상태 관리 최적화 - 모든 Controller에서 불필요한 상태 관리 로직 제거 - 페이지네이션 로직 통일 및 간소화 - 에러 처리 로직 개선 (에러 메시지 한글화) - 로딩 상태 관리 최적화 ### Mock 서비스 제거 - MockDataService 완전 제거 - 모든 화면을 실제 API 전용으로 전환 - 불필요한 Mock 관련 코드 정리 ### UI/UX 개선 - Overview 화면 대시보드 기능 강화 - 라이선스 만료 알림 위젯 추가 - 사이드바 네비게이션 개선 - 일관된 UI 컴포넌트 사용 ### 코드 품질 - 중복 코드 제거 및 함수 추출 - 파일별 책임 분리 명확화 - 테스트 코드 업데이트 ## 영향 범위 - 모든 화면의 Controller 리팩토링 - API 통신 레이어 구조 개선 - 에러 처리 및 로깅 시스템 개선 ## 향후 계획 - 단위 테스트 커버리지 확대 - 통합 테스트 시나리오 추가 - 성능 모니터링 도구 통합
123 lines
3.9 KiB
Dart
123 lines
3.9 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import '../../../services/equipment_service.dart';
|
|
import '../../../data/models/equipment/equipment_in_request.dart';
|
|
import '../../../data/models/equipment/equipment_io_response.dart';
|
|
import '../../../core/errors/failures.dart';
|
|
import '../base_usecase.dart';
|
|
|
|
/// 장비 입고 파라미터
|
|
class EquipmentInParams {
|
|
final int equipmentId;
|
|
final int warehouseLocationId;
|
|
final int quantity;
|
|
final String serialNumber;
|
|
final String? remark;
|
|
final DateTime? purchaseDate;
|
|
final double? purchasePrice;
|
|
|
|
const EquipmentInParams({
|
|
required this.equipmentId,
|
|
required this.warehouseLocationId,
|
|
required this.quantity,
|
|
required this.serialNumber,
|
|
this.remark,
|
|
this.purchaseDate,
|
|
this.purchasePrice,
|
|
});
|
|
}
|
|
|
|
/// 장비 입고 UseCase
|
|
/// 새로운 장비를 창고에 입고 처리
|
|
class EquipmentInUseCase extends UseCase<EquipmentIoResponse, EquipmentInParams> {
|
|
final EquipmentService _equipmentService;
|
|
|
|
EquipmentInUseCase(this._equipmentService);
|
|
|
|
@override
|
|
Future<Either<Failure, EquipmentIoResponse>> call(EquipmentInParams params) async {
|
|
try {
|
|
// 유효성 검증
|
|
final validationResult = _validateInput(params);
|
|
if (validationResult != null) {
|
|
return Left(validationResult);
|
|
}
|
|
|
|
// 시리얼 번호 중복 체크 (프론트엔드 임시 로직)
|
|
// TODO: 백엔드 API 구현 후 제거
|
|
|
|
final response = await _equipmentService.equipmentIn(
|
|
equipmentId: params.equipmentId,
|
|
quantity: params.quantity,
|
|
warehouseLocationId: params.warehouseLocationId,
|
|
notes: params.remark,
|
|
);
|
|
|
|
return Right(response);
|
|
} catch (e) {
|
|
if (e.toString().contains('시리얼')) {
|
|
return Left(ValidationFailure(
|
|
message: '이미 등록된 시리얼 번호입니다.',
|
|
code: 'DUPLICATE_SERIAL',
|
|
errors: {'serialNumber': '중복된 시리얼 번호입니다.'},
|
|
originalError: e,
|
|
));
|
|
} else if (e.toString().contains('재고')) {
|
|
return Left(ValidationFailure(
|
|
message: '재고 수량이 부족합니다.',
|
|
code: 'INSUFFICIENT_STOCK',
|
|
originalError: e,
|
|
));
|
|
} else if (e.toString().contains('권한')) {
|
|
return Left(PermissionFailure(
|
|
message: '장비 입고 권한이 없습니다.',
|
|
code: 'PERMISSION_DENIED',
|
|
originalError: e,
|
|
));
|
|
} else {
|
|
return Left(ServerFailure(
|
|
message: '장비 입고 처리 중 오류가 발생했습니다.',
|
|
originalError: e,
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
ValidationFailure? _validateInput(EquipmentInParams params) {
|
|
final errors = <String, String>{};
|
|
|
|
// 수량 검증
|
|
if (params.quantity <= 0) {
|
|
errors['quantity'] = '수량은 1개 이상이어야 합니다.';
|
|
}
|
|
if (params.quantity > 999) {
|
|
errors['quantity'] = '한 번에 입고 가능한 최대 수량은 999개입니다.';
|
|
}
|
|
|
|
// 시리얼 번호 검증
|
|
if (params.serialNumber.isEmpty) {
|
|
errors['serialNumber'] = '시리얼 번호를 입력해주세요.';
|
|
}
|
|
if (!RegExp(r'^[A-Za-z0-9-]+$').hasMatch(params.serialNumber)) {
|
|
errors['serialNumber'] = '시리얼 번호는 영문, 숫자, 하이픈만 사용 가능합니다.';
|
|
}
|
|
|
|
// 구매 가격 검증 (선택사항)
|
|
if (params.purchasePrice != null && params.purchasePrice! < 0) {
|
|
errors['purchasePrice'] = '구매 가격은 0 이상이어야 합니다.';
|
|
}
|
|
|
|
// 구매 날짜 검증 (선택사항)
|
|
if (params.purchaseDate != null && params.purchaseDate!.isAfter(DateTime.now())) {
|
|
errors['purchaseDate'] = '구매 날짜는 미래 날짜일 수 없습니다.';
|
|
}
|
|
|
|
if (errors.isNotEmpty) {
|
|
return ValidationFailure(
|
|
message: '입력값을 확인해주세요.',
|
|
errors: errors,
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
} |