Files

32 lines
1.1 KiB
Dart
Raw Permalink Normal View History

// 🛠️ 관리자 대시보드의 기능(서버 통신/상태) 담당 컨트롤러.
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import '../config.dart';
class AdminController extends ChangeNotifier {
bool _isLoading = false;
bool get isLoading => _isLoading;
Future<String> resetDatabase() async {
_isLoading = true;
notifyListeners();
// 🆕 백엔드 보안 규칙에 맞추어 초기화 토큰 비밀번호 파라미터(?password=...)를 연동 주소에 매칭했습니다.
final url = Uri.parse('$baseUrl/reset-db?password=adminreset2010');
try {
final response = await http.get(url);
if (response.statusCode == 200) {
return 'DB가 깔끔하게 초기화되었습니다! (출석 번호 1번부터 시작)';
} else {
return '초기화 실패: 서버 권한 오류 (${response.statusCode})';
}
} catch (e) {
return '네트워크 에러: 서버와 연결할 수 없습니다.';
} finally {
_isLoading = false;
notifyListeners();
}
}
}