Files
superport/lib/data/datasources/remote/license_remote_datasource.dart
JiWoong Sul 8384423cf2 feat: 라이선스 및 창고 관리 API 연동 구현
- 라이선스 관리 API 연동 완료
  - LicenseRemoteDataSource, LicenseService 구현
  - LicenseListController, LicenseFormController API 연동
  - 페이지네이션, 검색, 필터링 기능 추가
  - 라이선스 할당/해제 기능 구현

- 창고 관리 API 연동 완료
  - WarehouseRemoteDataSource, WarehouseService 구현
  - WarehouseLocationListController, WarehouseLocationFormController API 연동
  - 창고별 장비 조회 및 용량 관리 기능 추가

- DI 컨테이너에 새로운 서비스 등록
- API 통합 문서 업데이트 (전체 진행률 100% 달성)
2025-07-25 00:18:49 +09:00

181 lines
4.5 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';
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(),
);
}
}