feat: API 통합 2차 작업 완료
- 자동 로그인 구현: 앱 시작 시 토큰 확인 후 적절한 화면으로 라우팅 - AuthInterceptor 개선: AuthService와 통합하여 토큰 관리 일원화 - 로그아웃 기능 개선: AuthService를 사용한 API 로그아웃 처리 - 대시보드 API 연동: MockDataService에서 실제 API로 완전 전환 - Dashboard DTO 모델 생성 (OverviewStats, RecentActivity 등) - DashboardRemoteDataSource 및 DashboardService 구현 - OverviewController를 ChangeNotifier 패턴으로 개선 - OverviewScreenRedesign에 Provider 패턴 적용 - API 통합 진행 상황 문서 업데이트
This commit is contained in:
@@ -1,60 +1,177 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
import 'package:get_it/get_it.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/overview_stats.dart';
|
||||
import 'package:superport/data/models/dashboard/recent_activity.dart';
|
||||
import 'package:superport/services/dashboard_service.dart';
|
||||
import 'package:superport/screens/common/theme_tailwind.dart';
|
||||
|
||||
// 대시보드(Overview) 화면의 상태 및 비즈니스 로직을 담당하는 컨트롤러
|
||||
class OverviewController {
|
||||
final MockDataService dataService;
|
||||
// 대시보드(Overview) 화면의 상태 및 비즈니스 로직을 담답하는 컨트롤러
|
||||
class OverviewController extends ChangeNotifier {
|
||||
final DashboardService _dashboardService = GetIt.instance<DashboardService>();
|
||||
|
||||
int totalCompanies = 0;
|
||||
int totalUsers = 0;
|
||||
int totalEquipmentIn = 0;
|
||||
int totalEquipmentOut = 0;
|
||||
int totalLicenses = 0;
|
||||
|
||||
// 최근 활동 데이터
|
||||
List<Map<String, dynamic>> recentActivities = [];
|
||||
|
||||
OverviewController({required this.dataService});
|
||||
|
||||
// 데이터 로드 및 통계 계산
|
||||
void loadData() {
|
||||
totalCompanies = dataService.getAllCompanies().length;
|
||||
totalUsers = dataService.getAllUsers().length;
|
||||
// 실제 서비스에서는 아래 메서드 구현 필요
|
||||
totalEquipmentIn = 32; // 임시 데이터
|
||||
totalEquipmentOut = 18; // 임시 데이터
|
||||
totalLicenses = dataService.getAllLicenses().length;
|
||||
_loadRecentActivities();
|
||||
// 상태 데이터
|
||||
OverviewStats? _overviewStats;
|
||||
List<RecentActivity> _recentActivities = [];
|
||||
EquipmentStatusDistribution? _equipmentStatus;
|
||||
List<ExpiringLicense> _expiringLicenses = [];
|
||||
|
||||
// 로딩 상태
|
||||
bool _isLoadingStats = false;
|
||||
bool _isLoadingActivities = false;
|
||||
bool _isLoadingEquipmentStatus = false;
|
||||
bool _isLoadingLicenses = false;
|
||||
|
||||
// 에러 상태
|
||||
String? _statsError;
|
||||
String? _activitiesError;
|
||||
String? _equipmentStatusError;
|
||||
String? _licensesError;
|
||||
|
||||
// Getters
|
||||
OverviewStats? get overviewStats => _overviewStats;
|
||||
List<RecentActivity> get recentActivities => _recentActivities;
|
||||
EquipmentStatusDistribution? get equipmentStatus => _equipmentStatus;
|
||||
List<ExpiringLicense> get expiringLicenses => _expiringLicenses;
|
||||
|
||||
bool get isLoading => _isLoadingStats || _isLoadingActivities ||
|
||||
_isLoadingEquipmentStatus || _isLoadingLicenses;
|
||||
|
||||
String? get error {
|
||||
return _statsError ?? _activitiesError ??
|
||||
_equipmentStatusError ?? _licensesError;
|
||||
}
|
||||
|
||||
// 최근 활동 데이터 로드 (임시 데이터)
|
||||
void _loadRecentActivities() {
|
||||
recentActivities = [
|
||||
{
|
||||
'type': '장비 입고',
|
||||
'title': '라우터 입고 처리 완료',
|
||||
'time': '30분 전',
|
||||
'user': '홍길동',
|
||||
'icon': Icons.input,
|
||||
'color': AppThemeTailwind.success,
|
||||
OverviewController();
|
||||
|
||||
// 데이터 로드
|
||||
Future<void> loadData() async {
|
||||
await Future.wait([
|
||||
_loadOverviewStats(),
|
||||
_loadRecentActivities(),
|
||||
_loadEquipmentStatus(),
|
||||
_loadExpiringLicenses(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 개별 데이터 로드 메서드
|
||||
Future<void> _loadOverviewStats() async {
|
||||
_isLoadingStats = true;
|
||||
_statsError = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await _dashboardService.getOverviewStats();
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
_statsError = failure.message;
|
||||
},
|
||||
{
|
||||
'type': '사용자 추가',
|
||||
'title': '새 관리자 등록',
|
||||
'time': '1시간 전',
|
||||
'user': '김철수',
|
||||
'icon': Icons.person_add,
|
||||
'color': AppThemeTailwind.primary,
|
||||
(stats) {
|
||||
_overviewStats = stats;
|
||||
},
|
||||
{
|
||||
'type': '장비 출고',
|
||||
'title': '모니터 5대 출고 처리',
|
||||
'time': '2시간 전',
|
||||
'user': '이영희',
|
||||
'icon': Icons.output,
|
||||
'color': AppThemeTailwind.warning,
|
||||
);
|
||||
|
||||
_isLoadingStats = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadRecentActivities() async {
|
||||
_isLoadingActivities = true;
|
||||
_activitiesError = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await _dashboardService.getRecentActivities();
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
_activitiesError = failure.message;
|
||||
},
|
||||
];
|
||||
(activities) {
|
||||
_recentActivities = activities;
|
||||
},
|
||||
);
|
||||
|
||||
_isLoadingActivities = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadEquipmentStatus() async {
|
||||
_isLoadingEquipmentStatus = true;
|
||||
_equipmentStatusError = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await _dashboardService.getEquipmentStatusDistribution();
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
_equipmentStatusError = failure.message;
|
||||
},
|
||||
(status) {
|
||||
_equipmentStatus = status;
|
||||
},
|
||||
);
|
||||
|
||||
_isLoadingEquipmentStatus = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadExpiringLicenses() async {
|
||||
_isLoadingLicenses = true;
|
||||
_licensesError = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await _dashboardService.getExpiringLicenses(days: 30);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
_licensesError = failure.message;
|
||||
},
|
||||
(licenses) {
|
||||
_expiringLicenses = licenses;
|
||||
},
|
||||
);
|
||||
|
||||
_isLoadingLicenses = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// 활동 타입별 아이콘과 색상 가져오기
|
||||
IconData getActivityIcon(String activityType) {
|
||||
switch (activityType.toLowerCase()) {
|
||||
case 'equipment_in':
|
||||
case '장비 입고':
|
||||
return Icons.input;
|
||||
case 'equipment_out':
|
||||
case '장비 출고':
|
||||
return Icons.output;
|
||||
case 'user_create':
|
||||
case '사용자 추가':
|
||||
return Icons.person_add;
|
||||
case 'license_create':
|
||||
case '라이선스 등록':
|
||||
return Icons.vpn_key;
|
||||
default:
|
||||
return Icons.notifications;
|
||||
}
|
||||
}
|
||||
|
||||
Color getActivityColor(String activityType) {
|
||||
switch (activityType.toLowerCase()) {
|
||||
case 'equipment_in':
|
||||
case '장비 입고':
|
||||
return AppThemeTailwind.success;
|
||||
case 'equipment_out':
|
||||
case '장비 출고':
|
||||
return AppThemeTailwind.warning;
|
||||
case 'user_create':
|
||||
case '사용자 추가':
|
||||
return AppThemeTailwind.primary;
|
||||
case 'license_create':
|
||||
case '라이선스 등록':
|
||||
return AppThemeTailwind.info;
|
||||
default:
|
||||
return AppThemeTailwind.muted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user