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

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

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
+73 -1
View File
@@ -13,11 +13,17 @@ class GroupDetailController extends ChangeNotifier {
bool _isLoading = true;
bool _isBusy = false;
List<dynamic> _members = [];
List<dynamic> _joinRequests = [];
bool _isPublic = false;
bool _disposed = false;
bool get isLoading => _isLoading;
bool get isBusy => _isBusy;
List<dynamic> get members => _members;
List<dynamic> get joinRequests => _joinRequests;
bool get isPublic => _isPublic;
bool get isOwner =>
_members.any((m) => m['studentId'] == studentId && m['role'] == 'owner');
void _safeNotify() {
if (!_disposed) notifyListeners();
@@ -41,11 +47,77 @@ class GroupDetailController extends ChangeNotifier {
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
_members = data['members'] ?? [];
_isPublic = data['isPublic'] == true;
}
} catch (_) {
// 조용히 무시
}
if (isOwner) await _fetchJoinRequests();
_isLoading = false;
_safeNotify();
}
Future<void> _fetchJoinRequests() async {
try {
final response = await http.get(
Uri.parse(
'$baseUrl/api/groups/$groupId/join-requests?ownerId=$studentId',
),
);
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
_joinRequests = data['requests'] ?? [];
}
} catch (_) {
// 조용히 무시
}
}
Future<(bool success, String message)> respondJoinRequest(
int requestId,
bool accept,
) async {
_isBusy = true;
_safeNotify();
try {
final response = await http.post(
Uri.parse('$baseUrl/api/groups/join-requests/$requestId/respond'),
headers: {"Content-Type": "application/json"},
body: jsonEncode({"responderId": studentId, "accept": accept}),
);
final result = jsonDecode(utf8.decode(response.bodyBytes));
if (response.statusCode == 200 && result['status'] == 'success') {
await refresh();
return (true, '${result['message'] ?? '처리했습니다.'}');
}
return (false, '${result['message'] ?? '처리 실패'}');
} catch (e) {
return (false, '네트워크 에러: $e');
} finally {
_isLoading = false;
_isBusy = false;
_safeNotify();
}
}
Future<(bool success, String message)> setVisibility(bool isPublic) async {
_isBusy = true;
_safeNotify();
try {
final response = await http.post(
Uri.parse('$baseUrl/api/groups/$groupId/visibility'),
headers: {"Content-Type": "application/json"},
body: jsonEncode({"ownerId": studentId, "isPublic": isPublic}),
);
final result = jsonDecode(utf8.decode(response.bodyBytes));
if (response.statusCode == 200 && result['status'] == 'success') {
await refresh();
return (true, '${result['message'] ?? '변경했습니다.'}');
}
return (false, '${result['message'] ?? '변경 실패'}');
} catch (e) {
return (false, '네트워크 에러: $e');
} finally {
_isBusy = false;
_safeNotify();
}
}