백품타에 친구/그룹 스터디/출석 달력 기능 추가
친구 신청·수락, 그룹 생성·초대(친구 목록에서 선택)·오늘 출석 현황 공유, 개인 연속 출석(스트릭) 달력, 관리자가 날짜별로 선물/이벤트를 등록하는 달력 관리 화면을 추가. 대시보드에 학생용 3개(친구/그룹 스터디/출석 달력) + 교사·관리자용 1개(출석 달력 관리) 타일을 배치. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
// 🧑🤝🧑 백품타 친구 목록/신청 화면의 기능(서버 통신/상태) 담당 컨트롤러.
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../config.dart';
|
||||
|
||||
class FriendController extends ChangeNotifier {
|
||||
final String studentId;
|
||||
final String studentName;
|
||||
|
||||
FriendController({required this.studentId, required this.studentName});
|
||||
|
||||
bool _isLoading = true;
|
||||
bool _isBusy = false;
|
||||
List<dynamic> _friends = [];
|
||||
List<dynamic> _requests = [];
|
||||
bool _disposed = false;
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isBusy => _isBusy;
|
||||
List<dynamic> get friends => _friends;
|
||||
List<dynamic> get requests => _requests;
|
||||
|
||||
void _safeNotify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
await refresh();
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
_isLoading = true;
|
||||
_safeNotify();
|
||||
await Future.wait([_fetchFriends(), _fetchRequests()]);
|
||||
_isLoading = false;
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
Future<void> _fetchFriends() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/api/friends/list?studentId=$studentId'),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
_friends = data['friends'] ?? [];
|
||||
}
|
||||
} catch (_) {
|
||||
// 조용히 무시
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchRequests() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/api/friends/requests?studentId=$studentId'),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
_requests = data['requests'] ?? [];
|
||||
}
|
||||
} catch (_) {
|
||||
// 조용히 무시
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> sendRequest(String friendId) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/friends/request'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"studentId": studentId,
|
||||
"studentName": studentName,
|
||||
"friendId": friendId.trim(),
|
||||
}),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
return (true, '${result['message'] ?? '친구 신청을 보냈습니다.'}');
|
||||
}
|
||||
return (false, '${result['message'] ?? '친구 신청 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> respondRequest(
|
||||
int requestId,
|
||||
bool accept,
|
||||
) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/friends/respond'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"requestId": requestId,
|
||||
"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 {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> removeFriend(String friendId) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/api/friends'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({"studentId": studentId, "friendId": friendId}),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
await _fetchFriends();
|
||||
return (true, '${result['message'] ?? '삭제했습니다.'}');
|
||||
}
|
||||
return (false, '${result['message'] ?? '삭제 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
// 👥 백품타 그룹 스터디(목록/생성/초대) 화면의 기능(서버 통신/상태) 담당 컨트롤러.
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../config.dart';
|
||||
|
||||
class GroupController extends ChangeNotifier {
|
||||
final String studentId;
|
||||
final String studentName;
|
||||
|
||||
GroupController({required this.studentId, required this.studentName});
|
||||
|
||||
bool _isLoading = true;
|
||||
bool _isBusy = false;
|
||||
List<dynamic> _groups = [];
|
||||
List<dynamic> _invites = [];
|
||||
bool _disposed = false;
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isBusy => _isBusy;
|
||||
List<dynamic> get groups => _groups;
|
||||
List<dynamic> get invites => _invites;
|
||||
|
||||
void _safeNotify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> init() => refresh();
|
||||
|
||||
Future<void> refresh() async {
|
||||
_isLoading = true;
|
||||
_safeNotify();
|
||||
await Future.wait([_fetchGroups(), _fetchInvites()]);
|
||||
_isLoading = false;
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
Future<void> _fetchGroups() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/api/groups/mine?studentId=$studentId'),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
_groups = data['groups'] ?? [];
|
||||
}
|
||||
} catch (_) {
|
||||
// 조용히 무시
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchInvites() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/api/groups/invites?studentId=$studentId'),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
_invites = data['invites'] ?? [];
|
||||
}
|
||||
} catch (_) {
|
||||
// 조용히 무시
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> createGroup(String name) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/groups'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"ownerId": studentId,
|
||||
"ownerName": studentName,
|
||||
"name": name.trim(),
|
||||
}),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
await _fetchGroups();
|
||||
return (true, '${result['message'] ?? '그룹을 만들었습니다.'}');
|
||||
}
|
||||
return (false, '${result['message'] ?? '그룹 생성 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> respondInvite(
|
||||
int inviteId,
|
||||
bool accept,
|
||||
) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/groups/invites/$inviteId/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 {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// 👥 백품타 그룹 상세(멤버/오늘 출석/초대/나가기) 화면의 기능 담당 컨트롤러.
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../config.dart';
|
||||
|
||||
class GroupDetailController extends ChangeNotifier {
|
||||
final int groupId;
|
||||
final String studentId;
|
||||
|
||||
GroupDetailController({required this.groupId, required this.studentId});
|
||||
|
||||
bool _isLoading = true;
|
||||
bool _isBusy = false;
|
||||
List<dynamic> _members = [];
|
||||
bool _disposed = false;
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isBusy => _isBusy;
|
||||
List<dynamic> get members => _members;
|
||||
|
||||
void _safeNotify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> init() => refresh();
|
||||
|
||||
Future<void> refresh() async {
|
||||
_isLoading = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/api/groups/$groupId/members'),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
_members = data['members'] ?? [];
|
||||
}
|
||||
} catch (_) {
|
||||
// 조용히 무시
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> invite(
|
||||
String inviteeId,
|
||||
String inviteeName,
|
||||
) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/groups/$groupId/invite'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"inviterId": studentId,
|
||||
"inviteeId": inviteeId,
|
||||
"inviteeName": inviteeName,
|
||||
}),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
return (true, '${result['message'] ?? '초대를 보냈습니다.'}');
|
||||
}
|
||||
return (false, '${result['message'] ?? '초대 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> leave() async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/groups/$groupId/leave'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({"studentId": studentId}),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
return (true, '${result['message'] ?? '그룹에서 나갔습니다.'}');
|
||||
}
|
||||
return (false, '${result['message'] ?? '처리 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// 📅 백품타 출석 달력(개인 스트릭 + 관리자 이벤트) 화면의 기능 담당 컨트롤러.
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../config.dart';
|
||||
|
||||
class StudyCalendarController extends ChangeNotifier {
|
||||
final String studentId;
|
||||
|
||||
StudyCalendarController({required this.studentId});
|
||||
|
||||
bool _isLoading = true;
|
||||
bool _isBusy = false;
|
||||
int _currentStreak = 0;
|
||||
int _longestStreak = 0;
|
||||
Set<String> _studiedDates = {};
|
||||
Map<String, dynamic> _events = {}; // date -> {title, description}
|
||||
DateTime _visibleMonth = DateTime.now();
|
||||
bool _disposed = false;
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isBusy => _isBusy;
|
||||
int get currentStreak => _currentStreak;
|
||||
int get longestStreak => _longestStreak;
|
||||
Set<String> get studiedDates => _studiedDates;
|
||||
Map<String, dynamic> get events => _events;
|
||||
DateTime get visibleMonth => _visibleMonth;
|
||||
|
||||
void _safeNotify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> init() => refresh();
|
||||
|
||||
Future<void> goToPreviousMonth() async {
|
||||
_visibleMonth = DateTime(_visibleMonth.year, _visibleMonth.month - 1);
|
||||
await refresh();
|
||||
}
|
||||
|
||||
Future<void> goToNextMonth() async {
|
||||
_visibleMonth = DateTime(_visibleMonth.year, _visibleMonth.month + 1);
|
||||
await refresh();
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
_isLoading = true;
|
||||
_safeNotify();
|
||||
await Future.wait([_fetchStreak(), _fetchEvents()]);
|
||||
_isLoading = false;
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
Future<void> _fetchStreak() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
'$baseUrl/api/study/streak?studentId=$studentId'
|
||||
'&year=${_visibleMonth.year}&month=${_visibleMonth.month}',
|
||||
),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
_currentStreak = (data['currentStreak'] as num?)?.toInt() ?? 0;
|
||||
_longestStreak = (data['longestStreak'] as num?)?.toInt() ?? 0;
|
||||
_studiedDates = ((data['studiedDates'] as List<dynamic>?) ?? [])
|
||||
.map((d) => d.toString())
|
||||
.toSet();
|
||||
}
|
||||
} catch (_) {
|
||||
// 조용히 무시
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchEvents() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
'$baseUrl/api/calendar/events?year=${_visibleMonth.year}&month=${_visibleMonth.month}',
|
||||
),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
final List<dynamic> list = data['events'] ?? [];
|
||||
_events = {for (final e in list) e['date']: e};
|
||||
}
|
||||
} catch (_) {
|
||||
// 조용히 무시
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> saveEvent({
|
||||
required String date,
|
||||
required String title,
|
||||
required String description,
|
||||
required String createdBy,
|
||||
}) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/api/calendar/events'),
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode({
|
||||
"date": date,
|
||||
"title": title.trim(),
|
||||
"description": description.trim(),
|
||||
"createdBy": createdBy,
|
||||
}),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
await _fetchEvents();
|
||||
return (true, '${result['message'] ?? '등록했습니다.'}');
|
||||
}
|
||||
return (false, '${result['message'] ?? '등록 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
|
||||
Future<(bool success, String message)> deleteEvent(String date) async {
|
||||
_isBusy = true;
|
||||
_safeNotify();
|
||||
try {
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/api/calendar/events/$date'),
|
||||
);
|
||||
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200 && result['status'] == 'success') {
|
||||
await _fetchEvents();
|
||||
return (true, '${result['message'] ?? '삭제했습니다.'}');
|
||||
}
|
||||
return (false, '${result['message'] ?? '삭제 실패'}');
|
||||
} catch (e) {
|
||||
return (false, '네트워크 에러: $e');
|
||||
} finally {
|
||||
_isBusy = false;
|
||||
_safeNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user