2026-08-05 15:04:24 +09:00
|
|
|
// 🎓 학생 대시보드(마스터 계정 전용 계정 강제 삭제)의 기능(서버 통신/상태) 담당 컨트롤러.
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
import '../config.dart';
|
|
|
|
|
|
|
|
|
|
class StudentDashboardController extends ChangeNotifier {
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
bool get isLoading => _isLoading;
|
|
|
|
|
|
|
|
|
|
/// 👑 마스터 계정 전용 회원 삭제 API 호출.
|
|
|
|
|
Future<(bool success, String message)> deleteUser(String userId) async {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
final url = Uri.parse('$baseUrl/api/users/delete/$userId');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final response = await http.delete(url);
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
final responseData = jsonDecode(response.body);
|
2026-09-04 22:31:03 +09:00
|
|
|
return (true, '${responseData['message']}');
|
2026-08-05 15:04:24 +09:00
|
|
|
} else {
|
|
|
|
|
final errorData = jsonDecode(response.body);
|
2026-09-04 22:31:03 +09:00
|
|
|
return (false, '삭제 실패: ${errorData['detail'] ?? '알 수 없는 오류'}');
|
2026-08-05 15:04:24 +09:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2026-09-04 22:31:03 +09:00
|
|
|
return (false, '서버와 연결할 수 없습니다. (네트워크 에러)');
|
2026-08-05 15:04:24 +09:00
|
|
|
} finally {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|