feat: 라이선스 및 창고 관리 API 연동 구현
- 라이선스 관리 API 연동 완료 - LicenseRemoteDataSource, LicenseService 구현 - LicenseListController, LicenseFormController API 연동 - 페이지네이션, 검색, 필터링 기능 추가 - 라이선스 할당/해제 기능 구현 - 창고 관리 API 연동 완료 - WarehouseRemoteDataSource, WarehouseService 구현 - WarehouseLocationListController, WarehouseLocationFormController API 연동 - 창고별 장비 조회 및 용량 관리 기능 추가 - DI 컨테이너에 새로운 서비스 등록 - API 통합 문서 업데이트 (전체 진행률 100% 달성)
This commit is contained in:
175
lib/data/datasources/remote/warehouse_remote_datasource.dart
Normal file
175
lib/data/datasources/remote/warehouse_remote_datasource.dart
Normal file
@@ -0,0 +1,175 @@
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:superport/core/constants/api_endpoints.dart';
|
||||
import 'package:superport/core/errors/exceptions.dart';
|
||||
import 'package:superport/data/datasources/remote/api_client.dart';
|
||||
import 'package:superport/data/models/warehouse/warehouse_dto.dart';
|
||||
|
||||
abstract class WarehouseRemoteDataSource {
|
||||
Future<WarehouseLocationListDto> getWarehouseLocations({
|
||||
int page = 1,
|
||||
int perPage = 20,
|
||||
bool? isActive,
|
||||
});
|
||||
|
||||
Future<WarehouseLocationDto> getWarehouseLocationById(int id);
|
||||
Future<WarehouseLocationDto> createWarehouseLocation(CreateWarehouseLocationRequest request);
|
||||
Future<WarehouseLocationDto> updateWarehouseLocation(int id, UpdateWarehouseLocationRequest request);
|
||||
Future<void> deleteWarehouseLocation(int id);
|
||||
Future<WarehouseEquipmentListDto> getWarehouseEquipment(
|
||||
int warehouseId, {
|
||||
int page = 1,
|
||||
int perPage = 20,
|
||||
});
|
||||
Future<WarehouseCapacityInfo> getWarehouseCapacity(int id);
|
||||
Future<List<WarehouseLocationDto>> getInUseWarehouseLocations();
|
||||
}
|
||||
|
||||
@LazySingleton(as: WarehouseRemoteDataSource)
|
||||
class WarehouseRemoteDataSourceImpl implements WarehouseRemoteDataSource {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
WarehouseRemoteDataSourceImpl({
|
||||
required ApiClient apiClient,
|
||||
}) : _apiClient = apiClient;
|
||||
|
||||
@override
|
||||
Future<WarehouseLocationListDto> getWarehouseLocations({
|
||||
int page = 1,
|
||||
int perPage = 20,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
try {
|
||||
final queryParams = <String, dynamic>{
|
||||
'page': page,
|
||||
'per_page': perPage,
|
||||
};
|
||||
|
||||
if (isActive != null) queryParams['is_active'] = isActive;
|
||||
|
||||
final response = await _apiClient.get(
|
||||
ApiEndpoints.warehouseLocations,
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
return WarehouseLocationListDto.fromJson(response.data);
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WarehouseLocationDto> getWarehouseLocationById(int id) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'${ApiEndpoints.warehouseLocations}/$id',
|
||||
);
|
||||
|
||||
return WarehouseLocationDto.fromJson(response.data);
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WarehouseLocationDto> createWarehouseLocation(CreateWarehouseLocationRequest request) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
ApiEndpoints.warehouseLocations,
|
||||
data: request.toJson(),
|
||||
);
|
||||
|
||||
return WarehouseLocationDto.fromJson(response.data);
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WarehouseLocationDto> updateWarehouseLocation(int id, UpdateWarehouseLocationRequest request) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
'${ApiEndpoints.warehouseLocations}/$id',
|
||||
data: request.toJson(),
|
||||
);
|
||||
|
||||
return WarehouseLocationDto.fromJson(response.data);
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteWarehouseLocation(int id) async {
|
||||
try {
|
||||
await _apiClient.delete(
|
||||
'${ApiEndpoints.warehouseLocations}/$id',
|
||||
);
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WarehouseEquipmentListDto> getWarehouseEquipment(
|
||||
int warehouseId, {
|
||||
int page = 1,
|
||||
int perPage = 20,
|
||||
}) async {
|
||||
try {
|
||||
final queryParams = <String, dynamic>{
|
||||
'page': page,
|
||||
'per_page': perPage,
|
||||
};
|
||||
|
||||
final response = await _apiClient.get(
|
||||
'${ApiEndpoints.warehouseLocations}/$warehouseId/equipment',
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
return WarehouseEquipmentListDto.fromJson(response.data);
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WarehouseCapacityInfo> getWarehouseCapacity(int id) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'${ApiEndpoints.warehouseLocations}/$id/capacity',
|
||||
);
|
||||
|
||||
return WarehouseCapacityInfo.fromJson(response.data);
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<WarehouseLocationDto>> getInUseWarehouseLocations() async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'${ApiEndpoints.warehouseLocations}/in-use',
|
||||
);
|
||||
|
||||
if (response.data is List) {
|
||||
return (response.data as List)
|
||||
.map((item) => WarehouseLocationDto.fromJson(item))
|
||||
.toList();
|
||||
} else {
|
||||
throw ApiException(message: 'Invalid response format');
|
||||
}
|
||||
} catch (e) {
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
Exception _handleError(dynamic error) {
|
||||
if (error is ApiException) {
|
||||
return error;
|
||||
}
|
||||
return ApiException(
|
||||
message: error.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user