- CLAUDE.md 대폭 개선: 개발 가이드라인 및 프로젝트 상태 문서화 - 백엔드 API 통합: 모든 엔티티 간 Foreign Key 관계 완벽 구현 - UI 일관성 강화: shadcn_ui 컴포넌트 표준화 적용 - 데이터 모델 개선: DTO 및 모델 클래스 백엔드 스키마와 100% 일치 - 사용자 관리: 회사 연결, 중복 검사, 입력 검증 기능 추가 - 창고 관리: 우편번호 연결, 중복 검사 기능 강화 - 회사 관리: 우편번호 연결, 중복 검사 로직 구현 - 장비 관리: 불필요한 카테고리 필드 제거, 벤더-모델 관계 정리 - 우편번호 시스템: 검색 다이얼로그 Provider 버그 수정 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
252 lines
7.7 KiB
Dart
252 lines
7.7 KiB
Dart
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,
|
|
String? search,
|
|
bool includeInactive = false,
|
|
});
|
|
|
|
Future<WarehouseDto> getWarehouseLocationById(int id);
|
|
Future<WarehouseDto> createWarehouseLocation(WarehouseRequestDto request);
|
|
Future<WarehouseDto> updateWarehouseLocation(int id, WarehouseUpdateRequestDto request);
|
|
Future<void> deleteWarehouseLocation(int id);
|
|
Future<WarehouseEquipmentListDto> getWarehouseEquipment(
|
|
int warehouseId, {
|
|
int page = 1,
|
|
int perPage = 20,
|
|
});
|
|
Future<WarehouseCapacityInfo> getWarehouseCapacity(int id);
|
|
Future<List<WarehouseDto>> 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,
|
|
String? search,
|
|
bool includeInactive = false,
|
|
}) async {
|
|
try {
|
|
final queryParams = <String, dynamic>{
|
|
'page': page,
|
|
'per_page': perPage,
|
|
};
|
|
|
|
if (isActive != null) queryParams['is_active'] = isActive;
|
|
if (search != null && search.isNotEmpty) queryParams['search'] = search;
|
|
queryParams['include_inactive'] = includeInactive;
|
|
|
|
final response = await _apiClient.get(
|
|
ApiEndpoints.warehouses,
|
|
queryParameters: queryParams,
|
|
);
|
|
|
|
// 백엔드 응답을 직접 처리 (success 필드 없음)
|
|
if (response.data != null && response.data['data'] != null) {
|
|
final List<dynamic> dataList = response.data['data'];
|
|
|
|
final listData = {
|
|
'items': dataList,
|
|
'total': response.data['total'] ?? 0,
|
|
'page': response.data['page'] ?? 1,
|
|
'per_page': response.data['page_size'] ?? 20,
|
|
'total_pages': response.data['total_pages'] ?? 1,
|
|
};
|
|
|
|
return WarehouseLocationListDto.fromJson(listData);
|
|
} else {
|
|
throw ApiException(
|
|
message: 'Failed to fetch warehouse locations',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<WarehouseDto> getWarehouseLocationById(int id) async {
|
|
try {
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.warehouses}/$id',
|
|
);
|
|
|
|
// 백엔드가 직접 데이터를 반환하는 경우 처리
|
|
if (response.data != null) {
|
|
// success 필드가 없으면 직접 데이터로 간주
|
|
if (response.data is Map && !response.data.containsKey('success')) {
|
|
return WarehouseDto.fromJson(response.data);
|
|
}
|
|
// success 필드가 있는 경우 기존 방식 처리
|
|
else if (response.data['success'] == true && response.data['data'] != null) {
|
|
return WarehouseDto.fromJson(response.data['data']);
|
|
}
|
|
}
|
|
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch warehouse location',
|
|
);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<WarehouseDto> createWarehouseLocation(WarehouseRequestDto request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
ApiEndpoints.warehouses,
|
|
data: request.toJson(),
|
|
);
|
|
|
|
// 백엔드가 직접 데이터를 반환하는 경우 처리
|
|
if (response.data != null) {
|
|
// success 필드가 없으면 직접 데이터로 간주
|
|
if (response.data is Map && !response.data.containsKey('success')) {
|
|
return WarehouseDto.fromJson(response.data);
|
|
}
|
|
// success 필드가 있는 경우 기존 방식 처리
|
|
else if (response.data['success'] == true && response.data['data'] != null) {
|
|
return WarehouseDto.fromJson(response.data['data']);
|
|
}
|
|
}
|
|
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to create warehouse location',
|
|
);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<WarehouseDto> updateWarehouseLocation(int id, WarehouseUpdateRequestDto request) async {
|
|
try {
|
|
final response = await _apiClient.put(
|
|
'${ApiEndpoints.warehouses}/$id',
|
|
data: request.toJson(),
|
|
);
|
|
|
|
// 백엔드가 직접 데이터를 반환하는 경우 처리
|
|
if (response.data != null) {
|
|
// success 필드가 없으면 직접 데이터로 간주
|
|
if (response.data is Map && !response.data.containsKey('success')) {
|
|
return WarehouseDto.fromJson(response.data);
|
|
}
|
|
// success 필드가 있는 경우 기존 방식 처리
|
|
else if (response.data['success'] == true && response.data['data'] != null) {
|
|
return WarehouseDto.fromJson(response.data['data']);
|
|
}
|
|
}
|
|
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to update warehouse location',
|
|
);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> deleteWarehouseLocation(int id) async {
|
|
try {
|
|
await _apiClient.delete(
|
|
'${ApiEndpoints.warehouses}/$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,
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return WarehouseEquipmentListDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch warehouse equipment',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<WarehouseCapacityInfo> getWarehouseCapacity(int id) async {
|
|
try {
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.warehouseLocations}/$id/capacity',
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return WarehouseCapacityInfo.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch warehouse capacity',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<List<WarehouseDto>> getInUseWarehouseLocations() async {
|
|
try {
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.warehouses}/in-use',
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] is List) {
|
|
return (response.data['data'] as List)
|
|
.map((item) => WarehouseDto.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(),
|
|
);
|
|
}
|
|
} |