주요 변경사항: - CLAUDE.md: 프로젝트 규칙 v2.0으로 업데이트, 아키텍처 명확화 - 불필요한 문서 제거: NEXT_TASKS.md, TEST_PROGRESS.md, test_results 파일들 - 테스트 시스템 개선: 실제 API 테스트 스위트 추가 (15개 새 테스트 파일) - License 관리: DTO 모델 개선, API 응답 처리 최적화 - 에러 처리: Interceptor 로직 강화, 상세 로깅 추가 - Company/User/Warehouse 테스트: 자동화 테스트 안정성 향상 - Phone Utils: 전화번호 포맷팅 로직 개선 - Overview Controller: 대시보드 데이터 로딩 최적화 - Analysis Options: Flutter 린트 규칙 추가 테스트 개선: - company_real_api_test.dart: 실제 API 회사 관리 테스트 - equipment_in/out_real_api_test.dart: 장비 입출고 API 테스트 - license_real_api_test.dart: 라이선스 관리 API 테스트 - user_real_api_test.dart: 사용자 관리 API 테스트 - warehouse_location_real_api_test.dart: 창고 위치 API 테스트 - filter_sort_test.dart: 필터링/정렬 기능 테스트 - pagination_test.dart: 페이지네이션 테스트 - interactive_search_test.dart: 검색 기능 테스트 - overview_dashboard_test.dart: 대시보드 통합 테스트 코드 품질: - 모든 서비스에 에러 처리 강화 - DTO 모델 null safety 개선 - 테스트 커버리지 확대 - 불필요한 로그 파일 제거로 리포지토리 정리 Co-Authored-By: Claude <noreply@anthropic.com>
196 lines
6.5 KiB
Dart
196 lines
6.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
import 'package:superport/core/errors/exceptions.dart';
|
|
import 'package:superport/core/errors/failures.dart';
|
|
import 'package:superport/data/datasources/remote/warehouse_remote_datasource.dart';
|
|
import 'package:superport/data/models/warehouse/warehouse_dto.dart';
|
|
import 'package:superport/models/address_model.dart';
|
|
import 'package:superport/models/warehouse_location_model.dart';
|
|
|
|
@lazySingleton
|
|
class WarehouseService {
|
|
final WarehouseRemoteDataSource _remoteDataSource = GetIt.instance<WarehouseRemoteDataSource>();
|
|
|
|
// 창고 위치 목록 조회
|
|
Future<List<WarehouseLocation>> getWarehouseLocations({
|
|
int page = 1,
|
|
int perPage = 20,
|
|
bool? isActive,
|
|
}) async {
|
|
try {
|
|
final response = await _remoteDataSource.getWarehouseLocations(
|
|
page: page,
|
|
perPage: perPage,
|
|
isActive: isActive,
|
|
);
|
|
|
|
return response.items.map((dto) => _convertDtoToWarehouseLocation(dto)).toList();
|
|
} on ApiException catch (e) {
|
|
debugPrint('[WarehouseService] ApiException: ${e.message}');
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e, stackTrace) {
|
|
debugPrint('[WarehouseService] Error loading warehouse locations: $e');
|
|
debugPrint('[WarehouseService] Stack trace: $stackTrace');
|
|
throw ServerFailure(message: '창고 위치 목록을 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 창고 위치 상세 조회
|
|
Future<WarehouseLocation> getWarehouseLocationById(int id) async {
|
|
try {
|
|
final dto = await _remoteDataSource.getWarehouseLocationById(id);
|
|
return _convertDtoToWarehouseLocation(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '창고 위치 정보를 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 창고 위치 생성
|
|
Future<WarehouseLocation> createWarehouseLocation(WarehouseLocation location) async {
|
|
try {
|
|
final request = CreateWarehouseLocationRequest(
|
|
name: location.name,
|
|
address: location.address.detailAddress,
|
|
city: location.address.region,
|
|
postalCode: location.address.zipCode,
|
|
country: 'KR', // 기본값
|
|
);
|
|
|
|
final dto = await _remoteDataSource.createWarehouseLocation(request);
|
|
return _convertDtoToWarehouseLocation(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '창고 위치 생성에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 창고 위치 수정
|
|
Future<WarehouseLocation> updateWarehouseLocation(WarehouseLocation location) async {
|
|
try {
|
|
final request = UpdateWarehouseLocationRequest(
|
|
name: location.name,
|
|
address: location.address.detailAddress,
|
|
city: location.address.region,
|
|
postalCode: location.address.zipCode,
|
|
);
|
|
|
|
final dto = await _remoteDataSource.updateWarehouseLocation(location.id, request);
|
|
return _convertDtoToWarehouseLocation(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '창고 위치 수정에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 창고 위치 삭제
|
|
Future<void> deleteWarehouseLocation(int id) async {
|
|
try {
|
|
await _remoteDataSource.deleteWarehouseLocation(id);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '창고 위치 삭제에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 창고별 장비 목록 조회
|
|
Future<List<Map<String, dynamic>>> getWarehouseEquipment(
|
|
int warehouseId, {
|
|
int page = 1,
|
|
int perPage = 20,
|
|
}) async {
|
|
try {
|
|
final response = await _remoteDataSource.getWarehouseEquipment(
|
|
warehouseId,
|
|
page: page,
|
|
perPage: perPage,
|
|
);
|
|
|
|
return response.items.map((dto) => {
|
|
'id': dto.id,
|
|
'equipmentNumber': dto.equipmentNumber,
|
|
'manufacturer': dto.manufacturer,
|
|
'equipmentName': dto.equipmentName,
|
|
'serialNumber': dto.serialNumber,
|
|
'quantity': dto.quantity,
|
|
'status': dto.status,
|
|
'storedAt': dto.storedAt,
|
|
}).toList();
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '창고 장비 목록을 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 창고 용량 정보 조회
|
|
Future<WarehouseCapacityInfo> getWarehouseCapacity(int id) async {
|
|
try {
|
|
return await _remoteDataSource.getWarehouseCapacity(id);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '창고 용량 정보를 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 사용 중인 창고 위치 목록 조회
|
|
Future<List<WarehouseLocation>> getInUseWarehouseLocations() async {
|
|
try {
|
|
final dtos = await _remoteDataSource.getInUseWarehouseLocations();
|
|
return dtos.map((dto) => _convertDtoToWarehouseLocation(dto)).toList();
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '사용 중인 창고 위치를 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// DTO를 Flutter 모델로 변환
|
|
WarehouseLocation _convertDtoToWarehouseLocation(WarehouseLocationDto dto) {
|
|
// API에 주소 정보가 없으므로 기본값 사용
|
|
final address = Address(
|
|
zipCode: dto.postalCode ?? '',
|
|
region: dto.city ?? '',
|
|
detailAddress: dto.address ?? '주소 정보 없음',
|
|
);
|
|
|
|
// 담당자 정보 조합
|
|
final remarkParts = <String>[];
|
|
if (dto.code != null) {
|
|
remarkParts.add('코드: ${dto.code}');
|
|
}
|
|
if (dto.managerName != null) {
|
|
remarkParts.add('담당자: ${dto.managerName}');
|
|
}
|
|
if (dto.managerPhone != null) {
|
|
remarkParts.add('연락처: ${dto.managerPhone}');
|
|
}
|
|
|
|
return WarehouseLocation(
|
|
id: dto.id,
|
|
name: dto.name,
|
|
address: address,
|
|
remark: remarkParts.isNotEmpty ? remarkParts.join(', ') : null,
|
|
);
|
|
}
|
|
|
|
// 페이지네이션 정보
|
|
Future<int> getTotalWarehouseLocations({bool? isActive}) async {
|
|
try {
|
|
final response = await _remoteDataSource.getWarehouseLocations(
|
|
page: 1,
|
|
perPage: 1,
|
|
isActive: isActive,
|
|
);
|
|
return response.total;
|
|
} catch (e) {
|
|
return 0;
|
|
}
|
|
}
|
|
} |