refactor: Clean Architecture 적용 및 코드베이스 전면 리팩토링
## 주요 변경사항 ### 아키텍처 개선 - Clean Architecture 패턴 적용 (Domain, Data, Presentation 레이어 분리) - Use Case 패턴 도입으로 비즈니스 로직 캡슐화 - Repository 패턴으로 데이터 접근 추상화 - 의존성 주입 구조 개선 ### 상태 관리 최적화 - 모든 Controller에서 불필요한 상태 관리 로직 제거 - 페이지네이션 로직 통일 및 간소화 - 에러 처리 로직 개선 (에러 메시지 한글화) - 로딩 상태 관리 최적화 ### Mock 서비스 제거 - MockDataService 완전 제거 - 모든 화면을 실제 API 전용으로 전환 - 불필요한 Mock 관련 코드 정리 ### UI/UX 개선 - Overview 화면 대시보드 기능 강화 - 라이선스 만료 알림 위젯 추가 - 사이드바 네비게이션 개선 - 일관된 UI 컴포넌트 사용 ### 코드 품질 - 중복 코드 제거 및 함수 추출 - 파일별 책임 분리 명확화 - 테스트 코드 업데이트 ## 영향 범위 - 모든 화면의 Controller 리팩토링 - API 통신 레이어 구조 개선 - 에러 처리 및 로깅 시스템 개선 ## 향후 계획 - 단위 테스트 커버리지 확대 - 통합 테스트 시나리오 추가 - 성능 모니터링 도구 통합
This commit is contained in:
123
lib/domain/usecases/equipment/equipment_in_usecase.dart
Normal file
123
lib/domain/usecases/equipment/equipment_in_usecase.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
117
lib/domain/usecases/equipment/equipment_out_usecase.dart
Normal file
117
lib/domain/usecases/equipment/equipment_out_usecase.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/equipment_service.dart';
|
||||
import '../../../data/models/equipment/equipment_out_request.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;
|
||||
}
|
||||
}
|
||||
5
lib/domain/usecases/equipment/equipment_usecases.dart
Normal file
5
lib/domain/usecases/equipment/equipment_usecases.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
/// Equipment 도메인 UseCase 모음
|
||||
export 'get_equipments_usecase.dart';
|
||||
export 'equipment_in_usecase.dart';
|
||||
export 'equipment_out_usecase.dart';
|
||||
export 'get_equipment_history_usecase.dart';
|
||||
@@ -0,0 +1,90 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/equipment_service.dart';
|
||||
import '../../../data/models/equipment/equipment_history_dto.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 장비 이력 조회 파라미터
|
||||
class GetEquipmentHistoryParams {
|
||||
final int equipmentId;
|
||||
final DateTime? startDate;
|
||||
final DateTime? endDate;
|
||||
final String? historyType; // 'in', 'out', 'maintenance', 'disposal'
|
||||
|
||||
const GetEquipmentHistoryParams({
|
||||
required this.equipmentId,
|
||||
this.startDate,
|
||||
this.endDate,
|
||||
this.historyType,
|
||||
});
|
||||
}
|
||||
|
||||
/// 장비 이력 조회 UseCase
|
||||
/// 특정 장비의 입출고 및 상태 변경 이력 조회
|
||||
class GetEquipmentHistoryUseCase extends UseCase<List<EquipmentHistoryDto>, GetEquipmentHistoryParams> {
|
||||
final EquipmentService _equipmentService;
|
||||
|
||||
GetEquipmentHistoryUseCase(this._equipmentService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<EquipmentHistoryDto>>> call(GetEquipmentHistoryParams params) async {
|
||||
try {
|
||||
// 날짜 유효성 검증
|
||||
if (params.startDate != null && params.endDate != null) {
|
||||
if (params.startDate!.isAfter(params.endDate!)) {
|
||||
return Left(ValidationFailure(
|
||||
message: '시작일이 종료일보다 늦을 수 없습니다.',
|
||||
errors: {'date': '날짜 범위를 확인해주세요.'},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// 이력 타입 유효성 검증
|
||||
if (params.historyType != null &&
|
||||
!['in', 'out', 'maintenance', 'disposal'].contains(params.historyType)) {
|
||||
return Left(ValidationFailure(
|
||||
message: '올바르지 않은 이력 타입입니다.',
|
||||
errors: {'historyType': '유효한 이력 타입을 선택해주세요.'},
|
||||
));
|
||||
}
|
||||
|
||||
final history = await _equipmentService.getEquipmentHistory(params.equipmentId);
|
||||
|
||||
// 필터링 적용
|
||||
List<EquipmentHistoryDto> filteredHistory = history;
|
||||
|
||||
if (params.historyType != null) {
|
||||
filteredHistory = filteredHistory
|
||||
.where((h) => h.transactionType == params.historyType)
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (params.startDate != null) {
|
||||
filteredHistory = filteredHistory
|
||||
.where((h) => h.createdAt.isAfter(params.startDate!))
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (params.endDate != null) {
|
||||
filteredHistory = filteredHistory
|
||||
.where((h) => h.createdAt.isBefore(params.endDate!))
|
||||
.toList();
|
||||
}
|
||||
|
||||
return Right(filteredHistory);
|
||||
} catch (e) {
|
||||
if (e.toString().contains('찾을 수 없')) {
|
||||
return Left(ValidationFailure(
|
||||
message: '장비를 찾을 수 없습니다.',
|
||||
code: 'EQUIPMENT_NOT_FOUND',
|
||||
originalError: e,
|
||||
));
|
||||
} else {
|
||||
return Left(ServerFailure(
|
||||
message: '장비 이력을 조회하는 중 오류가 발생했습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
lib/domain/usecases/equipment/get_equipments_usecase.dart
Normal file
69
lib/domain/usecases/equipment/get_equipments_usecase.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/equipment_service.dart';
|
||||
import '../../../models/equipment_unified_model.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 장비 목록 조회 파라미터
|
||||
class GetEquipmentsParams {
|
||||
final int page;
|
||||
final int perPage;
|
||||
final String? status;
|
||||
final int? companyId;
|
||||
final int? warehouseLocationId;
|
||||
final String? search;
|
||||
|
||||
const GetEquipmentsParams({
|
||||
this.page = 1,
|
||||
this.perPage = 20,
|
||||
this.status,
|
||||
this.companyId,
|
||||
this.warehouseLocationId,
|
||||
this.search,
|
||||
});
|
||||
}
|
||||
|
||||
/// 장비 목록 조회 UseCase
|
||||
/// 필터링 및 페이지네이션 지원
|
||||
class GetEquipmentsUseCase extends UseCase<List<Equipment>, GetEquipmentsParams> {
|
||||
final EquipmentService _equipmentService;
|
||||
|
||||
GetEquipmentsUseCase(this._equipmentService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Equipment>>> call(GetEquipmentsParams params) async {
|
||||
try {
|
||||
// 상태 유효성 검증
|
||||
if (params.status != null &&
|
||||
!['available', 'in_use', 'maintenance', 'disposed', 'rented'].contains(params.status)) {
|
||||
return Left(ValidationFailure(
|
||||
message: '올바르지 않은 장비 상태입니다.',
|
||||
errors: {'status': '유효한 상태를 선택해주세요.'},
|
||||
));
|
||||
}
|
||||
|
||||
final equipments = await _equipmentService.getEquipments(
|
||||
page: params.page,
|
||||
perPage: params.perPage,
|
||||
status: params.status,
|
||||
companyId: params.companyId,
|
||||
warehouseLocationId: params.warehouseLocationId,
|
||||
search: params.search,
|
||||
);
|
||||
|
||||
return Right(equipments);
|
||||
} catch (e) {
|
||||
if (e.toString().contains('네트워크')) {
|
||||
return Left(NetworkFailure(
|
||||
message: '네트워크 연결을 확인해주세요.',
|
||||
originalError: e,
|
||||
));
|
||||
} else {
|
||||
return Left(ServerFailure(
|
||||
message: '장비 목록을 불러오는 중 오류가 발생했습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user