From 56af43c1eec4880cb9ffe999284e9fffe7d50d43 Mon Sep 17 00:00:00 2001 From: Mayank Variya Date: Fri, 11 Oct 2024 18:46:55 +0530 Subject: [PATCH] minor changes --- data/lib/service/match/match_service.dart | 11 ++---- data/lib/service/team/team_service.dart | 3 +- .../tournament/tournament_service.dart | 38 +++++++++---------- khelo/assets/locales/app_en.arb | 2 +- .../detail/tournament_detail_view_model.dart | 2 +- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/data/lib/service/match/match_service.dart b/data/lib/service/match/match_service.dart index cbd227ef..11b5dae7 100644 --- a/data/lib/service/match/match_service.dart +++ b/data/lib/service/match/match_service.dart @@ -465,15 +465,12 @@ class MatchService { } } - //Helper Methods Future> getMatchesByIds(List matchIds) async { try { - final List matches = []; - await Future.forEach(matchIds, (matchId) async { - final match = await getMatchById(matchId); - matches.add(match); - }); - return matches; + return await _matchCollection + .where(FieldPath.documentId, whereIn: matchIds) + .get() + .then((value) => value.docs.map((e) => e.data()).toList()); } catch (error, stack) { throw AppError.fromError(error, stack); } diff --git a/data/lib/service/team/team_service.dart b/data/lib/service/team/team_service.dart index 1d119eaf..3741ead9 100644 --- a/data/lib/service/team/team_service.dart +++ b/data/lib/service/team/team_service.dart @@ -269,11 +269,10 @@ class TeamService { Future> getTeamsByIds(List teamIds) async { try { - final teamList = await _teamsCollection + return await _teamsCollection .where(FieldPath.documentId, whereIn: teamIds) .get() .then((value) => value.docs.map((e) => e.data()).toList()); - return teamList; } catch (error, stack) { throw AppError.fromError(error, stack); } diff --git a/data/lib/service/tournament/tournament_service.dart b/data/lib/service/tournament/tournament_service.dart index 55bdfab9..f45076cc 100644 --- a/data/lib/service/tournament/tournament_service.dart +++ b/data/lib/service/tournament/tournament_service.dart @@ -10,28 +10,28 @@ import '../user/user_service.dart'; final tournamentServiceProvider = Provider( (ref) => TournamentService( - fireStore: FirebaseFirestore.instance, - teamService: ref.read(teamServiceProvider), - matchService: ref.read(matchServiceProvider), - userService: ref.read(userServiceProvider), + FirebaseFirestore.instance, + ref.read(teamServiceProvider), + ref.read(matchServiceProvider), + ref.read(userServiceProvider), ), ); class TournamentService { - final FirebaseFirestore fireStore; - final TeamService teamService; - final MatchService matchService; - final UserService userService; - - TournamentService({ - required this.fireStore, - required this.teamService, - required this.matchService, - required this.userService, - }); + final FirebaseFirestore _firestore; + final TeamService _teamService; + final MatchService _matchService; + final UserService _userService; + + TournamentService( + this._firestore, + this._teamService, + this._matchService, + this._userService, + ); CollectionReference get _tournamentCollection => - fireStore.collection(FireStoreConst.tournamentCollection).withConverter( + _firestore.collection(FireStoreConst.tournamentCollection).withConverter( fromFirestore: TournamentModel.fromFireStore, toFirestore: (TournamentModel tournament, _) => tournament.toJson(), ); @@ -86,18 +86,18 @@ class TournamentService { final matchIds = tournament.match_ids; if (teamIds.isNotEmpty) { - final teams = await teamService.getTeamsByIds(teamIds); + final teams = await _teamService.getTeamsByIds(teamIds); tournament = tournament.copyWith(teams: teams); } if (matchIds.isNotEmpty) { - final matches = await matchService.getMatchesByIds(matchIds); + final matches = await _matchService.getMatchesByIds(matchIds); tournament = tournament.copyWith(matches: matches); } if (tournament.members.isNotEmpty) { final memberIds = tournament.members.map((e) => e.id).toList(); - final users = await userService.getUsersByIds(memberIds); + final users = await _userService.getUsersByIds(memberIds); final members = tournament.members.map((member) { final user = users.firstWhere((element) => element.id == member.id); diff --git a/khelo/assets/locales/app_en.arb b/khelo/assets/locales/app_en.arb index 5fb4164b..ae1fb96f 100644 --- a/khelo/assets/locales/app_en.arb +++ b/khelo/assets/locales/app_en.arb @@ -167,7 +167,7 @@ "@_TOURNAMENT_DETAIL": { }, "tournament_detail_not_found_title": "No Tournament found", - "tournament_detail_not_found_description": "The tournament you are looking for does not available.", + "tournament_detail_not_found_description": "The tournament you are looking for is not available.", "tournament_detail_start_from_title": "Start from {date}", "@tournament_detail_start_from_title": { "description": "Start from {date}", diff --git a/khelo/lib/ui/flow/tournament/detail/tournament_detail_view_model.dart b/khelo/lib/ui/flow/tournament/detail/tournament_detail_view_model.dart index 3969801b..d1d53714 100644 --- a/khelo/lib/ui/flow/tournament/detail/tournament_detail_view_model.dart +++ b/khelo/lib/ui/flow/tournament/detail/tournament_detail_view_model.dart @@ -42,7 +42,7 @@ class TournamentDetailStateViewNotifier }, onError: (e) { state = state.copyWith(error: e, loading: false); debugPrint( - "TournamentListViewNotifier: error while loading tournament list -> $e"); + "TournamentDetailStateViewNotifier: error while loading tournament list -> $e"); }); }