이벤트 가져오기 위젯 테스트 추가 및 테스트 훅 도입

This commit is contained in:
2025-09-12 06:33:44 +09:00
parent 107abc963f
commit a5f2544d11
121 changed files with 39277 additions and 3911 deletions
+23 -1
View File
@@ -13,6 +13,8 @@ class ScoreService with ChangeNotifier {
ApiService _apiService = ApiService();
String? _memberId;
String? _eventId;
DateTime? _lastLoadedAt;
String? _lastError;
// 테스트용 생성자
ScoreService.forTest(ApiService apiService, {String? clubId, String? memberId, String? eventId}) {
@@ -37,6 +39,8 @@ class ScoreService with ChangeNotifier {
List<Score> get scores => [..._scores];
bool get isLoading => _isLoading;
DateTime? get lastLoadedAt => _lastLoadedAt;
String? get lastError => _lastError;
// 초기화 함수
void initialize(String token) {
@@ -61,6 +65,7 @@ class ScoreService with ChangeNotifier {
print('fetchClubScores 호출됨: token=$_token');
_isLoading = true;
_lastError = null;
notifyListeners();
try {
@@ -92,9 +97,11 @@ class ScoreService with ChangeNotifier {
}
_isLoading = false;
_lastLoadedAt = DateTime.now();
notifyListeners();
} catch (e) {
_isLoading = false;
_lastError = e.toString();
notifyListeners();
throw Exception('점수 목록을 불러오는데 실패했습니다: $e');
}
@@ -107,6 +114,7 @@ class ScoreService with ChangeNotifier {
}
_isLoading = true;
_lastError = null;
notifyListeners();
try {
@@ -127,6 +135,7 @@ class ScoreService with ChangeNotifier {
return memberScores;
} catch (e) {
_isLoading = false;
_lastError = e.toString();
notifyListeners();
throw Exception('회원 점수를 불러오는데 실패했습니다: $e');
}
@@ -139,6 +148,7 @@ class ScoreService with ChangeNotifier {
}
_isLoading = true;
_lastError = null;
notifyListeners();
try {
@@ -159,6 +169,7 @@ class ScoreService with ChangeNotifier {
return eventScores;
} catch (e) {
_isLoading = false;
_lastError = e.toString();
notifyListeners();
throw Exception('이벤트 점수를 불러오는데 실패했습니다: $e');
}
@@ -171,6 +182,7 @@ class ScoreService with ChangeNotifier {
}
_isLoading = true;
_lastError = null;
notifyListeners();
try {
@@ -186,6 +198,7 @@ class ScoreService with ChangeNotifier {
return newScore;
} catch (e) {
_isLoading = false;
_lastError = e.toString();
notifyListeners();
throw Exception('점수 추가에 실패했습니다: $e');
}
@@ -223,6 +236,7 @@ class ScoreService with ChangeNotifier {
return updatedScore;
} catch (e) {
_isLoading = false;
_lastError = e.toString();
notifyListeners();
throw Exception('점수 수정에 실패했습니다: $e');
}
@@ -249,6 +263,7 @@ class ScoreService with ChangeNotifier {
return true;
} catch (e) {
_isLoading = false;
_lastError = e.toString();
notifyListeners();
throw Exception('점수 삭제에 실패했습니다: $e');
}
@@ -257,17 +272,21 @@ class ScoreService with ChangeNotifier {
// 회원 통계 가져오기
Future<ScoreStatistics> fetchMemberStatistics(String memberId) async {
if (_token == null || _clubId == null) {
throw Exception('인증 또는 클럽 정보가 필요합니다');
throw Exception('인증 정보가 필요합니다');
}
_lastError = null;
try {
final data = await _apiService.post(
'${ApiConfig.clubs}/members/stats',
data: {'memberId': memberId},
);
_lastLoadedAt = DateTime.now();
return ScoreStatistics.fromJson(data['statistics']);
} catch (e) {
_lastError = e.toString();
throw Exception('회원 통계를 불러오는데 실패했습니다: $e');
}
}
@@ -309,8 +328,11 @@ class ScoreService with ChangeNotifier {
});
}
_lastLoadedAt = DateTime.now();
_lastError = null;
return statistics;
} catch (e) {
_lastError = e.toString();
throw Exception('클럽 통계를 불러오는데 실패했습니다: $e');
}
}