feat: API 연동 개선 및 라이선스 모델 확장

- 라이선스 모델 전면 개편 (상세 필드 추가, 계산 필드 구현)
- API 응답 처리 개선 (HTTP 상태 코드 기반)
- 장비 출고 폼 컨트롤러 추가
- 회사 지점 정보 모델 추가
- 공통 데이터 모델 구조 추가
- 전체 서비스 레이어 API 호출 방식 통일
- UI 컴포넌트 마이너 개선
This commit is contained in:
JiWoong Sul
2025-07-25 01:22:15 +09:00
parent 8384423cf2
commit 71b7b7f40b
42 changed files with 1543 additions and 315 deletions

View File

@@ -9,7 +9,9 @@ import 'package:superport/models/license_model.dart';
@lazySingleton
class LicenseService {
final LicenseRemoteDataSource _remoteDataSource = GetIt.instance<LicenseRemoteDataSource>();
final LicenseRemoteDataSource _remoteDataSource;
LicenseService(this._remoteDataSource);
// 라이선스 목록 조회
Future<List<License>> getLicenses({
@@ -32,9 +34,9 @@ class LicenseService {
return response.items.map((dto) => _convertDtoToLicense(dto)).toList();
} on ApiException catch (e) {
throw Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '라이선스 목록을 불러오는 데 실패했습니다: $e');
throw ServerFailure(message: '라이선스 목록을 불러오는 데 실패했습니다: $e');
}
}
@@ -44,36 +46,35 @@ class LicenseService {
final dto = await _remoteDataSource.getLicenseById(id);
return _convertDtoToLicense(dto);
} on ApiException catch (e) {
throw Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '라이선스 정보를 불러오는 데 실패했습니다: $e');
throw ServerFailure(message: '라이선스 정보를 불러오는 데 실패했습니다: $e');
}
}
// 라이선스 생성
Future<License> createLicense(License license) async {
try {
// Flutter 모델의 visitCycle과 durationMonths를 API 필드에 매핑
// visitCycle은 remark에 저장하고, durationMonths는 날짜 계산에 사용
final now = DateTime.now();
final expiryDate = now.add(Duration(days: license.durationMonths * 30));
final request = CreateLicenseRequest(
licenseKey: license.name, // name을 licenseKey로 매핑
productName: '유지보수 계약', // 기본값 설정
licenseType: 'maintenance', // 유지보수 타입으로 고정
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,
purchaseDate: now,
expiryDate: expiryDate,
remark: '방문주기: ${license.visitCycle}', // visitCycle을 remark에 저장
branchId: license.branchId,
remark: license.remark,
);
final dto = await _remoteDataSource.createLicense(request);
return _convertDtoToLicense(dto);
} on ApiException catch (e) {
throw Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '라이선스 생성에 실패했습니다: $e');
throw ServerFailure(message: '라이선스 생성에 실패했습니다: $e');
}
}
@@ -81,30 +82,28 @@ class LicenseService {
Future<License> updateLicense(License license) async {
try {
if (license.id == null) {
throw Failure(message: '라이선스 ID가 없습니다');
}
// 기존 라이선스 정보를 먼저 조회
final existingDto = await _remoteDataSource.getLicenseById(license.id!);
// 만료일 계산 (durationMonths가 변경된 경우)
DateTime? newExpiryDate;
if (existingDto.purchaseDate != null) {
newExpiryDate = existingDto.purchaseDate!.add(Duration(days: license.durationMonths * 30));
throw BusinessFailure(message: '라이선스 ID가 없습니다');
}
final request = UpdateLicenseRequest(
licenseKey: license.name,
expiryDate: newExpiryDate,
remark: '방문주기: ${license.visitCycle}',
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 Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '라이선스 수정에 실패했습니다: $e');
throw ServerFailure(message: '라이선스 수정에 실패했습니다: $e');
}
}
@@ -113,9 +112,9 @@ class LicenseService {
try {
await _remoteDataSource.deleteLicense(id);
} on ApiException catch (e) {
throw Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '라이선스 삭제에 실패했습니다: $e');
throw ServerFailure(message: '라이선스 삭제에 실패했습니다: $e');
}
}
@@ -126,9 +125,9 @@ class LicenseService {
final dto = await _remoteDataSource.assignLicense(licenseId, request);
return _convertDtoToLicense(dto);
} on ApiException catch (e) {
throw Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '라이선스 할당에 실패했습니다: $e');
throw ServerFailure(message: '라이선스 할당에 실패했습니다: $e');
}
}
@@ -138,9 +137,9 @@ class LicenseService {
final dto = await _remoteDataSource.unassignLicense(licenseId);
return _convertDtoToLicense(dto);
} on ApiException catch (e) {
throw Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '라이선스 할당 해제에 실패했습니다: $e');
throw ServerFailure(message: '라이선스 할당 해제에 실패했습니다: $e');
}
}
@@ -159,33 +158,34 @@ class LicenseService {
return response.items.map((dto) => _convertExpiringDtoToLicense(dto)).toList();
} on ApiException catch (e) {
throw Failure(message: e.message);
throw ServerFailure(message: e.message);
} catch (e) {
throw Failure(message: '만료 예정 라이선스를 불러오는 데 실패했습니다: $e');
throw ServerFailure(message: '만료 예정 라이선스를 불러오는 데 실패했습니다: $e');
}
}
// DTO를 Flutter 모델로 변환
License _convertDtoToLicense(LicenseDto dto) {
// remark에서 방문주기 추출
String visitCycle = '미방문'; // 기본값
if (dto.remark != null && dto.remark!.contains('방문주기:')) {
visitCycle = dto.remark!.split('방문주기:').last.trim();
}
// 기간 계산 (purchaseDate와 expiryDate 차이)
int durationMonths = 12; // 기본값
if (dto.purchaseDate != null && dto.expiryDate != null) {
final difference = dto.expiryDate!.difference(dto.purchaseDate!);
durationMonths = (difference.inDays / 30).round();
}
return License(
id: dto.id,
companyId: dto.companyId ?? 0,
name: dto.licenseKey,
durationMonths: durationMonths,
visitCycle: visitCycle,
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,
);
}
@@ -193,10 +193,24 @@ class LicenseService {
License _convertExpiringDtoToLicense(ExpiringLicenseDto dto) {
return License(
id: dto.id,
companyId: 0, // ExpiringLicenseDto에는 companyId가 없으므로 기본값 사용
name: dto.licenseKey,
durationMonths: 12, // 기본값
visitCycle: '미방문', // 기본값
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,
);
}