- 라이선스 모델 전면 개편 (상세 필드 추가, 계산 필드 구현) - API 응답 처리 개선 (HTTP 상태 코드 기반) - 장비 출고 폼 컨트롤러 추가 - 회사 지점 정보 모델 추가 - 공통 데이터 모델 구조 추가 - 전체 서비스 레이어 API 호출 방식 통일 - UI 컴포넌트 마이너 개선
191 lines
6.2 KiB
Dart
191 lines
6.2 KiB
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) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
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) {
|
|
// 주소 조합
|
|
final addressParts = <String>[];
|
|
if (dto.address != null && dto.address!.isNotEmpty) {
|
|
addressParts.add(dto.address!);
|
|
}
|
|
if (dto.city != null && dto.city!.isNotEmpty) {
|
|
addressParts.add(dto.city!);
|
|
}
|
|
if (dto.state != null && dto.state!.isNotEmpty) {
|
|
addressParts.add(dto.state!);
|
|
}
|
|
|
|
final address = Address(
|
|
zipCode: dto.postalCode ?? '',
|
|
region: dto.city ?? '',
|
|
detailAddress: addressParts.join(' '),
|
|
);
|
|
|
|
return WarehouseLocation(
|
|
id: dto.id,
|
|
name: dto.name,
|
|
address: address,
|
|
remark: dto.managerName != null ? '담당자: ${dto.managerName}' : 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;
|
|
}
|
|
}
|
|
} |