feat: 라이선스 및 창고 관리 API 연동 구현
- 라이선스 관리 API 연동 완료 - LicenseRemoteDataSource, LicenseService 구현 - LicenseListController, LicenseFormController API 연동 - 페이지네이션, 검색, 필터링 기능 추가 - 라이선스 할당/해제 기능 구현 - 창고 관리 API 연동 완료 - WarehouseRemoteDataSource, WarehouseService 구현 - WarehouseLocationListController, WarehouseLocationFormController API 연동 - 창고별 장비 조회 및 용량 관리 기능 추가 - DI 컨테이너에 새로운 서비스 등록 - API 통합 문서 업데이트 (전체 진행률 100% 달성)
This commit is contained in:
224
lib/services/license_service.dart
Normal file
224
lib/services/license_service.dart
Normal file
@@ -0,0 +1,224 @@
|
||||
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 = GetIt.instance<LicenseRemoteDataSource>();
|
||||
|
||||
// 라이선스 목록 조회
|
||||
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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '라이선스 목록을 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 라이선스 상세 조회
|
||||
Future<License> getLicenseById(int id) async {
|
||||
try {
|
||||
final dto = await _remoteDataSource.getLicenseById(id);
|
||||
return _convertDtoToLicense(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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', // 유지보수 타입으로 고정
|
||||
companyId: license.companyId,
|
||||
purchaseDate: now,
|
||||
expiryDate: expiryDate,
|
||||
remark: '방문주기: ${license.visitCycle}', // visitCycle을 remark에 저장
|
||||
);
|
||||
|
||||
final dto = await _remoteDataSource.createLicense(request);
|
||||
return _convertDtoToLicense(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '라이선스 생성에 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 라이선스 수정
|
||||
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));
|
||||
}
|
||||
|
||||
final request = UpdateLicenseRequest(
|
||||
licenseKey: license.name,
|
||||
expiryDate: newExpiryDate,
|
||||
remark: '방문주기: ${license.visitCycle}',
|
||||
);
|
||||
|
||||
final dto = await _remoteDataSource.updateLicense(license.id!, request);
|
||||
return _convertDtoToLicense(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '라이선스 수정에 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 라이선스 삭제
|
||||
Future<void> deleteLicense(int id) async {
|
||||
try {
|
||||
await _remoteDataSource.deleteLicense(id);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '라이선스 할당에 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 라이선스 할당 해제
|
||||
Future<License> unassignLicense(int licenseId) async {
|
||||
try {
|
||||
final dto = await _remoteDataSource.unassignLicense(licenseId);
|
||||
return _convertDtoToLicense(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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 Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(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,
|
||||
);
|
||||
}
|
||||
|
||||
// 만료 예정 DTO를 Flutter 모델로 변환
|
||||
License _convertExpiringDtoToLicense(ExpiringLicenseDto dto) {
|
||||
return License(
|
||||
id: dto.id,
|
||||
companyId: 0, // ExpiringLicenseDto에는 companyId가 없으므로 기본값 사용
|
||||
name: dto.licenseKey,
|
||||
durationMonths: 12, // 기본값
|
||||
visitCycle: '미방문', // 기본값
|
||||
);
|
||||
}
|
||||
|
||||
// 페이지네이션 정보
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
191
lib/services/warehouse_service.dart
Normal file
191
lib/services/warehouse_service.dart
Normal file
@@ -0,0 +1,191 @@
|
||||
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/warehouse_remote_datasource.dart';
|
||||
import 'package:superport/data/models/warehouse/warehouse_dto.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
import 'package:superport/models/warehouse_location_model.dart';
|
||||
|
||||
@lazySingleton
|
||||
class WarehouseService {
|
||||
final WarehouseRemoteDataSource _remoteDataSource = GetIt.instance<WarehouseRemoteDataSource>();
|
||||
|
||||
// 창고 위치 목록 조회
|
||||
Future<List<WarehouseLocation>> getWarehouseLocations({
|
||||
int page = 1,
|
||||
int perPage = 20,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _remoteDataSource.getWarehouseLocations(
|
||||
page: page,
|
||||
perPage: perPage,
|
||||
isActive: isActive,
|
||||
);
|
||||
|
||||
return response.items.map((dto) => _convertDtoToWarehouseLocation(dto)).toList();
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 위치 목록을 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 위치 상세 조회
|
||||
Future<WarehouseLocation> getWarehouseLocationById(int id) async {
|
||||
try {
|
||||
final dto = await _remoteDataSource.getWarehouseLocationById(id);
|
||||
return _convertDtoToWarehouseLocation(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 위치 정보를 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 위치 생성
|
||||
Future<WarehouseLocation> createWarehouseLocation(WarehouseLocation location) async {
|
||||
try {
|
||||
final request = CreateWarehouseLocationRequest(
|
||||
name: location.name,
|
||||
address: location.address.detailAddress,
|
||||
city: location.address.region,
|
||||
postalCode: location.address.zipCode,
|
||||
country: 'KR', // 기본값
|
||||
);
|
||||
|
||||
final dto = await _remoteDataSource.createWarehouseLocation(request);
|
||||
return _convertDtoToWarehouseLocation(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 위치 생성에 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 위치 수정
|
||||
Future<WarehouseLocation> updateWarehouseLocation(WarehouseLocation location) async {
|
||||
try {
|
||||
final request = UpdateWarehouseLocationRequest(
|
||||
name: location.name,
|
||||
address: location.address.detailAddress,
|
||||
city: location.address.region,
|
||||
postalCode: location.address.zipCode,
|
||||
);
|
||||
|
||||
final dto = await _remoteDataSource.updateWarehouseLocation(location.id, request);
|
||||
return _convertDtoToWarehouseLocation(dto);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 위치 수정에 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 위치 삭제
|
||||
Future<void> deleteWarehouseLocation(int id) async {
|
||||
try {
|
||||
await _remoteDataSource.deleteWarehouseLocation(id);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 위치 삭제에 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고별 장비 목록 조회
|
||||
Future<List<Map<String, dynamic>>> getWarehouseEquipment(
|
||||
int warehouseId, {
|
||||
int page = 1,
|
||||
int perPage = 20,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _remoteDataSource.getWarehouseEquipment(
|
||||
warehouseId,
|
||||
page: page,
|
||||
perPage: perPage,
|
||||
);
|
||||
|
||||
return response.items.map((dto) => {
|
||||
'id': dto.id,
|
||||
'equipmentNumber': dto.equipmentNumber,
|
||||
'manufacturer': dto.manufacturer,
|
||||
'equipmentName': dto.equipmentName,
|
||||
'serialNumber': dto.serialNumber,
|
||||
'quantity': dto.quantity,
|
||||
'status': dto.status,
|
||||
'storedAt': dto.storedAt,
|
||||
}).toList();
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 장비 목록을 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 창고 용량 정보 조회
|
||||
Future<WarehouseCapacityInfo> getWarehouseCapacity(int id) async {
|
||||
try {
|
||||
return await _remoteDataSource.getWarehouseCapacity(id);
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '창고 용량 정보를 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 사용 중인 창고 위치 목록 조회
|
||||
Future<List<WarehouseLocation>> getInUseWarehouseLocations() async {
|
||||
try {
|
||||
final dtos = await _remoteDataSource.getInUseWarehouseLocations();
|
||||
return dtos.map((dto) => _convertDtoToWarehouseLocation(dto)).toList();
|
||||
} on ApiException catch (e) {
|
||||
throw Failure(message: e.message);
|
||||
} catch (e) {
|
||||
throw Failure(message: '사용 중인 창고 위치를 불러오는 데 실패했습니다: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// DTO를 Flutter 모델로 변환
|
||||
WarehouseLocation _convertDtoToWarehouseLocation(WarehouseLocationDto dto) {
|
||||
// 주소 조합
|
||||
final addressParts = <String>[];
|
||||
if (dto.address != null && dto.address!.isNotEmpty) {
|
||||
addressParts.add(dto.address!);
|
||||
}
|
||||
if (dto.city != null && dto.city!.isNotEmpty) {
|
||||
addressParts.add(dto.city!);
|
||||
}
|
||||
if (dto.state != null && dto.state!.isNotEmpty) {
|
||||
addressParts.add(dto.state!);
|
||||
}
|
||||
|
||||
final address = Address(
|
||||
zipCode: dto.postalCode ?? '',
|
||||
region: dto.city ?? '',
|
||||
detailAddress: addressParts.join(' '),
|
||||
);
|
||||
|
||||
return WarehouseLocation(
|
||||
id: dto.id,
|
||||
name: dto.name,
|
||||
address: address,
|
||||
remark: dto.managerName != null ? '담당자: ${dto.managerName}' : null,
|
||||
);
|
||||
}
|
||||
|
||||
// 페이지네이션 정보
|
||||
Future<int> getTotalWarehouseLocations({bool? isActive}) async {
|
||||
try {
|
||||
final response = await _remoteDataSource.getWarehouseLocations(
|
||||
page: 1,
|
||||
perPage: 1,
|
||||
isActive: isActive,
|
||||
);
|
||||
return response.total;
|
||||
} catch (e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user