Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-mayank committed Oct 11, 2024
1 parent 2697e5c commit 56af43c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
11 changes: 4 additions & 7 deletions data/lib/service/match/match_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,12 @@ class MatchService {
}
}

//Helper Methods
Future<List<MatchModel>> getMatchesByIds(List<String> matchIds) async {
try {
final List<MatchModel> 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);
}
Expand Down
3 changes: 1 addition & 2 deletions data/lib/service/team/team_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,10 @@ class TeamService {

Future<List<TeamModel>> getTeamsByIds(List<String> 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);
}
Expand Down
38 changes: 19 additions & 19 deletions data/lib/service/tournament/tournament_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<TournamentModel> get _tournamentCollection =>
fireStore.collection(FireStoreConst.tournamentCollection).withConverter(
_firestore.collection(FireStoreConst.tournamentCollection).withConverter(
fromFirestore: TournamentModel.fromFireStore,
toFirestore: (TournamentModel tournament, _) => tournament.toJson(),
);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}

Expand Down

0 comments on commit 56af43c

Please sign in to comment.