그룹 스터디 공개/비공개 기능 추가

그룹을 공개로 만들면 "공개 그룹" 목록에 뜨고, 학생이 참여 신청을
보내면 그룹장이 허용/거절할 수 있다. 그룹 상세 화면에 그룹장 전용
공개/비공개 전환 버튼과 대기 중인 참여 신청 목록을 추가.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-22 03:49:35 +00:00
co-authored by Claude Sonnet 5
parent 1140747af2
commit 4f64315197
4 changed files with 418 additions and 31 deletions
+45 -2
View File
@@ -14,12 +14,14 @@ class GroupController extends ChangeNotifier {
bool _isBusy = false;
List<dynamic> _groups = [];
List<dynamic> _invites = [];
List<dynamic> _publicGroups = [];
bool _disposed = false;
bool get isLoading => _isLoading;
bool get isBusy => _isBusy;
List<dynamic> get groups => _groups;
List<dynamic> get invites => _invites;
List<dynamic> get publicGroups => _publicGroups;
void _safeNotify() {
if (!_disposed) notifyListeners();
@@ -36,7 +38,7 @@ class GroupController extends ChangeNotifier {
Future<void> refresh() async {
_isLoading = true;
_safeNotify();
await Future.wait([_fetchGroups(), _fetchInvites()]);
await Future.wait([_fetchGroups(), _fetchInvites(), _fetchPublicGroups()]);
_isLoading = false;
_safeNotify();
}
@@ -69,7 +71,24 @@ class GroupController extends ChangeNotifier {
}
}
Future<(bool success, String message)> createGroup(String name) async {
Future<void> _fetchPublicGroups() async {
try {
final response = await http.get(
Uri.parse('$baseUrl/api/groups/public?studentId=$studentId'),
);
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
_publicGroups = data['groups'] ?? [];
}
} catch (_) {
// 조용히 무시
}
}
Future<(bool success, String message)> createGroup(
String name, {
bool isPublic = false,
}) async {
_isBusy = true;
_safeNotify();
try {
@@ -80,6 +99,7 @@ class GroupController extends ChangeNotifier {
"ownerId": studentId,
"ownerName": studentName,
"name": name.trim(),
"isPublic": isPublic,
}),
);
final result = jsonDecode(utf8.decode(response.bodyBytes));
@@ -121,4 +141,27 @@ class GroupController extends ChangeNotifier {
_safeNotify();
}
}
Future<(bool success, String message)> requestJoin(int groupId) async {
_isBusy = true;
_safeNotify();
try {
final response = await http.post(
Uri.parse('$baseUrl/api/groups/$groupId/join-request'),
headers: {"Content-Type": "application/json"},
body: jsonEncode({"studentId": studentId, "studentName": studentName}),
);
final result = jsonDecode(utf8.decode(response.bodyBytes));
if (response.statusCode == 200 && result['status'] == 'success') {
await _fetchPublicGroups();
return (true, '${result['message'] ?? '참여 신청을 보냈습니다.'}');
}
return (false, '${result['message'] ?? '참여 신청 실패'}');
} catch (e) {
return (false, '네트워크 에러: $e');
} finally {
_isBusy = false;
_safeNotify();
}
}
}