- 라이선스 모델 전면 개편 (상세 필드 추가, 계산 필드 구현) - API 응답 처리 개선 (HTTP 상태 코드 기반) - 장비 출고 폼 컨트롤러 추가 - 회사 지점 정보 모델 추가 - 공통 데이터 모델 구조 추가 - 전체 서비스 레이어 API 호출 방식 통일 - UI 컴포넌트 마이너 개선
182 lines
4.6 KiB
Dart
182 lines
4.6 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,
|
|
);
|
|
|
|
return LicenseListResponseDto.fromJson(response.data);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> getLicenseById(int id) async {
|
|
try {
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.licenses}/$id',
|
|
);
|
|
|
|
return LicenseDto.fromJson(response.data);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> createLicense(CreateLicenseRequest request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
ApiEndpoints.licenses,
|
|
data: request.toJson(),
|
|
);
|
|
|
|
return LicenseDto.fromJson(response.data);
|
|
} 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(),
|
|
);
|
|
|
|
return LicenseDto.fromJson(response.data);
|
|
} 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(),
|
|
);
|
|
|
|
return LicenseDto.fromJson(response.data);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> unassignLicense(int id) async {
|
|
try {
|
|
final response = await _apiClient.patch(
|
|
'${ApiEndpoints.licenses}/$id/unassign',
|
|
);
|
|
|
|
return LicenseDto.fromJson(response.data);
|
|
} 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,
|
|
);
|
|
|
|
return ExpiringLicenseListDto.fromJson(response.data);
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
Exception _handleError(dynamic error) {
|
|
if (error is ApiException) {
|
|
return error;
|
|
}
|
|
return ApiException(
|
|
message: error.toString(),
|
|
);
|
|
}
|
|
} |