- 모든 *_redesign.dart 파일을 기본 화면 파일로 통합 - 백업용 컨트롤러 파일들 제거 (*_controller.backup.dart) - 사용하지 않는 예제 및 테스트 파일 제거 - Clean Architecture 적용 후 남은 정리 작업 완료 - 테스트 코드 정리 및 구조 개선 준비 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
122 lines
3.8 KiB
Dart
122 lines
3.8 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import '../../../services/equipment_service.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;
|
|
}
|
|
} |