78 lines
2.1 KiB
Dart
78 lines
2.1 KiB
Dart
// 🚩 커뮤니티 게시판 - 신고 검토(운영자용) 화면의 기능(서버 통신/상태) 담당 컨트롤러.
|
|||
|
|
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<dynamic> _reports = [];
|
||
|
|
bool _disposed = false;
|
||
|
|
|
||
|
|
bool get isLoading => _isLoading;
|
||
|
|
bool get isBusy => _isBusy;
|
||
|
|
List<dynamic> get reports => _reports;
|
||
|
|
|
||
|
|
void _safeNotify() {
|
||
|
|
if (!_disposed) notifyListeners();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void dispose() {
|
||
|
|
_disposed = true;
|
||
|
|
super.dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> init() => fetchPending();
|
||
|
|
|
||
|
|
Future<void> 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();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|