feat: 대시보드에 라이선스 만료 요약 및 Lookup 데이터 캐싱 시스템 구현
- License Expiry Summary API 연동 완료 - 30/60/90일 내 만료 예정 라이선스 요약 표시 - 대시보드 상단에 알림 카드로 통합 - 만료 임박 순서로 색상 구분 (빨강/주황/노랑) - Lookup 데이터 전역 캐싱 시스템 구축 - LookupService 및 RemoteDataSource 생성 - 전체 lookup 데이터 일괄 로드 및 캐싱 - 타입별 필터링 지원 - 새로운 모델 추가 - LicenseExpirySummary (Freezed) - LookupData, LookupCategory, LookupItem 모델 - CLAUDE.md 문서 업데이트 - 미사용 API 활용 계획 추가 - 구현 우선순위 정의 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:superport/core/errors/failures.dart';
|
||||
import 'package:superport/data/datasources/remote/api_client.dart';
|
||||
import 'package:superport/data/models/dashboard/equipment_status_distribution.dart';
|
||||
import 'package:superport/data/models/dashboard/expiring_license.dart';
|
||||
import 'package:superport/data/models/dashboard/license_expiry_summary.dart';
|
||||
import 'package:superport/data/models/dashboard/overview_stats.dart';
|
||||
import 'package:superport/data/models/dashboard/recent_activity.dart';
|
||||
|
||||
@@ -14,6 +15,7 @@ abstract class DashboardRemoteDataSource {
|
||||
Future<Either<Failure, List<RecentActivity>>> getRecentActivities();
|
||||
Future<Either<Failure, EquipmentStatusDistribution>> getEquipmentStatusDistribution();
|
||||
Future<Either<Failure, List<ExpiringLicense>>> getExpiringLicenses({int days = 30});
|
||||
Future<Either<Failure, LicenseExpirySummary>> getLicenseExpirySummary();
|
||||
}
|
||||
|
||||
@LazySingleton(as: DashboardRemoteDataSource)
|
||||
@@ -105,6 +107,25 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, LicenseExpirySummary>> getLicenseExpirySummary() async {
|
||||
try {
|
||||
final response = await _apiClient.get('/overview/license-expiry');
|
||||
|
||||
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
||||
final summary = LicenseExpirySummary.fromJson(response.data['data']);
|
||||
return Right(summary);
|
||||
} else {
|
||||
final errorMessage = response.data?['error']?['message'] ?? '응답 데이터가 올바르지 않습니다';
|
||||
return Left(ServerFailure(message: errorMessage));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
return Left(_handleDioError(e));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: '라이선스 만료 요약을 가져오는 중 오류가 발생했습니다: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
Failure _handleDioError(DioException error) {
|
||||
switch (error.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
|
||||
102
lib/data/datasources/remote/lookup_remote_datasource.dart
Normal file
102
lib/data/datasources/remote/lookup_remote_datasource.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:superport/core/errors/failures.dart';
|
||||
import 'package:superport/data/datasources/remote/api_client.dart';
|
||||
import 'package:superport/data/models/lookups/lookup_data.dart';
|
||||
|
||||
abstract class LookupRemoteDataSource {
|
||||
Future<Either<Failure, LookupData>> getAllLookups();
|
||||
Future<Either<Failure, Map<String, List<LookupItem>>>> getLookupsByType(String type);
|
||||
}
|
||||
|
||||
@LazySingleton(as: LookupRemoteDataSource)
|
||||
class LookupRemoteDataSourceImpl implements LookupRemoteDataSource {
|
||||
final ApiClient _apiClient;
|
||||
|
||||
LookupRemoteDataSourceImpl(this._apiClient);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, LookupData>> getAllLookups() async {
|
||||
try {
|
||||
final response = await _apiClient.get('/lookups');
|
||||
|
||||
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
||||
final lookupData = LookupData.fromJson(response.data['data']);
|
||||
return Right(lookupData);
|
||||
} else {
|
||||
final errorMessage = response.data?['error']?['message'] ?? '응답 데이터가 올바르지 않습니다';
|
||||
return Left(ServerFailure(message: errorMessage));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
return Left(_handleDioError(e));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: '조회 데이터를 가져오는 중 오류가 발생했습니다: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Map<String, List<LookupItem>>>> getLookupsByType(String type) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'/lookups/type',
|
||||
queryParameters: {'lookup_type': type},
|
||||
);
|
||||
|
||||
if (response.data != null && response.data['success'] == true && response.data['data'] != null) {
|
||||
final data = response.data['data'] as Map<String, dynamic>;
|
||||
final result = <String, List<LookupItem>>{};
|
||||
|
||||
data.forEach((key, value) {
|
||||
if (value is List) {
|
||||
result[key] = value.map((item) => LookupItem.fromJson(item)).toList();
|
||||
}
|
||||
});
|
||||
|
||||
return Right(result);
|
||||
} else {
|
||||
final errorMessage = response.data?['error']?['message'] ?? '응답 데이터가 올바르지 않습니다';
|
||||
return Left(ServerFailure(message: errorMessage));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
return Left(_handleDioError(e));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: '타입별 조회 데이터를 가져오는 중 오류가 발생했습니다: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
Failure _handleDioError(DioException error) {
|
||||
switch (error.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
case DioExceptionType.sendTimeout:
|
||||
case DioExceptionType.receiveTimeout:
|
||||
return NetworkFailure(message: '네트워크 연결 시간이 초과되었습니다');
|
||||
case DioExceptionType.connectionError:
|
||||
return NetworkFailure(message: '서버에 연결할 수 없습니다');
|
||||
case DioExceptionType.badResponse:
|
||||
final statusCode = error.response?.statusCode ?? 0;
|
||||
final errorData = error.response?.data;
|
||||
|
||||
String message;
|
||||
if (errorData is Map) {
|
||||
message = errorData['error']?['message'] ??
|
||||
errorData['message'] ??
|
||||
'서버 오류가 발생했습니다';
|
||||
} else {
|
||||
message = '서버 오류가 발생했습니다';
|
||||
}
|
||||
|
||||
if (statusCode == 401) {
|
||||
return AuthenticationFailure(message: '인증이 만료되었습니다');
|
||||
} else if (statusCode == 403) {
|
||||
return AuthenticationFailure(message: '접근 권한이 없습니다');
|
||||
} else {
|
||||
return ServerFailure(message: message);
|
||||
}
|
||||
case DioExceptionType.cancel:
|
||||
return ServerFailure(message: '요청이 취소되었습니다');
|
||||
default:
|
||||
return ServerFailure(message: '알 수 없는 오류가 발생했습니다');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user