feat: 라이선스 및 창고 관리 API 연동 구현
- 라이선스 관리 API 연동 완료 - LicenseRemoteDataSource, LicenseService 구현 - LicenseListController, LicenseFormController API 연동 - 페이지네이션, 검색, 필터링 기능 추가 - 라이선스 할당/해제 기능 구현 - 창고 관리 API 연동 완료 - WarehouseRemoteDataSource, WarehouseService 구현 - WarehouseLocationListController, WarehouseLocationFormController API 연동 - 창고별 장비 조회 및 용량 관리 기능 추가 - DI 컨테이너에 새로운 서비스 등록 - API 통합 문서 업데이트 (전체 진행률 100% 달성)
This commit is contained in:
191
lib/services/warehouse_service.dart
Normal file
191
lib/services/warehouse_service.dart
Normal file
@@ -0,0 +1,191 @@
|
||||
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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 위치 목록을 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 위치 상세 조회
|
||||
Future<WarehouseLocation> getWarehouseLocationById(int id) async {
|
||||
try {
|
||||
final dto = await _remoteDataSource.getWarehouseLocationById(id);
|
||||
return _convertDtoToWarehouseLocation(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 위치 수정에 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 위치 삭제
|
||||
Future<void> deleteWarehouseLocation(int id) async {
|
||||
try {
|
||||
await _remoteDataSource.deleteWarehouseLocation(id);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 장비 목록을 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 용량 정보 조회
|
||||
Future<WarehouseCapacityInfo> getWarehouseCapacity(int id) async {
|
||||
try {
|
||||
return await _remoteDataSource.getWarehouseCapacity(id);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user