From cde5241ffc27b173862f4ff5e035364efbfba6e9 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Mon, 27 Nov 2023 12:36:42 +0100 Subject: [PATCH] feat(common): Use getter with freezed --- .../lib/src/data/bout_config.dart | 5 ++ .../lib/src/data/club.dart | 5 ++ .../lib/src/data/data_object.dart | 2 + .../lib/src/data/fight.dart | 5 ++ .../lib/src/data/fight_action.dart | 5 ++ .../lib/src/data/lineup.dart | 5 ++ .../lib/src/data/membership.dart | 5 ++ .../lib/src/data/participant_state.dart | 5 ++ .../lib/src/data/participation.dart | 5 ++ .../lib/src/data/person.dart | 5 ++ .../lib/src/data/team.dart | 5 ++ .../lib/src/data/team_match/league.dart | 5 ++ .../team_match/league_team_participation.dart | 5 ++ .../data/team_match/league_weight_class.dart | 5 ++ .../lib/src/data/team_match/team_match.dart | 5 ++ .../src/data/team_match/team_match_fight.dart | 5 ++ .../lib/src/data/tournament/tournament.dart | 5 ++ .../src/data/tournament/tournament_fight.dart | 5 ++ .../data/tournament/tournament_person.dart | 5 ++ .../tournament_team_participation.dart | 5 ++ .../lib/src/data/weight_class.dart | 5 ++ .../lib/src/util/data_wrapper.dart | 54 ++++++++++--------- 22 files changed, 130 insertions(+), 26 deletions(-) diff --git a/wrestling_scoreboard_common/lib/src/data/bout_config.dart b/wrestling_scoreboard_common/lib/src/data/bout_config.dart index 77b61a60..13011bf7 100644 --- a/wrestling_scoreboard_common/lib/src/data/bout_config.dart +++ b/wrestling_scoreboard_common/lib/src/data/bout_config.dart @@ -57,4 +57,9 @@ class BoutConfig with _$BoutConfig implements DataObject { @override String get tableName => 'bout_config'; + + @override + BoutConfig copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/club.dart b/wrestling_scoreboard_common/lib/src/data/club.dart index 8e61b2c6..0ce0a3f6 100644 --- a/wrestling_scoreboard_common/lib/src/data/club.dart +++ b/wrestling_scoreboard_common/lib/src/data/club.dart @@ -35,4 +35,9 @@ class Club with _$Club implements DataObject { @override String get tableName => 'club'; + + @override + Club copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/data_object.dart b/wrestling_scoreboard_common/lib/src/data/data_object.dart index 0955624f..3f03f3f2 100644 --- a/wrestling_scoreboard_common/lib/src/data/data_object.dart +++ b/wrestling_scoreboard_common/lib/src/data/data_object.dart @@ -10,6 +10,8 @@ abstract class DataObject { Map toRaw(); + DataObject copyWithId(int? id); + String get tableName; static T fromJson(Map json) { diff --git a/wrestling_scoreboard_common/lib/src/data/fight.dart b/wrestling_scoreboard_common/lib/src/data/fight.dart index 747b4988..920ac41d 100644 --- a/wrestling_scoreboard_common/lib/src/data/fight.dart +++ b/wrestling_scoreboard_common/lib/src/data/fight.dart @@ -180,4 +180,9 @@ class Fight with _$Fight implements DataObject { return 0; } } + + @override + Fight copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/fight_action.dart b/wrestling_scoreboard_common/lib/src/data/fight_action.dart index b9beaa62..2f85077b 100644 --- a/wrestling_scoreboard_common/lib/src/data/fight_action.dart +++ b/wrestling_scoreboard_common/lib/src/data/fight_action.dart @@ -65,4 +65,9 @@ class FightAction with _$FightAction implements DataObject { @override String get tableName => 'fight_action'; + + @override + FightAction copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/lineup.dart b/wrestling_scoreboard_common/lib/src/data/lineup.dart index 72583bf0..a25f8639 100644 --- a/wrestling_scoreboard_common/lib/src/data/lineup.dart +++ b/wrestling_scoreboard_common/lib/src/data/lineup.dart @@ -43,4 +43,9 @@ class Lineup with _$Lineup implements DataObject { @override String get tableName => 'lineup'; + + @override + Lineup copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/membership.dart b/wrestling_scoreboard_common/lib/src/data/membership.dart index 456c5f87..feb4506f 100644 --- a/wrestling_scoreboard_common/lib/src/data/membership.dart +++ b/wrestling_scoreboard_common/lib/src/data/membership.dart @@ -44,4 +44,9 @@ class Membership with _$Membership implements DataObject { @override String get tableName => 'membership'; + + @override + Membership copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/participant_state.dart b/wrestling_scoreboard_common/lib/src/data/participant_state.dart index 7bd5be29..b68e9a99 100644 --- a/wrestling_scoreboard_common/lib/src/data/participant_state.dart +++ b/wrestling_scoreboard_common/lib/src/data/participant_state.dart @@ -54,4 +54,9 @@ class ParticipantState with _$ParticipantState implements DataObject { } bool equalDuringFight(o) => o is ParticipantState && o.runtimeType == runtimeType && participation == o.participation; + + @override + ParticipantState copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/participation.dart b/wrestling_scoreboard_common/lib/src/data/participation.dart index cd438cd4..0a36e7cd 100644 --- a/wrestling_scoreboard_common/lib/src/data/participation.dart +++ b/wrestling_scoreboard_common/lib/src/data/participation.dart @@ -56,4 +56,9 @@ class Participation with _$Participation implements DataObject { @override String get tableName => 'participation'; + + @override + Participation copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/person.dart b/wrestling_scoreboard_common/lib/src/data/person.dart index e907ea31..42405c56 100644 --- a/wrestling_scoreboard_common/lib/src/data/person.dart +++ b/wrestling_scoreboard_common/lib/src/data/person.dart @@ -63,4 +63,9 @@ class Person with _$Person implements DataObject { @override String get tableName => 'person'; + + @override + Person copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/team.dart b/wrestling_scoreboard_common/lib/src/data/team.dart index 43761313..33cbbcb5 100644 --- a/wrestling_scoreboard_common/lib/src/data/team.dart +++ b/wrestling_scoreboard_common/lib/src/data/team.dart @@ -42,4 +42,9 @@ class Team with _$Team implements DataObject { @override String get tableName => 'team'; + + @override + Team copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/team_match/league.dart b/wrestling_scoreboard_common/lib/src/data/team_match/league.dart index 6a031142..99f28220 100644 --- a/wrestling_scoreboard_common/lib/src/data/team_match/league.dart +++ b/wrestling_scoreboard_common/lib/src/data/team_match/league.dart @@ -45,4 +45,9 @@ class League with _$League implements DataObject { @override String get tableName => 'league'; + + @override + League copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/team_match/league_team_participation.dart b/wrestling_scoreboard_common/lib/src/data/team_match/league_team_participation.dart index 3bd8b84f..ac699a0f 100644 --- a/wrestling_scoreboard_common/lib/src/data/team_match/league_team_participation.dart +++ b/wrestling_scoreboard_common/lib/src/data/team_match/league_team_participation.dart @@ -38,4 +38,9 @@ class LeagueTeamParticipation with _$LeagueTeamParticipation implements DataObje @override String get tableName => 'league_team_participation'; + + @override + LeagueTeamParticipation copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/team_match/league_weight_class.dart b/wrestling_scoreboard_common/lib/src/data/team_match/league_weight_class.dart index 0b43b751..814edb0f 100644 --- a/wrestling_scoreboard_common/lib/src/data/team_match/league_weight_class.dart +++ b/wrestling_scoreboard_common/lib/src/data/team_match/league_weight_class.dart @@ -40,4 +40,9 @@ class LeagueWeightClass with _$LeagueWeightClass implements DataObject { @override String get tableName => 'league_weight_class'; + + @override + LeagueWeightClass copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart b/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart index 314a3055..c95a656e 100644 --- a/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart +++ b/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart @@ -132,4 +132,9 @@ class TeamMatch extends WrestlingEvent with _$TeamMatch { @override String get tableName => 'team_match'; + + @override + TeamMatch copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/team_match/team_match_fight.dart b/wrestling_scoreboard_common/lib/src/data/team_match/team_match_fight.dart index dbf25f6b..8d704227 100644 --- a/wrestling_scoreboard_common/lib/src/data/team_match/team_match_fight.dart +++ b/wrestling_scoreboard_common/lib/src/data/team_match/team_match_fight.dart @@ -43,4 +43,9 @@ class TeamMatchFight with _$TeamMatchFight implements DataObject { @override String get tableName => 'team_match_fight'; + + @override + TeamMatchFight copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/tournament/tournament.dart b/wrestling_scoreboard_common/lib/src/data/tournament/tournament.dart index 12f48ccf..07d9c2e8 100644 --- a/wrestling_scoreboard_common/lib/src/data/tournament/tournament.dart +++ b/wrestling_scoreboard_common/lib/src/data/tournament/tournament.dart @@ -60,4 +60,9 @@ class Tournament extends WrestlingEvent with _$Tournament { @override String get tableName => 'tournament'; + + @override + Tournament copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/tournament/tournament_fight.dart b/wrestling_scoreboard_common/lib/src/data/tournament/tournament_fight.dart index 9a0d02d9..715803c8 100644 --- a/wrestling_scoreboard_common/lib/src/data/tournament/tournament_fight.dart +++ b/wrestling_scoreboard_common/lib/src/data/tournament/tournament_fight.dart @@ -41,4 +41,9 @@ class TournamentFight with _$TournamentFight implements DataObject { @override String get tableName => 'tournament_fight'; + + @override + TournamentFight copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/tournament/tournament_person.dart b/wrestling_scoreboard_common/lib/src/data/tournament/tournament_person.dart index 17b6b740..34b66d95 100644 --- a/wrestling_scoreboard_common/lib/src/data/tournament/tournament_person.dart +++ b/wrestling_scoreboard_common/lib/src/data/tournament/tournament_person.dart @@ -42,4 +42,9 @@ class TournamentPerson with _$TournamentPerson implements DataObject { @override String get tableName => 'tournament_person'; + + @override + TournamentPerson copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/tournament/tournament_team_participation.dart b/wrestling_scoreboard_common/lib/src/data/tournament/tournament_team_participation.dart index 440ba96a..4ac12bff 100644 --- a/wrestling_scoreboard_common/lib/src/data/tournament/tournament_team_participation.dart +++ b/wrestling_scoreboard_common/lib/src/data/tournament/tournament_team_participation.dart @@ -39,4 +39,9 @@ class TournamentTeamParticipation with _$TournamentTeamParticipation implements @override String get tableName => 'tournament_team_participation'; + + @override + TournamentTeamParticipation copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/data/weight_class.dart b/wrestling_scoreboard_common/lib/src/data/weight_class.dart index c78d3d7f..4876c28d 100644 --- a/wrestling_scoreboard_common/lib/src/data/weight_class.dart +++ b/wrestling_scoreboard_common/lib/src/data/weight_class.dart @@ -56,4 +56,9 @@ class WeightClass with _$WeightClass implements DataObject { @override int get hashCode => Object.hash(suffix, weight, style, unit); + + @override + WeightClass copyWithId(int? id) { + return copyWith(id: id); + } } diff --git a/wrestling_scoreboard_common/lib/src/util/data_wrapper.dart b/wrestling_scoreboard_common/lib/src/util/data_wrapper.dart index 3c7239f8..90fc2941 100644 --- a/wrestling_scoreboard_common/lib/src/util/data_wrapper.dart +++ b/wrestling_scoreboard_common/lib/src/util/data_wrapper.dart @@ -31,11 +31,12 @@ typedef HandleManyCallback = Future Function( typedef HandleManyRawCallback = Future Function( {required CRUD operation, required ManyDataObject> many}); -Future handlefromJson(Map json, - {required HandleSingleCallback handleSingle, - required HandleManyCallback handleMany, - required HandleSingleRawCallback handleSingleRaw, - required HandleManyRawCallback handleManyRaw}) { +Future handleFromJson(Map json, { + required HandleSingleCallback handleSingle, + required HandleManyCallback handleMany, + required HandleSingleRawCallback handleSingleRaw, + required HandleManyRawCallback handleManyRaw, +}) { final type = getTypeFromTableName(json['tableName'] as String); switch (type) { case BoutConfig: @@ -145,11 +146,12 @@ Future handlefromJson(Map json, } } -Future _handleFromJsonGeneric(Map json, - {required HandleSingleCallback handleSingle, - required HandleManyCallback handleMany, - required HandleSingleRawCallback handleSingleRaw, - required HandleManyRawCallback handleManyRaw}) async { +Future _handleFromJsonGeneric(Map json, { + required HandleSingleCallback handleSingle, + required HandleManyCallback handleMany, + required HandleSingleRawCallback handleSingleRaw, + required HandleManyRawCallback handleManyRaw, +}) async { final isMany = json['isMany'] as bool; final isRaw = json['isRaw'] as bool; final operation = CrudParser.valueOf(json['operation']); @@ -191,37 +193,37 @@ class ManyDataObject { // TODO: deprecate in favor of Type.tableName String getTableNameFromType(Type t) { switch (t) { - case BoutConfig: + case const (BoutConfig): return 'bout_config'; - case Club: + case const (Club): return 'club'; - case Fight: + case const (Fight): return 'fight'; - case FightAction: + case const (FightAction): return 'fight_action'; - case League: + case const (League): return 'league'; - case LeagueWeightClass: + case const (LeagueWeightClass): return 'league_weight_class'; - case Lineup: + case const (Lineup): return 'lineup'; - case Membership: + case const (Membership): return 'membership'; - case Participation: + case const (Participation): return 'participation'; - case ParticipantState: + case const (ParticipantState): return 'participant_state'; - case Person: + case const (Person): return 'person'; - case Team: + case const (Team): return 'team'; - case TeamMatch: + case const (TeamMatch): return 'team_match'; - case TeamMatchFight: + case const (TeamMatchFight): return 'team_match_fight'; - case Tournament: + case const (Tournament): return 'tournament'; - case WeightClass: + case const (WeightClass): return 'weight_class'; default: throw UnimplementedError('ClassName for "${t.toString()}" not found.');