// ๐Ÿ‘ฅ ๋ฐฑํ’ˆํƒ€ ๊ทธ๋ฃน ์ƒ์„ธ(๋ฉค๋ฒ„/์˜ค๋Š˜ ์ถœ์„/์ดˆ๋Œ€/๋‚˜๊ฐ€๊ธฐ) ํ™”๋ฉด์˜ ๊ธฐ๋Šฅ ๋‹ด๋‹น ์ปจํŠธ๋กค๋Ÿฌ. import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; import '../config.dart'; class GroupDetailController extends ChangeNotifier { final int groupId; final String studentId; GroupDetailController({required this.groupId, required this.studentId}); bool _isLoading = true; bool _isBusy = false; List _members = []; bool _disposed = false; bool get isLoading => _isLoading; bool get isBusy => _isBusy; List get members => _members; void _safeNotify() { if (!_disposed) notifyListeners(); } @override void dispose() { _disposed = true; super.dispose(); } Future init() => refresh(); Future refresh() async { _isLoading = true; _safeNotify(); try { final response = await http.get( Uri.parse('$baseUrl/api/groups/$groupId/members'), ); if (response.statusCode == 200) { final data = jsonDecode(utf8.decode(response.bodyBytes)); _members = data['members'] ?? []; } } catch (_) { // ์กฐ์šฉํžˆ ๋ฌด์‹œ } finally { _isLoading = false; _safeNotify(); } } Future<(bool success, String message)> invite( String inviteeId, String inviteeName, ) async { _isBusy = true; _safeNotify(); try { final response = await http.post( Uri.parse('$baseUrl/api/groups/$groupId/invite'), headers: {"Content-Type": "application/json"}, body: jsonEncode({ "inviterId": studentId, "inviteeId": inviteeId, "inviteeName": inviteeName, }), ); final result = jsonDecode(utf8.decode(response.bodyBytes)); if (response.statusCode == 200 && result['status'] == 'success') { return (true, '${result['message'] ?? '์ดˆ๋Œ€๋ฅผ ๋ณด๋ƒˆ์Šต๋‹ˆ๋‹ค.'}'); } return (false, '${result['message'] ?? '์ดˆ๋Œ€ ์‹คํŒจ'}'); } catch (e) { return (false, '๋„คํŠธ์›Œํฌ ์—๋Ÿฌ: $e'); } finally { _isBusy = false; _safeNotify(); } } Future<(bool success, String message)> leave() async { _isBusy = true; _safeNotify(); try { final response = await http.post( Uri.parse('$baseUrl/api/groups/$groupId/leave'), headers: {"Content-Type": "application/json"}, body: jsonEncode({"studentId": studentId}), ); final result = jsonDecode(utf8.decode(response.bodyBytes)); if (response.statusCode == 200 && result['status'] == 'success') { return (true, '${result['message'] ?? '๊ทธ๋ฃน์—์„œ ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.'}'); } return (false, '${result['message'] ?? '์ฒ˜๋ฆฌ ์‹คํŒจ'}'); } catch (e) { return (false, '๋„คํŠธ์›Œํฌ ์—๋Ÿฌ: $e'); } finally { _isBusy = false; _safeNotify(); } } }