Skip to content

Commit

Permalink
feat(common): Use getter with freezed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Nov 27, 2023
1 parent d412da9 commit cde5241
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 26 deletions.
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/bout_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/club.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ class Club with _$Club implements DataObject {

@override
String get tableName => 'club';

@override
Club copyWithId(int? id) {
return copyWith(id: id);
}
}
2 changes: 2 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/data_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ abstract class DataObject {

Map<String, dynamic> toRaw();

DataObject copyWithId(int? id);

String get tableName;

static T fromJson<T extends DataObject>(Map<String, dynamic> json) {
Expand Down
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/fight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,9 @@ class Fight with _$Fight implements DataObject {
return 0;
}
}

@override
Fight copyWithId(int? id) {
return copyWith(id: id);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/fight_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/lineup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ class Lineup with _$Lineup implements DataObject {

@override
String get tableName => 'lineup';

@override
Lineup copyWithId(int? id) {
return copyWith(id: id);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/membership.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ class Membership with _$Membership implements DataObject {

@override
String get tableName => 'membership';

@override
Membership copyWithId(int? id) {
return copyWith(id: id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/participation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ class Participation with _$Participation implements DataObject {

@override
String get tableName => 'participation';

@override
Participation copyWithId(int? id) {
return copyWith(id: id);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ class Person with _$Person implements DataObject {

@override
String get tableName => 'person';

@override
Person copyWithId(int? id) {
return copyWith(id: id);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/team.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ class Team with _$Team implements DataObject {

@override
String get tableName => 'team';

@override
Team copyWithId(int? id) {
return copyWith(id: id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ class League with _$League implements DataObject {

@override
String get tableName => 'league';

@override
League copyWithId(int? id) {
return copyWith(id: id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ class Tournament extends WrestlingEvent with _$Tournament {

@override
String get tableName => 'tournament';

@override
Tournament copyWithId(int? id) {
return copyWith(id: id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions wrestling_scoreboard_common/lib/src/data/weight_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
54 changes: 28 additions & 26 deletions wrestling_scoreboard_common/lib/src/util/data_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ typedef HandleManyCallback = Future<void> Function<T extends DataObject>(
typedef HandleManyRawCallback = Future<void> Function<T extends DataObject>(
{required CRUD operation, required ManyDataObject<Map<String, dynamic>> many});

Future<int?> handlefromJson(Map<String, Object?> json,
{required HandleSingleCallback handleSingle,
required HandleManyCallback handleMany,
required HandleSingleRawCallback handleSingleRaw,
required HandleManyRawCallback handleManyRaw}) {
Future<int?> handleFromJson(Map<String, Object?> json, {
required HandleSingleCallback handleSingle,
required HandleManyCallback handleMany,
required HandleSingleRawCallback handleSingleRaw,
required HandleManyRawCallback handleManyRaw,
}) {
final type = getTypeFromTableName(json['tableName'] as String);
switch (type) {
case BoutConfig:
Expand Down Expand Up @@ -145,11 +146,12 @@ Future<int?> handlefromJson(Map<String, Object?> json,
}
}

Future<int?> _handleFromJsonGeneric<T extends DataObject>(Map<String, dynamic> json,
{required HandleSingleCallback handleSingle,
required HandleManyCallback handleMany,
required HandleSingleRawCallback handleSingleRaw,
required HandleManyRawCallback handleManyRaw}) async {
Future<int?> _handleFromJsonGeneric<T extends DataObject>(Map<String, dynamic> 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']);
Expand Down Expand Up @@ -191,37 +193,37 @@ class ManyDataObject<T> {
// 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.');
Expand Down

0 comments on commit cde5241

Please sign in to comment.