## 주요 변경사항 - Company, Equipment, License, Warehouse Location 모든 화면에 소프트 딜리트 구현 - 관리자 권한으로 삭제된 데이터 조회 가능 (includeInactive 파라미터) - 데이터 무결성 보장을 위한 논리 삭제 시스템 완성 ## 기능 개선 - 각 리스트 컨트롤러에 toggleIncludeInactive() 메서드 추가 - UI에 "비활성 포함" 체크박스 추가 (관리자 전용) - API 데이터소스에 includeInactive 파라미터 지원 ## 문서 정리 - 불필요한 문서 파일 제거 및 재구성 - CLAUDE.md 프로젝트 상태 업데이트 (진행률 80%) - 테스트 결과 문서화 (test20250812v01.md) ## UI 컴포넌트 - Equipment 화면 위젯 모듈화 (custom_dropdown_field, equipment_basic_info_section) - 폼 유효성 검증 강화 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
301 lines
9.4 KiB
Dart
301 lines
9.4 KiB
Dart
import 'package:flutter/foundation.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,
|
|
bool includeInactive = false,
|
|
});
|
|
|
|
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,
|
|
bool includeInactive = false,
|
|
}) async {
|
|
try {
|
|
final queryParams = <String, dynamic>{
|
|
'page': page,
|
|
'per_page': perPage,
|
|
'include_inactive': includeInactive,
|
|
};
|
|
|
|
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,
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
// API 응답이 배열인 경우와 객체인 경우를 모두 처리
|
|
final data = response.data['data'];
|
|
if (data is List) {
|
|
// 배열 응답을 LicenseListResponseDto 형식으로 변환
|
|
final List<LicenseDto> licenses = [];
|
|
|
|
for (int i = 0; i < data.length; i++) {
|
|
try {
|
|
final item = data[i];
|
|
debugPrint('📑 Parsing license item $i: ${item['license_key']}');
|
|
|
|
// null 검사 및 기본값 설정
|
|
final licenseDto = LicenseDto.fromJson({
|
|
...item,
|
|
// 필수 필드 보장
|
|
'license_key': item['license_key'] ?? '',
|
|
'is_active': item['is_active'] ?? true,
|
|
'created_at': item['created_at'] ?? DateTime.now().toIso8601String(),
|
|
'updated_at': item['updated_at'] ?? DateTime.now().toIso8601String(),
|
|
});
|
|
licenses.add(licenseDto);
|
|
} catch (e, stackTrace) {
|
|
debugPrint('❌ Error parsing license item $i: $e');
|
|
debugPrint('Item data: ${data[i]}');
|
|
debugPrint('Stack trace: $stackTrace');
|
|
// 파싱 실패한 항목은 건너뛰고 계속
|
|
continue;
|
|
}
|
|
}
|
|
|
|
final pagination = response.data['pagination'] ?? {};
|
|
return LicenseListResponseDto(
|
|
items: licenses,
|
|
total: pagination['total'] ?? licenses.length,
|
|
page: pagination['page'] ?? page,
|
|
perPage: pagination['per_page'] ?? perPage,
|
|
totalPages: pagination['total_pages'] ?? 1,
|
|
);
|
|
} else if (data['items'] != null) {
|
|
// 이미 LicenseListResponseDto 형식인 경우
|
|
return LicenseListResponseDto.fromJson(data);
|
|
} else {
|
|
// 예상치 못한 형식인 경우
|
|
throw ApiException(
|
|
message: 'Unexpected response format for license list',
|
|
);
|
|
}
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch licenses',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> getLicenseById(int id) async {
|
|
try {
|
|
final response = await _apiClient.get(
|
|
'${ApiEndpoints.licenses}/$id',
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> createLicense(CreateLicenseRequest request) async {
|
|
try {
|
|
final response = await _apiClient.post(
|
|
ApiEndpoints.licenses,
|
|
data: request.toJson(),
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} 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(),
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} 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(),
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LicenseDto> unassignLicense(int id) async {
|
|
try {
|
|
final response = await _apiClient.patch(
|
|
'${ApiEndpoints.licenses}/$id/unassign',
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
return LicenseDto.fromJson(response.data['data']);
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch license',
|
|
);
|
|
}
|
|
} 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,
|
|
);
|
|
|
|
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
|
// API 응답이 배열 형태인 경우 처리
|
|
final data = response.data['data'];
|
|
final pagination = response.data['pagination'] ?? {};
|
|
|
|
if (data is List) {
|
|
// 배열 응답을 ExpiringLicenseListDto 형식으로 변환
|
|
final List<ExpiringLicenseDto> licenses = [];
|
|
|
|
for (var item in data) {
|
|
try {
|
|
licenses.add(ExpiringLicenseDto.fromJson(item));
|
|
} catch (e) {
|
|
debugPrint('❌ Error parsing expiring license: $e');
|
|
debugPrint('Item data: $item');
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return ExpiringLicenseListDto(
|
|
items: licenses,
|
|
total: pagination['total'] ?? licenses.length,
|
|
page: pagination['page'] ?? page,
|
|
perPage: pagination['per_page'] ?? perPage,
|
|
totalPages: pagination['total_pages'] ?? 1,
|
|
);
|
|
} else {
|
|
// 이미 올바른 형식인 경우
|
|
return ExpiringLicenseListDto.fromJson(data);
|
|
}
|
|
} else {
|
|
throw ApiException(
|
|
message: response.data?['error']?['message'] ?? 'Failed to fetch expiring licenses',
|
|
);
|
|
}
|
|
} catch (e) {
|
|
throw _handleError(e);
|
|
}
|
|
}
|
|
|
|
Exception _handleError(dynamic error) {
|
|
if (error is ApiException) {
|
|
return error;
|
|
}
|
|
return ApiException(
|
|
message: error.toString(),
|
|
);
|
|
}
|
|
} |