주요 변경사항: - 창고 관리 API 응답 구조와 DTO 불일치 수정 - WarehouseLocationDto에 code, manager_phone 필드 추가 - RemoteDataSource에서 API 응답을 DTO 구조에 맞게 변환 - 회사 관리 API 응답 파싱 오류 수정 - CompanyResponse의 필수 필드를 nullable로 변경 - PaginatedResponse 구조 매핑 로직 개선 - 에러 처리 및 로깅 개선 - Service Layer에 상세 에러 로깅 추가 - Controller에서 에러 타입별 처리 - 새로운 유틸리티 추가 - ResponseInterceptor: API 응답 정규화 - DebugLogger: 디버깅 도구 - HealthCheckService: 서버 상태 확인 - 문서화 - API 통합 테스트 가이드 - 에러 분석 보고서 - 리팩토링 계획서
224 lines
6.4 KiB
Dart
224 lines
6.4 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/license/license_dto.dart';
|
|
import 'package:superport/data/models/license/license_request_dto.dart';
|
|
import 'package:superport/data/models/license/license_query_dto.dart';
|
|
|
|
abstract class LicenseRemoteDataSource {
|
|
Future<LicenseListResponseDto> getLicenses({
|
|
int page = 1,
|
|
int perPage = 20,
|
|
bool? isActive,
|
|
int? companyId,
|
|
int? assignedUserId,
|
|
String? licenseType,
|
|
});
|
|
|
|
Future<LicenseDto> getLicenseById(int id);
|
|
Future<LicenseDto> createLicense(CreateLicenseRequest request);
|
|
Future<LicenseDto> updateLicense(int id, UpdateLicenseRequest request);
|
|
Future<void> deleteLicense(int id);
|
|
Future<LicenseDto> assignLicense(int id, AssignLicenseRequest request);
|
|
Future<LicenseDto> unassignLicense(int id);
|
|
Future<ExpiringLicenseListDto> getExpiringLicenses({
|
|
int days = 30,
|
|
int page = 1,
|
|
int perPage = 20,
|
|
});
|
|
}
|
|
|
|
@LazySingleton(as: LicenseRemoteDataSource)
|
|
class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource {
|
|
final ApiClient _apiClient;
|
|
|
|
LicenseRemoteDataSourceImpl({
|
|
required ApiClient apiClient,
|
|
}) : _apiClient = apiClient;
|
|
|
|
@override
|
|
Future<LicenseListResponseDto> getLicenses({
|
|
int page = 1,
|
|
int perPage = 20,
|
|
bool? isActive,
|
|
int? companyId,
|
|
int? assignedUserId,
|
|
String? licenseType,
|
|
}) async {
|
|
try {
|
|
final queryParams = <String, dynamic>{
|
|
'page': page,
|
|
'per_page': perPage,
|
|
};
|
|
|
|
if (isActive != null) queryParams['is_active'] = isActive;
|
|
if (companyId != null) queryParams['company_id'] = companyId;
|
|
if (assignedUserId != null) queryParams['assigned_user_id'] = assignedUserId;
|
|
if (licenseType != null) queryParams['license_type'] = licenseType;
|
|
|
|
final response = await _apiClient.get(
|
|
ApiEndpoints.licenses,
|
|
queryParameters: queryParams,
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseListResponseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch licenses',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> getLicenseById(int id) async {
|
|
try {
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.licenses}/$id',
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> createLicense(CreateLicenseRequest request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
ApiEndpoints.licenses,
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> updateLicense(int id, UpdateLicenseRequest request) async {
|
|
try {
|
|
final response = await _apiClient.put(
|
|
'${ApiEndpoints.licenses}/$id',
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> deleteLicense(int id) async {
|
|
try {
|
|
await _apiClient.delete(
|
|
'${ApiEndpoints.licenses}/$id',
|
|
);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> assignLicense(int id, AssignLicenseRequest request) async {
|
|
try {
|
|
final response = await _apiClient.patch(
|
|
'${ApiEndpoints.licenses}/$id/assign',
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> unassignLicense(int id) async {
|
|
try {
|
|
final response = await _apiClient.patch(
|
|
'${ApiEndpoints.licenses}/$id/unassign',
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<ExpiringLicenseListDto> getExpiringLicenses({
|
|
int days = 30,
|
|
int page = 1,
|
|
int perPage = 20,
|
|
}) async {
|
|
try {
|
|
final queryParams = <String, dynamic>{
|
|
'days': days,
|
|
'page': page,
|
|
'per_page': perPage,
|
|
};
|
|
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.licenses}/expiring',
|
|
queryParameters: queryParams,
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return ExpiringLicenseListDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch expiring licenses',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
Exception _handleError(dynamic error) {
|
|
if (error is ApiException) {
|
|
return error;
|
|
}
|
|
return ApiException(
|
|
message: error.toString(),
|
|
);
|
|
}
|
|
} |