익명 커뮤니티 게시판(백판) 기능 추가
디시인사이드식 고정 카테고리 게시판 + 에타 스타일 익명(글 안에서만 유효한 익명 번호) 댓글. 신고는 자동 삭제 없이 운영자(교사/관리자) 검토 후 처리하도록 별도 신고 검토 화면을 대시보드에 추가. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// ✍️ 커뮤니티 게시판 - 글쓰기 화면의 기능(서버 통신/상태) 담당 컨트롤러.
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../config.dart';
|
||||
|
||||
class BoardWriteController extends ChangeNotifier {
|
||||
final String studentId;
|
||||
|
||||
BoardWriteController({required this.studentId});
|
||||
|
||||
bool _isSubmitting = false;
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
|
||||
Future<(bool success, String message)> submit({
|
||||
required String category,
|
||||
required String title,
|
||||
required String content,
|
||||
}) async {
|
||||
if (title.trim().isEmpty || content.trim().isEmpty) {
|
||||
return (false, '제목과 내용을 입력해주세요.');
|
||||
}
|
||||
_isSubmitting = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/board/posts'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"studentId": studentId,
|
||||
"category": category,
|
||||
"title": title.trim(),
|
||||
"content": content.trim(),
|
||||
}),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
return (true, '게시글이 등록되었습니다.');
|
||||
}
|
||||
return (false, '${result['message'] ?? '게시글 등록 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isSubmitting = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user