Skip to content

Commit

Permalink
refactor: Convert enum names
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Mar 22, 2024
1 parent ab30f8a commit a4eaa31
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 49 deletions.
4 changes: 2 additions & 2 deletions wrestling_scoreboard_common/lib/src/data/bout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Bout with _$Bout implements DataObject {
r: redId == null ? null : await getSingle<ParticipantState>(redId),
b: blueId == null ? null : await getSingle<ParticipantState>(blueId),
weightClass: weightClassId == null ? null : await getSingle<WeightClass>(weightClassId),
winnerRole: winner == null ? null : BoutRoleParser.valueOf(winner),
result: boutResult == null ? null : BoutResultParser.valueOf(boutResult),
winnerRole: winner == null ? null : BoutRole.values.byName(winner),
result: boutResult == null ? null : BoutResult.values.byName(boutResult),
duration: durationMillis == null ? Duration() : Duration(milliseconds: durationMillis),
);
}
Expand Down
4 changes: 2 additions & 2 deletions wrestling_scoreboard_common/lib/src/data/bout_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class BoutAction with _$BoutAction implements DataObject {

static Future<BoutAction> fromRaw(Map<String, dynamic> e, GetSingleOfTypeCallback getSingle) async => BoutAction(
id: e['id'] as int?,
actionType: BoutActionTypeParser.valueOf(e['action_type']),
actionType: BoutActionType.values.byName(e['action_type']),
duration: Duration(milliseconds: e['duration_millis']),
role: BoutRoleParser.valueOf(e['bout_role']),
role: BoutRole.values.byName(e['bout_role']),
pointCount: e['point_count'] as int?,
bout: (await getSingle<Bout>(e['bout_id'] as int)),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CompetitionPerson with _$CompetitionPerson implements DataObject {
id: e['id'] as int?,
competition: (await getSingle<Competition>(e['competition_id'] as int)),
person: (await getSingle<Person>(e['person_id'] as int)),
role: PersonRoleParser.valueOf(e['person_role']),
role: PersonRole.values.byName(e['person_role']),
);

@override
Expand Down
2 changes: 1 addition & 1 deletion wrestling_scoreboard_common/lib/src/data/person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Person with _$Person implements DataObject {
id: e['id'] as int?,
prename: e['prename'] as String,
surname: e['surname'] as String,
gender: gender == null ? null : GenderParser.valueOf(gender),
gender: gender == null ? null : Gender.values.byName(gender),
birthDate: e['birth_date'] as DateTime?,
nationality: nationality == null ? null : CountryJsonConverter().fromJson(nationality),
);
Expand Down
4 changes: 2 additions & 2 deletions wrestling_scoreboard_common/lib/src/data/weight_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class WeightClass with _$WeightClass implements DataObject {
id: e['id'] as int?,
suffix: e['suffix'] as String?,
weight: e['weight'] as int,
unit: WeightUnitParser.valueOf(e['unit']),
style: WrestlingStyleParser.valueOf(e['style']),
unit: WeightUnit.values.byName(e['unit']),
style: WrestlingStyle.values.byName(e['style']),
);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ enum BoutActionType {
passivity, // P
verbal, // V admonition
caution, // yellow card
dismissal // red card
}
dismissal; // red card

extension BoutActionTypeParser on BoutActionType {
String get name => toString().split('.').last;

static BoutActionType valueOf(String name) => BoutActionType.values.singleWhere((element) => element.name == name);
}
6 changes: 1 addition & 5 deletions wrestling_scoreboard_common/lib/src/enums/bout_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ enum BoutResult {

/// In case both wrestlers have been disqualified due to infringement of the rules
/// Beide Ringer disqualifiziert wegen Unsportlichkeit / Regelwidrigkeit (DQ2)
dsq2,
}
dsq2;

extension BoutResultParser on BoutResult {
String get name => toString().split('.').last;

static BoutResult valueOf(String name) => BoutResult.values.singleWhere((element) => element.name == name);
}
6 changes: 1 addition & 5 deletions wrestling_scoreboard_common/lib/src/enums/bout_role.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/// The role of the participant (red = home, blue = guest).
enum BoutRole {
red,
blue,
}
blue;

extension BoutRoleParser on BoutRole {
String get name => toString().split('.').last;

static BoutRole valueOf(String name) => BoutRole.values.singleWhere((element) => element.name == name);
}
6 changes: 1 addition & 5 deletions wrestling_scoreboard_common/lib/src/enums/crud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ enum CRUD {
create,
read,
update,
delete,
}
delete;

extension CrudParser on CRUD {
String get name => toString().split('.').last;

static CRUD valueOf(String name) => CRUD.values.singleWhere((element) => element.name == name);
}
6 changes: 1 addition & 5 deletions wrestling_scoreboard_common/lib/src/enums/gender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
enum Gender {
male,
female,
other,
}
other;

extension GenderParser on Gender {
String get name => toString().split('.').last;

static Gender valueOf(String name) => Gender.values.singleWhere((element) => element.name == name);
}
6 changes: 1 addition & 5 deletions wrestling_scoreboard_common/lib/src/enums/person_role.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ enum PersonRole {
judge,
transcriptWriter,
timeKeeper,
steward,
}
steward;

extension PersonRoleParser on PersonRole {
String get name => toString().split('.').last;

static PersonRole valueOf(String name) => PersonRole.values.singleWhere((element) => element.name == name);
}
6 changes: 1 addition & 5 deletions wrestling_scoreboard_common/lib/src/enums/weight_unit.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/// The unit of weight.
enum WeightUnit {
kilogram,
pound,
}
pound;

extension WeightUnitParser on WeightUnit {
String get name => toString().split('.').last;

static WeightUnit valueOf(String name) => WeightUnit.values.singleWhere((element) => element.name == name);

String toAbbr() {
if (this == WeightUnit.pound) return 'lb';
return 'kg';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
enum WrestlingStyle {
free, // free style
greco, // greco-roman style
}
greco; // greco-roman style

extension WrestlingStyleParser on WrestlingStyle {
String get name => toString().split('.').last;

static WrestlingStyle valueOf(String name) => WrestlingStyle.values.singleWhere((element) => element.name == name);
}
3 changes: 2 additions & 1 deletion wrestling_scoreboard_common/lib/src/util/data_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ Future<int?> _handleFromJsonGeneric<T extends DataObject>(
}) async {
final isMany = json['isMany'] as bool;
final isRaw = json['isRaw'] as bool;
final operation = CrudParser.valueOf(json['operation']);
final operation = CRUD.values.byName(json['operation']);

if (isMany) {
final List<dynamic> data = json['data'];
final filterType = json['filterType'] == null ? null : getTypeFromTableName(json['filterType']);
Expand Down

0 comments on commit a4eaa31

Please sign in to comment.