- 라이선스 모델 전면 개편 (상세 필드 추가, 계산 필드 구현) - API 응답 처리 개선 (HTTP 상태 코드 기반) - 장비 출고 폼 컨트롤러 추가 - 회사 지점 정보 모델 추가 - 공통 데이터 모델 구조 추가 - 전체 서비스 레이어 API 호출 방식 통일 - UI 컴포넌트 마이너 개선
238 lines
7.2 KiB
Dart
238 lines
7.2 KiB
Dart
import 'package:get_it/get_it.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
import 'package:superport/core/errors/exceptions.dart';
|
|
import 'package:superport/core/errors/failures.dart';
|
|
import 'package:superport/data/datasources/remote/license_remote_datasource.dart';
|
|
import 'package:superport/data/models/license/license_dto.dart';
|
|
import 'package:superport/data/models/license/license_request_dto.dart';
|
|
import 'package:superport/models/license_model.dart';
|
|
|
|
@lazySingleton
|
|
class LicenseService {
|
|
final LicenseRemoteDataSource _remoteDataSource;
|
|
|
|
LicenseService(this._remoteDataSource);
|
|
|
|
// 라이선스 목록 조회
|
|
Future<List<License>> getLicenses({
|
|
int page = 1,
|
|
int perPage = 20,
|
|
bool? isActive,
|
|
int? companyId,
|
|
int? assignedUserId,
|
|
String? licenseType,
|
|
}) async {
|
|
try {
|
|
final response = await _remoteDataSource.getLicenses(
|
|
page: page,
|
|
perPage: perPage,
|
|
isActive: isActive,
|
|
companyId: companyId,
|
|
assignedUserId: assignedUserId,
|
|
licenseType: licenseType,
|
|
);
|
|
|
|
return response.items.map((dto) => _convertDtoToLicense(dto)).toList();
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '라이선스 목록을 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 라이선스 상세 조회
|
|
Future<License> getLicenseById(int id) async {
|
|
try {
|
|
final dto = await _remoteDataSource.getLicenseById(id);
|
|
return _convertDtoToLicense(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '라이선스 정보를 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 라이선스 생성
|
|
Future<License> createLicense(License license) async {
|
|
try {
|
|
final request = CreateLicenseRequest(
|
|
licenseKey: license.licenseKey,
|
|
productName: license.productName,
|
|
vendor: license.vendor,
|
|
licenseType: license.licenseType,
|
|
userCount: license.userCount,
|
|
purchaseDate: license.purchaseDate,
|
|
expiryDate: license.expiryDate,
|
|
purchasePrice: license.purchasePrice,
|
|
companyId: license.companyId,
|
|
branchId: license.branchId,
|
|
remark: license.remark,
|
|
);
|
|
|
|
final dto = await _remoteDataSource.createLicense(request);
|
|
return _convertDtoToLicense(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '라이선스 생성에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 라이선스 수정
|
|
Future<License> updateLicense(License license) async {
|
|
try {
|
|
if (license.id == null) {
|
|
throw BusinessFailure(message: '라이선스 ID가 없습니다');
|
|
}
|
|
|
|
final request = UpdateLicenseRequest(
|
|
licenseKey: license.licenseKey,
|
|
productName: license.productName,
|
|
vendor: license.vendor,
|
|
licenseType: license.licenseType,
|
|
userCount: license.userCount,
|
|
purchaseDate: license.purchaseDate,
|
|
expiryDate: license.expiryDate,
|
|
purchasePrice: license.purchasePrice,
|
|
remark: license.remark,
|
|
isActive: license.isActive,
|
|
);
|
|
|
|
final dto = await _remoteDataSource.updateLicense(license.id!, request);
|
|
return _convertDtoToLicense(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '라이선스 수정에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 라이선스 삭제
|
|
Future<void> deleteLicense(int id) async {
|
|
try {
|
|
await _remoteDataSource.deleteLicense(id);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '라이선스 삭제에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 라이선스 할당
|
|
Future<License> assignLicense(int licenseId, int userId) async {
|
|
try {
|
|
final request = AssignLicenseRequest(userId: userId);
|
|
final dto = await _remoteDataSource.assignLicense(licenseId, request);
|
|
return _convertDtoToLicense(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '라이선스 할당에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 라이선스 할당 해제
|
|
Future<License> unassignLicense(int licenseId) async {
|
|
try {
|
|
final dto = await _remoteDataSource.unassignLicense(licenseId);
|
|
return _convertDtoToLicense(dto);
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '라이선스 할당 해제에 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// 만료 예정 라이선스 조회
|
|
Future<List<License>> getExpiringLicenses({
|
|
int days = 30,
|
|
int page = 1,
|
|
int perPage = 20,
|
|
}) async {
|
|
try {
|
|
final response = await _remoteDataSource.getExpiringLicenses(
|
|
days: days,
|
|
page: page,
|
|
perPage: perPage,
|
|
);
|
|
|
|
return response.items.map((dto) => _convertExpiringDtoToLicense(dto)).toList();
|
|
} on ApiException catch (e) {
|
|
throw ServerFailure(message: e.message);
|
|
} catch (e) {
|
|
throw ServerFailure(message: '만료 예정 라이선스를 불러오는 데 실패했습니다: $e');
|
|
}
|
|
}
|
|
|
|
// DTO를 Flutter 모델로 변환
|
|
License _convertDtoToLicense(LicenseDto dto) {
|
|
return License(
|
|
id: dto.id,
|
|
licenseKey: dto.licenseKey,
|
|
productName: dto.productName,
|
|
vendor: dto.vendor,
|
|
licenseType: dto.licenseType,
|
|
userCount: dto.userCount,
|
|
purchaseDate: dto.purchaseDate,
|
|
expiryDate: dto.expiryDate,
|
|
purchasePrice: dto.purchasePrice,
|
|
companyId: dto.companyId,
|
|
branchId: dto.branchId,
|
|
assignedUserId: dto.assignedUserId,
|
|
remark: dto.remark,
|
|
isActive: dto.isActive,
|
|
createdAt: dto.createdAt,
|
|
updatedAt: dto.updatedAt,
|
|
companyName: dto.companyName,
|
|
branchName: dto.branchName,
|
|
assignedUserName: dto.assignedUserName,
|
|
);
|
|
}
|
|
|
|
// 만료 예정 DTO를 Flutter 모델로 변환
|
|
License _convertExpiringDtoToLicense(ExpiringLicenseDto dto) {
|
|
return License(
|
|
id: dto.id,
|
|
licenseKey: dto.licenseKey,
|
|
productName: dto.productName,
|
|
vendor: null,
|
|
licenseType: null,
|
|
userCount: null,
|
|
purchaseDate: null,
|
|
expiryDate: dto.expiryDate,
|
|
purchasePrice: null,
|
|
companyId: null,
|
|
branchId: null,
|
|
assignedUserId: null,
|
|
remark: null,
|
|
isActive: dto.isActive,
|
|
createdAt: null,
|
|
updatedAt: null,
|
|
companyName: dto.companyName,
|
|
branchName: null,
|
|
assignedUserName: null,
|
|
);
|
|
}
|
|
|
|
// 페이지네이션 정보
|
|
Future<int> getTotalLicenses({
|
|
bool? isActive,
|
|
int? companyId,
|
|
int? assignedUserId,
|
|
String? licenseType,
|
|
}) async {
|
|
try {
|
|
final response = await _remoteDataSource.getLicenses(
|
|
page: 1,
|
|
perPage: 1,
|
|
isActive: isActive,
|
|
companyId: companyId,
|
|
assignedUserId: assignedUserId,
|
|
licenseType: licenseType,
|
|
);
|
|
return response.total;
|
|
} catch (e) {
|
|
return 0;
|
|
}
|
|
}
|
|
} |