- 모든 *_redesign.dart 파일을 기본 화면 파일로 통합 - 백업용 컨트롤러 파일들 제거 (*_controller.backup.dart) - 사용하지 않는 예제 및 테스트 파일 제거 - Clean Architecture 적용 후 남은 정리 작업 완료 - 테스트 코드 정리 및 구조 개선 준비 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
116 lines
3.6 KiB
Dart
116 lines
3.6 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 EquipmentOutParams {
|
|
final int equipmentInId;
|
|
final int companyId;
|
|
final int quantity;
|
|
final String? remark;
|
|
final String? recipientName;
|
|
final String? recipientPhone;
|
|
final DateTime? deliveryDate;
|
|
|
|
const EquipmentOutParams({
|
|
required this.equipmentInId,
|
|
required this.companyId,
|
|
required this.quantity,
|
|
this.remark,
|
|
this.recipientName,
|
|
this.recipientPhone,
|
|
this.deliveryDate,
|
|
});
|
|
}
|
|
|
|
/// 장비 출고 UseCase
|
|
/// 창고에서 회사로 장비 출고 처리
|
|
class EquipmentOutUseCase extends UseCase<EquipmentIoResponse, EquipmentOutParams> {
|
|
final EquipmentService _equipmentService;
|
|
|
|
EquipmentOutUseCase(this._equipmentService);
|
|
|
|
@override
|
|
Future<Either<Failure, EquipmentIoResponse>> call(EquipmentOutParams params) async {
|
|
try {
|
|
// 유효성 검증
|
|
final validationResult = _validateInput(params);
|
|
if (validationResult != null) {
|
|
return Left(validationResult);
|
|
}
|
|
|
|
final response = await _equipmentService.equipmentOut(
|
|
equipmentId: params.equipmentInId, // equipmentInId를 equipmentId로 사용
|
|
quantity: params.quantity,
|
|
companyId: params.companyId,
|
|
notes: params.remark,
|
|
);
|
|
|
|
return Right(response);
|
|
} catch (e) {
|
|
if (e.toString().contains('재고')) {
|
|
return Left(ValidationFailure(
|
|
message: '출고 가능한 재고가 부족합니다.',
|
|
code: 'INSUFFICIENT_STOCK',
|
|
originalError: e,
|
|
));
|
|
} else if (e.toString().contains('찾을 수 없')) {
|
|
return Left(ValidationFailure(
|
|
message: '장비 정보를 찾을 수 없습니다.',
|
|
code: 'EQUIPMENT_NOT_FOUND',
|
|
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(EquipmentOutParams params) {
|
|
final errors = <String, String>{};
|
|
|
|
// 수량 검증
|
|
if (params.quantity <= 0) {
|
|
errors['quantity'] = '출고 수량은 1개 이상이어야 합니다.';
|
|
}
|
|
if (params.quantity > 999) {
|
|
errors['quantity'] = '한 번에 출고 가능한 최대 수량은 999개입니다.';
|
|
}
|
|
|
|
// 수령자 정보 검증 (선택사항이지만 제공된 경우)
|
|
if (params.recipientName != null && params.recipientName!.isEmpty) {
|
|
errors['recipientName'] = '수령자 이름을 입력해주세요.';
|
|
}
|
|
|
|
if (params.recipientPhone != null && params.recipientPhone!.isNotEmpty) {
|
|
if (!RegExp(r'^01[0-9]{1}-?[0-9]{4}-?[0-9]{4}$').hasMatch(params.recipientPhone!)) {
|
|
errors['recipientPhone'] = '올바른 전화번호 형식이 아닙니다.';
|
|
}
|
|
}
|
|
|
|
// 배송 날짜 검증 (선택사항)
|
|
if (params.deliveryDate != null && params.deliveryDate!.isBefore(DateTime.now().subtract(Duration(days: 1)))) {
|
|
errors['deliveryDate'] = '배송 날짜는 과거 날짜일 수 없습니다.';
|
|
}
|
|
|
|
if (errors.isNotEmpty) {
|
|
return ValidationFailure(
|
|
message: '입력값을 확인해주세요.',
|
|
errors: errors,
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
} |