-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from OpenRowingCommunity/immutablility
Migrate to using `freezed` package for immutability instead of `equatable`
- Loading branch information
Showing
7 changed files
with
122 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
|
||
# Files generated by dart tools | ||
.dart_tool/ | ||
.packages | ||
doc/ | ||
|
||
# Avoid committing pubspec.lock for library packages; see | ||
# https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
pubspec.lock | ||
|
||
# Common build output | ||
/*/build/ | ||
build/ | ||
|
||
# Include .packages files from tests which are hand coded | ||
!build_runner_core/test/fixtures/**/.packages | ||
!build_runner_core/test/fixtures/**/pubspec.lock | ||
|
||
# Extra files from dart2js that we don't want | ||
build_runner/lib/src/server/graph_viz_main.dart.js.deps | ||
build_runner/lib/src/server/graph_viz_main.dart.js.tar.gz | ||
build_runner/lib/src/server/build_updates_client/hot_reload_client.dart.js.deps | ||
build_runner/lib/src/server/build_updates_client/hot_reload_client.dart.js.tar.gz | ||
|
||
|
||
*.g.dart | ||
|
||
*.freezed.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,39 @@ | ||
import 'c2_types.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class C2Results extends Equatable { | ||
int id; | ||
int userId; | ||
|
||
// DateTime date; | ||
String? timezone; | ||
DateTime? get dateUtc => null; | ||
|
||
int distance; | ||
C2ResultType type; | ||
|
||
int time; | ||
String get timeFormatted => ""; | ||
|
||
C2APIWorkoutType workoutType; | ||
// ignore_for_file: invalid_annotation_target | ||
|
||
String source; | ||
C2WeightClass weightClass; | ||
bool verified; | ||
bool ranked; | ||
String? comments; | ||
C2PrivacyLevel privacy; | ||
|
||
C2Results({ | ||
this.id = 0, | ||
this.userId = 0, | ||
// this.date = DateTime(1970,1,1), | ||
this.timezone, | ||
this.distance = 0, | ||
this.type = C2ResultType.rower, | ||
this.time = 0, | ||
this.workoutType = C2APIWorkoutType.JustRow, | ||
this.source = "c2logbook dart", | ||
this.weightClass = C2WeightClass.heavyweight, | ||
this.verified = false, | ||
this.ranked = false, | ||
this.comments, | ||
this.privacy = C2PrivacyLevel.private, | ||
}); | ||
|
||
@override | ||
List<Object> get props => [ | ||
id, | ||
userId, | ||
// date, | ||
// timezone, | ||
distance, | ||
type, | ||
time, | ||
workoutType, | ||
source, | ||
weightClass, | ||
verified, | ||
ranked, | ||
// comments, | ||
privacy | ||
]; | ||
|
||
factory C2Results.fromJson(Map<String, dynamic> json) { | ||
// { | ||
// "id": 3, | ||
// "user_id": 1, | ||
// "date": "2013-06-21 00:00:00", | ||
// "timezone": null, | ||
// "date_utc": null, | ||
// "distance": 23000, | ||
// "type": "rower", | ||
// "time": 152350, | ||
// "time_formatted": "4:13:55.0", | ||
// "workout_type": "unknown", | ||
// "source": "Web", | ||
// "weight_class": "H", | ||
// "verified": false, | ||
// "ranked": false, | ||
// "comments": null, | ||
// "privacy": "partners" | ||
// }, | ||
|
||
return C2Results( | ||
id: json['id'], | ||
userId: json['user_id'], | ||
// date: json['date'], | ||
timezone: json['timezone'], | ||
distance: json['distance'], | ||
type: C2ResultTypeExtension.fromString(json['type']), | ||
time: json['time'], | ||
workoutType: C2APIWorkoutTypeExtension.fromString(json['workout_type']), | ||
source: json['source'], | ||
weightClass: C2WeightClassExtension.fromString(json['weight_class']), | ||
verified: json['verified'], | ||
ranked: json['ranked'], | ||
comments: json['comments'], | ||
privacy: C2PrivacyExtension.fromString(json['privacy']) ?? | ||
C2PrivacyLevel.private); | ||
} | ||
import 'c2_types.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'c2_results.freezed.dart'; | ||
part 'c2_results.g.dart'; | ||
|
||
@freezed | ||
class C2Results with _$C2Results { | ||
//TODO: figure out how to get this into JSON as date_utc | ||
// DateTime? get dateUtc => null; | ||
//TODO: figure out how to get this into JSON as time_formatted | ||
// String get timeFormatted => ""; | ||
|
||
factory C2Results({ | ||
@Default(0) int id, | ||
@JsonKey(name: "user_id") @Default(0) int userId, | ||
// @JsonKey(name: "date") @Default(DateTime(1970, 1, 1)) DateTime date, | ||
String? timezone, | ||
@Default(0) int distance, | ||
@Default(C2ResultType.rower) C2ResultType type, | ||
@Default(0) int time, | ||
@JsonKey(name: "workout_type") | ||
@Default(C2APIWorkoutType.JustRow) | ||
C2APIWorkoutType workoutType, | ||
@Default("c2logbook dart") String source, | ||
@JsonKey(name: "weight_class") | ||
@Default(C2WeightClass.heavyweight) | ||
C2WeightClass weightClass, | ||
@Default(false) bool verified, | ||
@Default(false) bool ranked, | ||
String? comments, | ||
@Default(C2PrivacyLevel.private) C2PrivacyLevel privacy, | ||
}) = _C2Results; | ||
|
||
factory C2Results.fromJson(Map<dynamic, dynamic> json) => | ||
_$C2ResultsFromJson(Map<String, dynamic>.from(json)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,32 @@ | ||
import 'package:c2logbook/src/types/c2_types.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
// ignore_for_file: invalid_annotation_target | ||
|
||
class C2User extends Equatable { | ||
int id; | ||
String username; | ||
String firstName; | ||
String lastName; | ||
String gender; | ||
String birthday; | ||
String email; | ||
String country; | ||
String? profileImage; | ||
bool ageRestricted; | ||
bool emailPermission; | ||
int? maxHeartRate; | ||
int? weight; | ||
List<String> roles; | ||
C2PrivacyLevel logbookPrivacy; | ||
import 'package:c2logbook/src/types/c2_types.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
C2User( | ||
{this.id = 0, | ||
this.username = '', | ||
this.firstName = '', | ||
this.lastName = '', | ||
this.gender = 'F', | ||
this.birthday = '1970-01-01', | ||
this.email = '', | ||
this.country = '', | ||
this.profileImage, | ||
this.ageRestricted = false, | ||
this.emailPermission = false, | ||
this.maxHeartRate, | ||
this.weight, | ||
this.roles = const [], | ||
this.logbookPrivacy = C2PrivacyLevel.private}); | ||
part 'c2_user.freezed.dart'; | ||
part 'c2_user.g.dart'; | ||
|
||
@override | ||
List<Object> get props => [ | ||
id, | ||
username, | ||
firstName, | ||
lastName, | ||
gender, | ||
birthday, | ||
email, | ||
country, | ||
// profileImage, | ||
ageRestricted, | ||
emailPermission, | ||
// maxHeartRate, | ||
// weight, | ||
roles, | ||
logbookPrivacy | ||
]; | ||
@freezed | ||
class C2User with _$C2User { | ||
const factory C2User( | ||
{@Default(0) int id, | ||
@Default('') String username, | ||
@JsonKey(name: 'first_name') @Default('') String firstName, | ||
@JsonKey(name: 'last_name') @Default('') String lastName, | ||
@Default('F') String gender, | ||
@JsonKey(name: 'dob') @Default('1970-01-01') String birthday, | ||
@Default('') String email, | ||
@Default('') String country, | ||
@JsonKey(name: 'profile_image') String? profileImage, | ||
@JsonKey(name: 'age_restricted') @Default(false) bool ageRestricted, | ||
@JsonKey(name: 'email_permission') @Default(false) bool emailPermission, | ||
@JsonKey(name: 'max_heart_rate') int? maxHeartRate, | ||
int? weight, | ||
@Default(<String>[]) List<String> roles, | ||
@JsonKey(name: 'logbook_privacy') | ||
@Default(C2PrivacyLevel.private) | ||
C2PrivacyLevel logbookPrivacy}) = _C2User; | ||
|
||
factory C2User.fromJson(Map<String, dynamic> json) { | ||
return C2User( | ||
id: json['id'], | ||
username: json['username'], | ||
firstName: json['first_name'], | ||
lastName: json['last_name'], | ||
gender: json['gender'], | ||
birthday: json['dob'], | ||
email: json['email'], | ||
country: json['country'], | ||
profileImage: json['profile_image'], | ||
ageRestricted: json['age_restricted'], | ||
emailPermission: json['email_permission'], | ||
// maxHeartRate: json['max_heart_rate'], | ||
// weight: json['weight'], | ||
// roles: json['roles'], | ||
logbookPrivacy: | ||
C2PrivacyExtension.fromString(json['logbook_privacy']) ?? | ||
C2PrivacyLevel.private); | ||
} | ||
factory C2User.fromJson(Map<dynamic, dynamic> json) => | ||
_$C2UserFromJson(Map<String, dynamic>.from(json)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters