// ๐Ÿšฉ ์ปค๋ฎค๋‹ˆํ‹ฐ ๊ฒŒ์‹œํŒ - ์‹ ๊ณ  ๊ฒ€ํ† (์šด์˜์ž์šฉ) ํ™”๋ฉด์˜ ๊ธฐ๋Šฅ(์„œ๋ฒ„ ํ†ต์‹ /์ƒํƒœ) ๋‹ด๋‹น ์ปจํŠธ๋กค๋Ÿฌ. import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; import '../config.dart'; class BoardReportController extends ChangeNotifier { final String reviewerId; BoardReportController({required this.reviewerId}); bool _isLoading = true; bool _isBusy = false; List _reports = []; bool _disposed = false; bool get isLoading => _isLoading; bool get isBusy => _isBusy; List get reports => _reports; void _safeNotify() { if (!_disposed) notifyListeners(); } @override void dispose() { _disposed = true; super.dispose(); } Future init() => fetchPending(); Future fetchPending() async { _isLoading = true; _safeNotify(); try { final response = await http.get( Uri.parse('$baseUrl/api/board/reports?status=pending'), ); if (response.statusCode == 200) { final data = jsonDecode(utf8.decode(response.bodyBytes)); _reports = data['reports'] ?? []; } } catch (_) { // ์กฐ์šฉํžˆ ๋ฌด์‹œ - ๋งˆ์ง€๋ง‰์œผ๋กœ ๋ฐ›์•„์˜จ ๋ชฉ๋ก์„ ์œ ์ง€ํ•œ๋‹ค. } finally { _isLoading = false; _safeNotify(); } } Future<(bool success, String message)> resolve( int reportId, String action, ) async { _isBusy = true; _safeNotify(); try { final response = await http.post( Uri.parse('$baseUrl/api/board/reports/$reportId/resolve'), headers: {"Content-Type": "application/json"}, body: jsonEncode({"reviewerId": reviewerId, "action": action}), ); final result = jsonDecode(utf8.decode(response.bodyBytes)); if (response.statusCode == 200 && result['status'] == 'success') { await fetchPending(); return (true, '${result['message'] ?? '์ฒ˜๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'}'); } return (false, '${result['message'] ?? '์ฒ˜๋ฆฌ ์‹คํŒจ'}'); } catch (e) { return (false, '๋„คํŠธ์›Œํฌ ์—๋Ÿฌ: $e'); } finally { _isBusy = false; _safeNotify(); } } }