주요 변경사항: - 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>
293 lines
9.5 KiB
Dart
293 lines
9.5 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:get_it/get_it.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/equipment/equipment_history_dto.dart';
|
|
import 'package:superport/data/models/equipment/equipment_in_request.dart';
|
|
import 'package:superport/data/models/equipment/equipment_io_response.dart';
|
|
import 'package:superport/data/models/equipment/equipment_list_dto.dart';
|
|
import 'package:superport/data/models/equipment/equipment_out_request.dart';
|
|
import 'package:superport/data/models/equipment/equipment_request.dart';
|
|
import 'package:superport/data/models/equipment/equipment_response.dart';
|
|
|
|
abstract class EquipmentRemoteDataSource {
|
|
Future<List<EquipmentListDto>> getEquipments({
|
|
int page = 1,
|
|
int perPage = 20,
|
|
String? status,
|
|
int? companyId,
|
|
int? warehouseLocationId,
|
|
String? search,
|
|
});
|
|
|
|
Future<EquipmentResponse> createEquipment(CreateEquipmentRequest request);
|
|
|
|
Future<EquipmentResponse> getEquipmentDetail(int id);
|
|
|
|
Future<EquipmentResponse> updateEquipment(int id, UpdateEquipmentRequest request);
|
|
|
|
Future<void> deleteEquipment(int id);
|
|
|
|
Future<EquipmentResponse> changeEquipmentStatus(int id, String status, String? reason);
|
|
|
|
Future<EquipmentHistoryDto> addEquipmentHistory(int equipmentId, CreateHistoryRequest request);
|
|
|
|
Future<List<EquipmentHistoryDto>> getEquipmentHistory(int equipmentId, {int page = 1, int perPage = 20});
|
|
|
|
Future<EquipmentIoResponse> equipmentIn(EquipmentInRequest request);
|
|
|
|
Future<EquipmentIoResponse> equipmentOut(EquipmentOutRequest request);
|
|
}
|
|
|
|
class EquipmentRemoteDataSourceImpl implements EquipmentRemoteDataSource {
|
|
final ApiClient _apiClient = GetIt.instance<ApiClient>();
|
|
|
|
@override
|
|
Future<List<EquipmentListDto>> getEquipments({
|
|
int page = 1,
|
|
int perPage = 20,
|
|
String? status,
|
|
int? companyId,
|
|
int? warehouseLocationId,
|
|
String? search,
|
|
}) async {
|
|
try {
|
|
final queryParams = {
|
|
'page': page,
|
|
'per_page': perPage,
|
|
if (status != null) 'status': status,
|
|
if (companyId != null) 'company_id': companyId,
|
|
if (warehouseLocationId != null) 'warehouse_location_id': warehouseLocationId,
|
|
if (search != null && search.isNotEmpty) 'search': search,
|
|
};
|
|
|
|
final response = await _apiClient.get(
|
|
ApiEndpoints.equipment,
|
|
queryParameters: queryParams,
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
final List<dynamic> data = response.data['data'];
|
|
return data.map((json) => EquipmentListDto.fromJson(json)).toList();
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to fetch equipment list',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<EquipmentResponse> createEquipment(CreateEquipmentRequest request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
ApiEndpoints.equipment,
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
return EquipmentResponse.fromJson(response.data['data']);
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to create equipment',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<EquipmentResponse> getEquipmentDetail(int id) async {
|
|
try {
|
|
final response = await _apiClient.get('${ApiEndpoints.equipment}/$id');
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
return EquipmentResponse.fromJson(response.data['data']);
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to fetch equipment detail',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<EquipmentResponse> updateEquipment(int id, UpdateEquipmentRequest request) async {
|
|
try {
|
|
final response = await _apiClient.put(
|
|
'${ApiEndpoints.equipment}/$id',
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
return EquipmentResponse.fromJson(response.data['data']);
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to update equipment',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> deleteEquipment(int id) async {
|
|
try {
|
|
final response = await _apiClient.delete('${ApiEndpoints.equipment}/$id');
|
|
|
|
if (response.data['success'] != true) {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to delete equipment',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<EquipmentResponse> changeEquipmentStatus(int id, String status, String? reason) async {
|
|
try {
|
|
final response = await _apiClient.patch(
|
|
'${ApiEndpoints.equipment}/$id/status',
|
|
data: {
|
|
'status': status,
|
|
if (reason != null) 'reason': reason,
|
|
},
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
return EquipmentResponse.fromJson(response.data['data']);
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to change equipment status',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<EquipmentHistoryDto> addEquipmentHistory(int equipmentId, CreateHistoryRequest request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
'${ApiEndpoints.equipment}/$equipmentId/history',
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
return EquipmentHistoryDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to add equipment history',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<List<EquipmentHistoryDto>> getEquipmentHistory(int equipmentId, {int page = 1, int perPage = 20}) async {
|
|
try {
|
|
final queryParams = {
|
|
'page': page,
|
|
'per_page': perPage,
|
|
};
|
|
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.equipment}/$equipmentId/history',
|
|
queryParameters: queryParams,
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
final List<dynamic> data = response.data['data'];
|
|
return data.map((json) => EquipmentHistoryDto.fromJson(json)).toList();
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to fetch equipment history',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<EquipmentIoResponse> equipmentIn(EquipmentInRequest request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
'${ApiEndpoints.equipment}/in',
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
return EquipmentIoResponse.fromJson(response.data['data']);
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to process equipment in',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<EquipmentIoResponse> equipmentOut(EquipmentOutRequest request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
'${ApiEndpoints.equipment}/out',
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data['success'] == true && response.data['data'] != null) {
|
|
return EquipmentIoResponse.fromJson(response.data['data']);
|
|
} else {
|
|
throw ServerException(
|
|
message: response.data['message'] ?? 'Failed to process equipment out',
|
|
);
|
|
}
|
|
} on DioException catch (e) {
|
|
throw ServerException(
|
|
message: e.response?.data['message'] ?? 'Network error occurred',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
} |