// πŸ” (λ§ˆμŠ€ν„° κ³„μ •μš©) 학생 계정 및 κΈ°κΈ° 관리 ν™”λ©΄μ˜ κΈ°λŠ₯(μ„œλ²„ 톡신/μƒνƒœ) λ‹΄λ‹Ή 컨트둀러. import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; import '../config.dart'; class StudentManagementController extends ChangeNotifier { List _students = []; bool _isLoading = true; List get students => _students; bool get isLoading => _isLoading; Future init() => fetchStudents(); /// 🌐 μ„œλ²„μ—μ„œ 전체 학생 λͺ©λ‘ 뢈러였기. μ‹€νŒ¨ μ‹œ μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό λ°˜ν™˜ν•œλ‹€(성곡 μ‹œ null). Future fetchStudents() async { _isLoading = true; notifyListeners(); try { final response = await http.get(Uri.parse('$baseUrl/api/users')); if (response.statusCode == 200) { final data = jsonDecode(utf8.decode(response.bodyBytes)); _students = data['users'] ?? []; _isLoading = false; notifyListeners(); return null; } _isLoading = false; notifyListeners(); return '데이터 뢈러였기 μ‹€νŒ¨ (${response.statusCode})'; } catch (e) { _isLoading = false; notifyListeners(); return '데이터 뢈러였기 μ‹€νŒ¨: $e'; } } /// 🌐 μ„œλ²„λ‘œ κΈ°κΈ° μ΄ˆκΈ°ν™”(리셋) λͺ…λ Ή 보내기 Future<(bool success, String message)> resetDevice( String studentId, String studentName, ) async { try { final response = await http.post( Uri.parse('$baseUrl/api/users/reset'), headers: {"Content-Type": "application/json"}, body: jsonEncode({"studentId": studentId}), ); if (response.statusCode == 200) { await fetchStudents(); return (true, 'βœ… $studentName 학생 κΈ°κΈ° μ΄ˆκΈ°ν™” μ™„λ£Œ!'); } return (false, '❌ μ΄ˆκΈ°ν™” 톡신 μ‹€νŒ¨'); } catch (e) { return (false, '❌ μ΄ˆκΈ°ν™” 톡신 μ‹€νŒ¨'); } } /// 🌐 μ„œλ²„λ‘œ 계정 μ™„μ „ μ‚­μ œ λͺ…λ Ή 보내기 Future<(bool success, String message)> deleteUser( String studentId, String studentName, ) async { try { final response = await http.delete( Uri.parse('$baseUrl/api/users/delete'), headers: {"Content-Type": "application/json"}, body: jsonEncode({"studentId": studentId}), ); if (response.statusCode == 200) { await fetchStudents(); return (true, 'πŸ’₯ $studentName ν•™μƒμ˜ 계정이 영ꡬ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.'); } return (false, '❌ 계정 μ‚­μ œ 톡신 μ‹€νŒ¨'); } catch (e) { return (false, '❌ 계정 μ‚­μ œ 톡신 μ‹€νŒ¨'); } } /// 🌐 μ‹ κ·œ 학생 계정 생성 Future<(bool success, String message)> createUser( String studentId, String name, ) async { try { final response = await http.post( Uri.parse('$baseUrl/api/users/create'), headers: {"Content-Type": "application/json"}, body: jsonEncode({"studentId": studentId, "name": name}), ); final res = jsonDecode(response.body); if (res['status'] == 'success') { await fetchStudents(); return (true, 'βœ… ${res['message']}'); } return (false, '❌ ${res['message']}'); } catch (e) { return (false, '❌ 학생 등둝 μ‹€νŒ¨ (톡신 μ—λŸ¬)'); } } }