From 3d730ae4f08bd958cb98133c54506a88ec89247f Mon Sep 17 00:00:00 2001 From: sidhdhi canopas <122426509+cp-sidhdhi-p@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:47:54 +0530 Subject: [PATCH] add duplicate data for easy fetch (#71) --- data/lib/api/match/match_model.dart | 6 + data/lib/api/match/match_model.freezed.dart | 182 +++++++++++++- data/lib/api/match/match_model.g.dart | 30 +++ data/lib/service/match/match_service.dart | 235 ++++++++---------- .../utils/constant/firestore_constant.dart | 2 + khelo/lib/ui/flow/intro/intro_screen.dart | 3 +- .../add_match/add_match_view_model.dart | 6 + .../sign_in_with_phone_screen.dart | 3 +- 8 files changed, 337 insertions(+), 130 deletions(-) diff --git a/data/lib/api/match/match_model.dart b/data/lib/api/match/match_model.dart index a76e825c..e1d9394e 100644 --- a/data/lib/api/match/match_model.dart +++ b/data/lib/api/match/match_model.dart @@ -16,6 +16,9 @@ class MatchModel with _$MatchModel { required MatchType match_type, required int number_of_over, required int over_per_bowler, + @Default([]) List players, + @Default([]) List team_ids, + @Default([]) List team_creator_ids, @Default([]) List power_play_overs1, @Default([]) List power_play_overs2, @Default([]) List power_play_overs3, @@ -139,6 +142,9 @@ class AddEditMatchRequest with _$AddEditMatchRequest { required List teams, required MatchType match_type, required int number_of_over, + @Default([]) List players, + @Default([]) List team_ids, + @Default([]) List team_creator_ids, required int over_per_bowler, List? power_play_overs1, List? power_play_overs2, diff --git a/data/lib/api/match/match_model.freezed.dart b/data/lib/api/match/match_model.freezed.dart index df65e5f4..02f753e0 100644 --- a/data/lib/api/match/match_model.freezed.dart +++ b/data/lib/api/match/match_model.freezed.dart @@ -25,6 +25,9 @@ mixin _$MatchModel { MatchType get match_type => throw _privateConstructorUsedError; int get number_of_over => throw _privateConstructorUsedError; int get over_per_bowler => throw _privateConstructorUsedError; + List get players => throw _privateConstructorUsedError; + List get team_ids => throw _privateConstructorUsedError; + List get team_creator_ids => throw _privateConstructorUsedError; List get power_play_overs1 => throw _privateConstructorUsedError; List get power_play_overs2 => throw _privateConstructorUsedError; List get power_play_overs3 => throw _privateConstructorUsedError; @@ -61,6 +64,9 @@ abstract class $MatchModelCopyWith<$Res> { MatchType match_type, int number_of_over, int over_per_bowler, + List players, + List team_ids, + List team_creator_ids, List power_play_overs1, List power_play_overs2, List power_play_overs3, @@ -100,6 +106,9 @@ class _$MatchModelCopyWithImpl<$Res, $Val extends MatchModel> Object? match_type = null, Object? number_of_over = null, Object? over_per_bowler = null, + Object? players = null, + Object? team_ids = null, + Object? team_creator_ids = null, Object? power_play_overs1 = null, Object? power_play_overs2 = null, Object? power_play_overs3 = null, @@ -139,6 +148,18 @@ class _$MatchModelCopyWithImpl<$Res, $Val extends MatchModel> ? _value.over_per_bowler : over_per_bowler // ignore: cast_nullable_to_non_nullable as int, + players: null == players + ? _value.players + : players // ignore: cast_nullable_to_non_nullable + as List, + team_ids: null == team_ids + ? _value.team_ids + : team_ids // ignore: cast_nullable_to_non_nullable + as List, + team_creator_ids: null == team_creator_ids + ? _value.team_creator_ids + : team_creator_ids // ignore: cast_nullable_to_non_nullable + as List, power_play_overs1: null == power_play_overs1 ? _value.power_play_overs1 : power_play_overs1 // ignore: cast_nullable_to_non_nullable @@ -237,6 +258,9 @@ abstract class _$$MatchModelImplCopyWith<$Res> MatchType match_type, int number_of_over, int over_per_bowler, + List players, + List team_ids, + List team_creator_ids, List power_play_overs1, List power_play_overs2, List power_play_overs3, @@ -275,6 +299,9 @@ class __$$MatchModelImplCopyWithImpl<$Res> Object? match_type = null, Object? number_of_over = null, Object? over_per_bowler = null, + Object? players = null, + Object? team_ids = null, + Object? team_creator_ids = null, Object? power_play_overs1 = null, Object? power_play_overs2 = null, Object? power_play_overs3 = null, @@ -314,6 +341,18 @@ class __$$MatchModelImplCopyWithImpl<$Res> ? _value.over_per_bowler : over_per_bowler // ignore: cast_nullable_to_non_nullable as int, + players: null == players + ? _value._players + : players // ignore: cast_nullable_to_non_nullable + as List, + team_ids: null == team_ids + ? _value._team_ids + : team_ids // ignore: cast_nullable_to_non_nullable + as List, + team_creator_ids: null == team_creator_ids + ? _value._team_creator_ids + : team_creator_ids // ignore: cast_nullable_to_non_nullable + as List, power_play_overs1: null == power_play_overs1 ? _value._power_play_overs1 : power_play_overs1 // ignore: cast_nullable_to_non_nullable @@ -395,6 +434,9 @@ class _$MatchModelImpl implements _MatchModel { required this.match_type, required this.number_of_over, required this.over_per_bowler, + final List players = const [], + final List team_ids = const [], + final List team_creator_ids = const [], final List power_play_overs1 = const [], final List power_play_overs2 = const [], final List power_play_overs3 = const [], @@ -413,6 +455,9 @@ class _$MatchModelImpl implements _MatchModel { this.toss_winner_id, this.current_playing_team_id}) : _teams = teams, + _players = players, + _team_ids = team_ids, + _team_creator_ids = team_creator_ids, _power_play_overs1 = power_play_overs1, _power_play_overs2 = power_play_overs2, _power_play_overs3 = power_play_overs3, @@ -439,6 +484,34 @@ class _$MatchModelImpl implements _MatchModel { final int number_of_over; @override final int over_per_bowler; + final List _players; + @override + @JsonKey() + List get players { + if (_players is EqualUnmodifiableListView) return _players; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_players); + } + + final List _team_ids; + @override + @JsonKey() + List get team_ids { + if (_team_ids is EqualUnmodifiableListView) return _team_ids; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_team_ids); + } + + final List _team_creator_ids; + @override + @JsonKey() + List get team_creator_ids { + if (_team_creator_ids is EqualUnmodifiableListView) + return _team_creator_ids; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_team_creator_ids); + } + final List _power_play_overs1; @override @JsonKey() @@ -524,7 +597,7 @@ class _$MatchModelImpl implements _MatchModel { @override String toString() { - return 'MatchModel(id: $id, teams: $teams, match_type: $match_type, number_of_over: $number_of_over, over_per_bowler: $over_per_bowler, power_play_overs1: $power_play_overs1, power_play_overs2: $power_play_overs2, power_play_overs3: $power_play_overs3, city: $city, ground: $ground, start_time: $start_time, ball_type: $ball_type, pitch_type: $pitch_type, created_by: $created_by, umpires: $umpires, scorers: $scorers, commentators: $commentators, referee: $referee, match_status: $match_status, toss_decision: $toss_decision, toss_winner_id: $toss_winner_id, current_playing_team_id: $current_playing_team_id)'; + return 'MatchModel(id: $id, teams: $teams, match_type: $match_type, number_of_over: $number_of_over, over_per_bowler: $over_per_bowler, players: $players, team_ids: $team_ids, team_creator_ids: $team_creator_ids, power_play_overs1: $power_play_overs1, power_play_overs2: $power_play_overs2, power_play_overs3: $power_play_overs3, city: $city, ground: $ground, start_time: $start_time, ball_type: $ball_type, pitch_type: $pitch_type, created_by: $created_by, umpires: $umpires, scorers: $scorers, commentators: $commentators, referee: $referee, match_status: $match_status, toss_decision: $toss_decision, toss_winner_id: $toss_winner_id, current_playing_team_id: $current_playing_team_id)'; } @override @@ -540,6 +613,10 @@ class _$MatchModelImpl implements _MatchModel { other.number_of_over == number_of_over) && (identical(other.over_per_bowler, over_per_bowler) || other.over_per_bowler == over_per_bowler) && + const DeepCollectionEquality().equals(other._players, _players) && + const DeepCollectionEquality().equals(other._team_ids, _team_ids) && + const DeepCollectionEquality() + .equals(other._team_creator_ids, _team_creator_ids) && const DeepCollectionEquality() .equals(other._power_play_overs1, _power_play_overs1) && const DeepCollectionEquality() @@ -581,6 +658,9 @@ class _$MatchModelImpl implements _MatchModel { match_type, number_of_over, over_per_bowler, + const DeepCollectionEquality().hash(_players), + const DeepCollectionEquality().hash(_team_ids), + const DeepCollectionEquality().hash(_team_creator_ids), const DeepCollectionEquality().hash(_power_play_overs1), const DeepCollectionEquality().hash(_power_play_overs2), const DeepCollectionEquality().hash(_power_play_overs3), @@ -621,6 +701,9 @@ abstract class _MatchModel implements MatchModel { required final MatchType match_type, required final int number_of_over, required final int over_per_bowler, + final List players, + final List team_ids, + final List team_creator_ids, final List power_play_overs1, final List power_play_overs2, final List power_play_overs3, @@ -653,6 +736,12 @@ abstract class _MatchModel implements MatchModel { @override int get over_per_bowler; @override + List get players; + @override + List get team_ids; + @override + List get team_creator_ids; + @override List get power_play_overs1; @override List get power_play_overs2; @@ -1173,6 +1262,9 @@ mixin _$AddEditMatchRequest { List get teams => throw _privateConstructorUsedError; MatchType get match_type => throw _privateConstructorUsedError; int get number_of_over => throw _privateConstructorUsedError; + List get players => throw _privateConstructorUsedError; + List get team_ids => throw _privateConstructorUsedError; + List get team_creator_ids => throw _privateConstructorUsedError; int get over_per_bowler => throw _privateConstructorUsedError; List? get power_play_overs1 => throw _privateConstructorUsedError; List? get power_play_overs2 => throw _privateConstructorUsedError; @@ -1209,6 +1301,9 @@ abstract class $AddEditMatchRequestCopyWith<$Res> { List teams, MatchType match_type, int number_of_over, + List players, + List team_ids, + List team_creator_ids, int over_per_bowler, List? power_play_overs1, List? power_play_overs2, @@ -1246,6 +1341,9 @@ class _$AddEditMatchRequestCopyWithImpl<$Res, $Val extends AddEditMatchRequest> Object? teams = null, Object? match_type = null, Object? number_of_over = null, + Object? players = null, + Object? team_ids = null, + Object? team_creator_ids = null, Object? over_per_bowler = null, Object? power_play_overs1 = freezed, Object? power_play_overs2 = freezed, @@ -1282,6 +1380,18 @@ class _$AddEditMatchRequestCopyWithImpl<$Res, $Val extends AddEditMatchRequest> ? _value.number_of_over : number_of_over // ignore: cast_nullable_to_non_nullable as int, + players: null == players + ? _value.players + : players // ignore: cast_nullable_to_non_nullable + as List, + team_ids: null == team_ids + ? _value.team_ids + : team_ids // ignore: cast_nullable_to_non_nullable + as List, + team_creator_ids: null == team_creator_ids + ? _value.team_creator_ids + : team_creator_ids // ignore: cast_nullable_to_non_nullable + as List, over_per_bowler: null == over_per_bowler ? _value.over_per_bowler : over_per_bowler // ignore: cast_nullable_to_non_nullable @@ -1371,6 +1481,9 @@ abstract class _$$AddEditMatchRequestImplCopyWith<$Res> List teams, MatchType match_type, int number_of_over, + List players, + List team_ids, + List team_creator_ids, int over_per_bowler, List? power_play_overs1, List? power_play_overs2, @@ -1406,6 +1519,9 @@ class __$$AddEditMatchRequestImplCopyWithImpl<$Res> Object? teams = null, Object? match_type = null, Object? number_of_over = null, + Object? players = null, + Object? team_ids = null, + Object? team_creator_ids = null, Object? over_per_bowler = null, Object? power_play_overs1 = freezed, Object? power_play_overs2 = freezed, @@ -1442,6 +1558,18 @@ class __$$AddEditMatchRequestImplCopyWithImpl<$Res> ? _value.number_of_over : number_of_over // ignore: cast_nullable_to_non_nullable as int, + players: null == players + ? _value._players + : players // ignore: cast_nullable_to_non_nullable + as List, + team_ids: null == team_ids + ? _value._team_ids + : team_ids // ignore: cast_nullable_to_non_nullable + as List, + team_creator_ids: null == team_creator_ids + ? _value._team_creator_ids + : team_creator_ids // ignore: cast_nullable_to_non_nullable + as List, over_per_bowler: null == over_per_bowler ? _value.over_per_bowler : over_per_bowler // ignore: cast_nullable_to_non_nullable @@ -1526,6 +1654,9 @@ class _$AddEditMatchRequestImpl implements _AddEditMatchRequest { required final List teams, required this.match_type, required this.number_of_over, + final List players = const [], + final List team_ids = const [], + final List team_creator_ids = const [], required this.over_per_bowler, final List? power_play_overs1, final List? power_play_overs2, @@ -1545,6 +1676,9 @@ class _$AddEditMatchRequestImpl implements _AddEditMatchRequest { this.toss_winner_id, this.current_playing_team_id}) : _teams = teams, + _players = players, + _team_ids = team_ids, + _team_creator_ids = team_creator_ids, _power_play_overs1 = power_play_overs1, _power_play_overs2 = power_play_overs2, _power_play_overs3 = power_play_overs3, @@ -1569,6 +1703,34 @@ class _$AddEditMatchRequestImpl implements _AddEditMatchRequest { final MatchType match_type; @override final int number_of_over; + final List _players; + @override + @JsonKey() + List get players { + if (_players is EqualUnmodifiableListView) return _players; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_players); + } + + final List _team_ids; + @override + @JsonKey() + List get team_ids { + if (_team_ids is EqualUnmodifiableListView) return _team_ids; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_team_ids); + } + + final List _team_creator_ids; + @override + @JsonKey() + List get team_creator_ids { + if (_team_creator_ids is EqualUnmodifiableListView) + return _team_creator_ids; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_team_creator_ids); + } + @override final int over_per_bowler; final List? _power_play_overs1; @@ -1659,7 +1821,7 @@ class _$AddEditMatchRequestImpl implements _AddEditMatchRequest { @override String toString() { - return 'AddEditMatchRequest(id: $id, teams: $teams, match_type: $match_type, number_of_over: $number_of_over, over_per_bowler: $over_per_bowler, power_play_overs1: $power_play_overs1, power_play_overs2: $power_play_overs2, power_play_overs3: $power_play_overs3, city: $city, ground: $ground, start_time: $start_time, ball_type: $ball_type, pitch_type: $pitch_type, created_by: $created_by, umpire_ids: $umpire_ids, scorer_ids: $scorer_ids, commentator_ids: $commentator_ids, referee_id: $referee_id, match_status: $match_status, toss_decision: $toss_decision, toss_winner_id: $toss_winner_id, current_playing_team_id: $current_playing_team_id)'; + return 'AddEditMatchRequest(id: $id, teams: $teams, match_type: $match_type, number_of_over: $number_of_over, players: $players, team_ids: $team_ids, team_creator_ids: $team_creator_ids, over_per_bowler: $over_per_bowler, power_play_overs1: $power_play_overs1, power_play_overs2: $power_play_overs2, power_play_overs3: $power_play_overs3, city: $city, ground: $ground, start_time: $start_time, ball_type: $ball_type, pitch_type: $pitch_type, created_by: $created_by, umpire_ids: $umpire_ids, scorer_ids: $scorer_ids, commentator_ids: $commentator_ids, referee_id: $referee_id, match_status: $match_status, toss_decision: $toss_decision, toss_winner_id: $toss_winner_id, current_playing_team_id: $current_playing_team_id)'; } @override @@ -1673,6 +1835,10 @@ class _$AddEditMatchRequestImpl implements _AddEditMatchRequest { other.match_type == match_type) && (identical(other.number_of_over, number_of_over) || other.number_of_over == number_of_over) && + const DeepCollectionEquality().equals(other._players, _players) && + const DeepCollectionEquality().equals(other._team_ids, _team_ids) && + const DeepCollectionEquality() + .equals(other._team_creator_ids, _team_creator_ids) && (identical(other.over_per_bowler, over_per_bowler) || other.over_per_bowler == over_per_bowler) && const DeepCollectionEquality() @@ -1718,6 +1884,9 @@ class _$AddEditMatchRequestImpl implements _AddEditMatchRequest { const DeepCollectionEquality().hash(_teams), match_type, number_of_over, + const DeepCollectionEquality().hash(_players), + const DeepCollectionEquality().hash(_team_ids), + const DeepCollectionEquality().hash(_team_creator_ids), over_per_bowler, const DeepCollectionEquality().hash(_power_play_overs1), const DeepCollectionEquality().hash(_power_play_overs2), @@ -1759,6 +1928,9 @@ abstract class _AddEditMatchRequest implements AddEditMatchRequest { required final List teams, required final MatchType match_type, required final int number_of_over, + final List players, + final List team_ids, + final List team_creator_ids, required final int over_per_bowler, final List? power_play_overs1, final List? power_play_overs2, @@ -1790,6 +1962,12 @@ abstract class _AddEditMatchRequest implements AddEditMatchRequest { @override int get number_of_over; @override + List get players; + @override + List get team_ids; + @override + List get team_creator_ids; + @override int get over_per_bowler; @override List? get power_play_overs1; diff --git a/data/lib/api/match/match_model.g.dart b/data/lib/api/match/match_model.g.dart index 1012c665..717b9432 100644 --- a/data/lib/api/match/match_model.g.dart +++ b/data/lib/api/match/match_model.g.dart @@ -15,6 +15,18 @@ _$MatchModelImpl _$$MatchModelImplFromJson(Map json) => match_type: $enumDecode(_$MatchTypeEnumMap, json['match_type']), number_of_over: (json['number_of_over'] as num).toInt(), over_per_bowler: (json['over_per_bowler'] as num).toInt(), + players: (json['players'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + team_ids: (json['team_ids'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + team_creator_ids: (json['team_creator_ids'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], power_play_overs1: (json['power_play_overs1'] as List?) ?.map((e) => (e as num).toInt()) .toList() ?? @@ -59,6 +71,9 @@ Map _$$MatchModelImplToJson(_$MatchModelImpl instance) => 'match_type': _$MatchTypeEnumMap[instance.match_type]!, 'number_of_over': instance.number_of_over, 'over_per_bowler': instance.over_per_bowler, + 'players': instance.players, + 'team_ids': instance.team_ids, + 'team_creator_ids': instance.team_creator_ids, 'power_play_overs1': instance.power_play_overs1, 'power_play_overs2': instance.power_play_overs2, 'power_play_overs3': instance.power_play_overs3, @@ -171,6 +186,18 @@ _$AddEditMatchRequestImpl _$$AddEditMatchRequestImplFromJson( .toList(), match_type: $enumDecode(_$MatchTypeEnumMap, json['match_type']), number_of_over: (json['number_of_over'] as num).toInt(), + players: (json['players'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + team_ids: (json['team_ids'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + team_creator_ids: (json['team_creator_ids'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], over_per_bowler: (json['over_per_bowler'] as num).toInt(), power_play_overs1: (json['power_play_overs1'] as List?) ?.map((e) => (e as num).toInt()) @@ -211,6 +238,9 @@ Map _$$AddEditMatchRequestImplToJson( 'teams': instance.teams, 'match_type': _$MatchTypeEnumMap[instance.match_type]!, 'number_of_over': instance.number_of_over, + 'players': instance.players, + 'team_ids': instance.team_ids, + 'team_creator_ids': instance.team_creator_ids, 'over_per_bowler': instance.over_per_bowler, 'power_play_overs1': instance.power_play_overs1, 'power_play_overs2': instance.power_play_overs2, diff --git a/data/lib/service/match/match_service.dart b/data/lib/service/match/match_service.dart index 6b52a84e..1bd70a56 100644 --- a/data/lib/service/match/match_service.dart +++ b/data/lib/service/match/match_service.dart @@ -36,45 +36,6 @@ class MatchService { this._currentUserId, ); - Future> getMatches() async { - try { - CollectionReference matchCollection = - _firestore.collection(FireStoreConst.matchesCollection); - - QuerySnapshot mainCollectionSnapshot = await matchCollection.get(); - List matches = []; - - for (QueryDocumentSnapshot mainDoc in mainCollectionSnapshot.docs) { - Map mainDocData = - mainDoc.data() as Map; - AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData); - - List teams = await getTeamsList(match.teams); - matches.add(MatchModel( - id: match.id, - teams: teams, - match_type: match.match_type, - number_of_over: match.number_of_over, - over_per_bowler: match.over_per_bowler, - city: match.city, - ground: match.ground, - start_time: match.start_time, - created_by: match.created_by, - ball_type: match.ball_type, - pitch_type: match.pitch_type, - match_status: match.match_status, - toss_winner_id: match.toss_winner_id, - toss_decision: match.toss_decision, - current_playing_team_id: match.current_playing_team_id, - )); - } - - return matches; - } catch (error, stack) { - throw AppError.fromError(error, stack); - } - } - Stream> getCurrentUserPlayedMatches() { if (_currentUserId == null) { return Stream.value([]); @@ -83,38 +44,44 @@ class MatchService { StreamController> controller = StreamController>(); - _firestore.collection(FireStoreConst.matchesCollection).snapshots().listen( - (QuerySnapshot> snapshot) async { - List matches = []; + _firestore + .collection(FireStoreConst.matchesCollection) + .where( + Filter.and( + Filter(FireStoreConst.matchStatus, + isEqualTo: MatchStatus.finish.value), + Filter(FireStoreConst.players, arrayContains: _currentUserId), + ), + ) + .snapshots() + .listen((QuerySnapshot> snapshot) async { try { - for (QueryDocumentSnapshot mainDoc in snapshot.docs) { - Map mainDocData = - mainDoc.data() as Map; + List matches = []; + matches = await Future.wait(snapshot.docs.map((mainDoc) async { + Map mainDocData = mainDoc.data(); AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData); - if (match.teams - .map((e) => e.squad.map((e) => e.id).contains(_currentUserId)) - .contains(true) && - match.match_status == MatchStatus.finish) { - List teams = await getTeamsList(match.teams); - matches.add(MatchModel( - id: match.id, - teams: teams, - match_type: match.match_type, - number_of_over: match.number_of_over, - over_per_bowler: match.over_per_bowler, - city: match.city, - ground: match.ground, - start_time: match.start_time, - created_by: match.created_by, - ball_type: match.ball_type, - pitch_type: match.pitch_type, - match_status: match.match_status, - toss_winner_id: match.toss_winner_id, - toss_decision: match.toss_decision, - current_playing_team_id: match.current_playing_team_id, - )); - } - } + List teams = await getTeamsList(match.teams); + return MatchModel( + id: match.id, + teams: teams, + match_type: match.match_type, + number_of_over: match.number_of_over, + over_per_bowler: match.over_per_bowler, + players: match.players, + team_ids: match.team_ids, + team_creator_ids: match.team_creator_ids, + city: match.city, + ground: match.ground, + start_time: match.start_time, + created_by: match.created_by, + ball_type: match.ball_type, + pitch_type: match.pitch_type, + match_status: match.match_status, + toss_winner_id: match.toss_winner_id, + toss_decision: match.toss_decision, + current_playing_team_id: match.current_playing_team_id, + ); + }).toList()); controller.add(matches); } catch (error, stack) { controller.addError(AppError.fromError(error, stack)); @@ -134,41 +101,43 @@ class MatchService { } StreamController> controller = StreamController>(); - - _firestore.collection(FireStoreConst.matchesCollection).snapshots().listen( - (QuerySnapshot> snapshot) async { - List matches = []; - + _firestore + .collection(FireStoreConst.matchesCollection) + .where(Filter.or( + Filter(FireStoreConst.createdBy, isEqualTo: _currentUserId), + Filter(FireStoreConst.players, arrayContains: _currentUserId), + Filter(FireStoreConst.teamCreatorIds, arrayContains: _currentUserId), + )) + .snapshots() + .listen((QuerySnapshot> snapshot) async { try { - for (QueryDocumentSnapshot mainDoc in snapshot.docs) { - Map mainDocData = - mainDoc.data() as Map; + List matches = []; + matches = await Future.wait(snapshot.docs.map((mainDoc) async { + Map mainDocData = mainDoc.data(); AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData); List teams = await getTeamsList(match.teams); - if (teams.any((team) => - team.team.players - ?.map((player) => player.id) - .contains(_currentUserId) ?? - false || team.team.created_by == _currentUserId)) { - matches.add(MatchModel( - id: match.id, - teams: teams, - match_type: match.match_type, - number_of_over: match.number_of_over, - over_per_bowler: match.over_per_bowler, - city: match.city, - ground: match.ground, - start_time: match.start_time, - created_by: match.created_by, - ball_type: match.ball_type, - pitch_type: match.pitch_type, - match_status: match.match_status, - toss_winner_id: match.toss_winner_id, - toss_decision: match.toss_decision, - current_playing_team_id: match.current_playing_team_id, - )); - } - } + return MatchModel( + id: match.id, + teams: teams, + match_type: match.match_type, + number_of_over: match.number_of_over, + over_per_bowler: match.over_per_bowler, + city: match.city, + players: match.players, + team_ids: match.team_ids, + team_creator_ids: match.team_creator_ids, + ground: match.ground, + start_time: match.start_time, + created_by: match.created_by, + ball_type: match.ball_type, + pitch_type: match.pitch_type, + match_status: match.match_status, + toss_winner_id: match.toss_winner_id, + toss_decision: match.toss_decision, + current_playing_team_id: match.current_playing_team_id, + ); + }).toList()); + controller.add(matches); } catch (error, stack) { controller.addError(AppError.fromError(error, stack)); @@ -187,36 +156,40 @@ class MatchService { CollectionReference matchCollection = _firestore.collection(FireStoreConst.matchesCollection); - QuerySnapshot mainCollectionSnapshot = await matchCollection.get(); + QuerySnapshot mainCollectionSnapshot = await matchCollection + .where(FireStoreConst.teamIds, arrayContains: teamId) + .get(); List matches = []; - for (QueryDocumentSnapshot mainDoc in mainCollectionSnapshot.docs) { + matches = + await Future.wait(mainCollectionSnapshot.docs.map((mainDoc) async { Map mainDocData = mainDoc.data() as Map; AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData); - if (match.teams.map((e) => e.team_id).contains(teamId)) { - List teams = await getTeamsList(match.teams); - matches.add(MatchModel( - id: match.id, - teams: teams, - match_type: match.match_type, - number_of_over: match.number_of_over, - over_per_bowler: match.over_per_bowler, - city: match.city, - ground: match.ground, - start_time: match.start_time, - created_by: match.created_by, - ball_type: match.ball_type, - pitch_type: match.pitch_type, - match_status: match.match_status, - toss_winner_id: match.toss_winner_id, - toss_decision: match.toss_decision, - current_playing_team_id: match.current_playing_team_id, - )); - } - } + List teams = await getTeamsList(match.teams); + return MatchModel( + id: match.id, + teams: teams, + match_type: match.match_type, + number_of_over: match.number_of_over, + over_per_bowler: match.over_per_bowler, + players: match.players, + team_ids: match.team_ids, + team_creator_ids: match.team_creator_ids, + city: match.city, + ground: match.ground, + start_time: match.start_time, + created_by: match.created_by, + ball_type: match.ball_type, + pitch_type: match.pitch_type, + match_status: match.match_status, + toss_winner_id: match.toss_winner_id, + toss_decision: match.toss_decision, + current_playing_team_id: match.current_playing_team_id, + ); + }).toList()); return matches; } catch (error, stack) { throw AppError.fromError(error, stack); @@ -229,7 +202,7 @@ class MatchService { _firestore .collection(FireStoreConst.matchesCollection) - .where(FireStoreConst.matchStatus, isEqualTo: 2) + .where(FireStoreConst.matchStatus, isEqualTo: MatchStatus.running.value) .snapshots() .listen((QuerySnapshot> snapshot) async { List matches = []; @@ -237,7 +210,8 @@ class MatchService { for (QueryDocumentSnapshot mainDoc in snapshot.docs) { Map mainDocData = mainDoc.data() as Map; - if (mainDocData[FireStoreConst.matchStatus] == 2) { + if (mainDocData[FireStoreConst.matchStatus] == + MatchStatus.running.value) { AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData); @@ -248,6 +222,9 @@ class MatchService { match_type: match.match_type, number_of_over: match.number_of_over, over_per_bowler: match.over_per_bowler, + players: match.players, + team_ids: match.team_ids, + team_creator_ids: match.team_creator_ids, city: match.city, ground: match.ground, start_time: match.start_time, @@ -306,6 +283,9 @@ class MatchService { match_type: match.match_type, number_of_over: match.number_of_over, over_per_bowler: match.over_per_bowler, + players: match.players, + team_ids: match.team_ids, + team_creator_ids: match.team_creator_ids, city: match.city, ground: match.ground, start_time: match.start_time, @@ -370,6 +350,9 @@ class MatchService { match_type: match.match_type, number_of_over: match.number_of_over, over_per_bowler: match.over_per_bowler, + players: match.players, + team_ids: match.team_ids, + team_creator_ids: match.team_creator_ids, city: match.city, ground: match.ground, start_time: match.start_time, diff --git a/data/lib/utils/constant/firestore_constant.dart b/data/lib/utils/constant/firestore_constant.dart index 8704eacf..cee197bc 100644 --- a/data/lib/utils/constant/firestore_constant.dart +++ b/data/lib/utils/constant/firestore_constant.dart @@ -19,6 +19,8 @@ class FireStoreConst { static const String matchStatus = "match_status"; static const String tossWinnerId = "toss_winner_id"; static const String tossDecision = "toss_decision"; + static const String teamIds = "team_ids"; + static const String teamCreatorIds = "team_creator_ids"; // innings field const static const String matchId = "match_id"; diff --git a/khelo/lib/ui/flow/intro/intro_screen.dart b/khelo/lib/ui/flow/intro/intro_screen.dart index 1383494b..25d021eb 100644 --- a/khelo/lib/ui/flow/intro/intro_screen.dart +++ b/khelo/lib/ui/flow/intro/intro_screen.dart @@ -26,7 +26,8 @@ class _IntroScreenState extends ConsumerState { return Stack( children: [ ListView( - padding: BottomStickyOverlay.padding + EdgeInsets.only(top: context.mediaQueryPadding.top), + padding: BottomStickyOverlay.padding + + EdgeInsets.only(top: context.mediaQueryPadding.top), children: [ Padding( padding: EdgeInsets.only( diff --git a/khelo/lib/ui/flow/matches/add_match/add_match_view_model.dart b/khelo/lib/ui/flow/matches/add_match/add_match_view_model.dart index dfe26f7f..00c1d658 100644 --- a/khelo/lib/ui/flow/matches/add_match/add_match_view_model.dart +++ b/khelo/lib/ui/flow/matches/add_match/add_match_view_model.dart @@ -152,9 +152,15 @@ class AddMatchViewNotifier extends StateNotifier { index: e.index)) .toList() ?? []; + final allPlayers = firstSquad.map((e) => e.id).toList(); + allPlayers.addAll(secondSquad.map((e) => e.id).toList()); final match = AddEditMatchRequest( id: matchId, + players: allPlayers.toSet().toList(), + team_ids: [state.teamA!.id!, state.teamB!.id!], + team_creator_ids: + {state.teamA!.created_by!, state.teamB!.created_by!}.toList(), teams: [ AddMatchTeamRequest( team_id: state.teamA!.id!, diff --git a/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart b/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart index 180ef06f..057c72cf 100644 --- a/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart +++ b/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_screen.dart @@ -34,7 +34,8 @@ class SignInWithPhoneScreen extends ConsumerWidget { children: [ ListView( padding: context.mediaQueryPadding + - const EdgeInsets.symmetric(horizontal: 16) + BottomStickyOverlay.padding, + const EdgeInsets.symmetric(horizontal: 16) + + BottomStickyOverlay.padding, children: [ Text( context.l10n.sign_in_verify_phone_number_title,