Commit 8c8b4f55 authored by Stefan Haslinger's avatar Stefan Haslinger

refactoring fromDb connstructors to exDb static methods for more compact maps

parent 5d7c6a26
......@@ -29,7 +29,7 @@ import 'heart_rate_zone_schema.dart';
class Activity {
Activity();
Activity.fromDb(this.db);
Activity._fromDb(this.db);
Activity.fromStrava({
strava_activity.SummaryActivity summaryActivity,
......@@ -543,7 +543,7 @@ class Activity {
.upperLimit
.greaterThanOrEquals(db.avgPower)
.toSingle();
_powerZone = PowerZone.fromDb(dbPowerZone);
_powerZone = PowerZone.exDb(dbPowerZone);
}
return _powerZone;
}
......@@ -562,7 +562,7 @@ class Activity {
.greaterThanOrEquals(db.avgHeartRate)
.toSingle();
_heartRateZone = HeartRateZone.fromDb(dbHeartRateZone);
_heartRateZone = HeartRateZone.exDb(dbHeartRateZone);
}
return _heartRateZone;
}
......@@ -624,4 +624,6 @@ class Activity {
.heartRateZoneCounts(heartRateZoneSchema: heartRateZoneSchema);
return heartRateZoneCounts;
}
static Activity exDb(DbActivity db) => Activity._fromDb(db);
}
......@@ -16,7 +16,7 @@ class ActivityTagging {
..system = system ?? false;
}
ActivityTagging.fromDb(this._db);
ActivityTagging._fromDb(this._db);
DbActivityTagging _db;
......@@ -38,7 +38,7 @@ class ActivityTagging {
.toSingle();
if (dbActivityTagging != null)
return ActivityTagging.fromDb(dbActivityTagging);
return ActivityTagging._fromDb(dbActivityTagging);
else {
final ActivityTagging activityTagging = ActivityTagging(
activity: activity, tag: tag, system: system ?? false);
......@@ -60,7 +60,7 @@ class ActivityTagging {
.equals(tag.id)
.toSingle();
if (dbActivityTagging != null)
return ActivityTagging.fromDb(dbActivityTagging);
return ActivityTagging._fromDb(dbActivityTagging);
return null;
}
......@@ -84,4 +84,6 @@ class ActivityTagging {
'< ActivityTagging | actvityId $activitiesId | tagId $tagsId >';
Future<BoolResult> delete() async => await _db.delete();
static ActivityTagging exDb(DbActivityTagging db) => ActivityTagging._fromDb(db);
}
......@@ -101,9 +101,7 @@ class Athlete {
Future<List<Activity>> get activities async {
final List<DbActivity> dbActivityList =
await _db.getDbActivities().orderByDesc('stravaId').toList();
return dbActivityList
.map((DbActivity dbActivity) => Activity.fromDb(dbActivity))
.toList();
return dbActivityList.map(Activity.exDb).toList();
}
Future<List<Weight>> get weights async {
......
......@@ -44,7 +44,7 @@ class Event {
}
}
Event.fromDb(this._db);
Event._fromDb(this._db);
Event.fromRecord({
@required DataMessage dataMessage,
......@@ -152,7 +152,7 @@ class Event {
final List<DbEvent> dbEventList = await activity.db.getDbEvents().toList();
final List<Event> eventList =
dbEventList.map((DbEvent dbEvent) => Event.fromDb(dbEvent)).toList();
dbEventList.map(Event.exDb).toList();
for (final Event event in eventList) {
event.activity = activity;
......@@ -168,4 +168,6 @@ class Event {
.map((Event event) => event._db)
.toList());
}
static Event exDb(DbEvent db) => Event._fromDb(db);
}
......@@ -26,7 +26,7 @@ class HeartRateZone {
if (upperPercentage != null)
upperLimit = (upperPercentage * heartRateZoneSchema.base / 100).round();
}
HeartRateZone.fromDb(this._db);
HeartRateZone._fromDb(this._db);
DbHeartRateZone _db;
......@@ -58,4 +58,6 @@ class HeartRateZone {
.map((HeartRateZone heartRateZone) => heartRateZone._db)
.toList());
}
static HeartRateZone exDb(DbHeartRateZone db) => HeartRateZone._fromDb(db);
}
......@@ -13,7 +13,7 @@ class HeartRateZoneSchema {
..name = 'My Schema'
..date = DateTime.now();
}
HeartRateZoneSchema.fromDb(this._db);
HeartRateZoneSchema._fromDb(this._db);
HeartRateZoneSchema.likeGarmin({Athlete athlete}) {
_db = DbHeartRateZoneSchema()
......@@ -45,10 +45,8 @@ class HeartRateZoneSchema {
Future<List<HeartRateZone>> get heartRateZones async {
final List<DbHeartRateZone> dbHeartRateZoneList =
await _db.getDbHeartRateZones().orderBy('lowerLimit').toList();
final List<HeartRateZone> heartRateZones = dbHeartRateZoneList
.map((DbHeartRateZone dbHeartRateZone) =>
HeartRateZone.fromDb(dbHeartRateZone))
.toList();
final List<HeartRateZone> heartRateZones =
dbHeartRateZoneList.map(HeartRateZone.exDb).toList();
return heartRateZones;
}
......@@ -150,10 +148,10 @@ class HeartRateZoneSchema {
.top(1)
.toList();
if (dbHeartRateZoneSchemas.isNotEmpty)
return HeartRateZoneSchema.fromDb(dbHeartRateZoneSchemas.first);
return HeartRateZoneSchema._fromDb(dbHeartRateZoneSchemas.first);
return null;
}
static HeartRateZoneSchema exDb(DbHeartRateZoneSchema db) =>
HeartRateZoneSchema.fromDb(db);
HeartRateZoneSchema._fromDb(db);
}
......@@ -22,7 +22,7 @@ class Lap {
_db = DbLap();
}
Lap.fromDb(this._db);
Lap._fromDb(this._db);
DbLap _db;
Activity activity;
......@@ -212,7 +212,7 @@ class Lap {
final List<DbLap> dbLapList = await activity.db.getDbLaps().toList();
final List<Lap> lapList =
dbLapList.map((DbLap dbLap) => Lap.fromDb(dbLap)).toList();
dbLapList.map(Lap.exDb).toList();
for (final Lap lap in lapList) {
lap
......@@ -277,7 +277,7 @@ class Lap {
.upperLimit
.greaterThanOrEquals(avgPower)
.toSingle();
_powerZone = PowerZone.fromDb(dbPowerZone);
_powerZone = PowerZone.exDb(dbPowerZone);
}
return _powerZone;
}
......@@ -296,7 +296,7 @@ class Lap {
.greaterThanOrEquals(avgHeartRate)
.toSingle();
_heartRateZone = HeartRateZone.fromDb(dbHeartRateZone);
_heartRateZone = HeartRateZone.exDb(dbHeartRateZone);
}
return _heartRateZone;
}
......@@ -357,6 +357,8 @@ class Lap {
Future<List<Event>> get events async {
final List<DbEvent> dbEvents = await _db.getDbEvents().toList();
return dbEvents.map((DbEvent dbEvent) => Event.fromDb(dbEvent)).toList();
return dbEvents.map(Event.exDb).toList();
}
static Lap exDb(DbLap db) => Lap._fromDb(db);
}
......@@ -16,7 +16,7 @@ class LapTagging {
..system = system ?? false;
}
LapTagging.fromDb(this._db);
LapTagging._fromDb(this._db);
DbLapTagging _db;
......@@ -45,7 +45,7 @@ class LapTagging {
.toSingle();
if (dbLapTagging != null)
return LapTagging.fromDb(dbLapTagging);
return LapTagging._fromDb(dbLapTagging);
else {
final LapTagging lapTagging = LapTagging(
lap: lap,
......@@ -69,7 +69,7 @@ class LapTagging {
.tagsId
.equals(tag.id)
.toSingle();
return (dbLapTagging != null) ? LapTagging.fromDb(dbLapTagging) : null;
return (dbLapTagging != null) ? LapTagging._fromDb(dbLapTagging) : null;
}
static Future<void> deleteBy({
......@@ -86,4 +86,6 @@ class LapTagging {
.toSingle();
await dbLapTagging.delete();
}
static LapTagging exDb(DbLapTagging db) => LapTagging._fromDb(db);
}
......@@ -27,7 +27,7 @@ class PowerZone {
upperLimit = (upperPercentage * powerZoneSchema.base / 100).round();
}
PowerZone.fromDb(this._db);
PowerZone._fromDb(this._db);
DbPowerZone _db;
......@@ -57,4 +57,6 @@ class PowerZone {
return await DbPowerZone().upsertAll(
powerZones.map((PowerZone powerZone) => powerZone._db).toList());
}
static PowerZone exDb(DbPowerZone db) => PowerZone._fromDb(db);
}
......@@ -12,7 +12,7 @@ class PowerZoneSchema {
..name = 'My Schema'
..date = DateTime.now();
}
PowerZoneSchema.fromDb(this._db);
PowerZoneSchema._fromDb(this._db);
PowerZoneSchema.likeStryd({Athlete athlete}) {
_db = DbPowerZoneSchema()
......@@ -57,7 +57,7 @@ class PowerZoneSchema {
final List<DbPowerZone> dbPowerZoneList =
await _db.getDbPowerZones().orderBy('lowerLimit').toList();
return dbPowerZoneList
.map((DbPowerZone dbPowerZone) => PowerZone.fromDb(dbPowerZone))
.map(PowerZone.exDb)
.toList();
}
......@@ -211,10 +211,10 @@ class PowerZoneSchema {
.top(1)
.toList();
if (dbPowerZoneSchemas.isNotEmpty)
return PowerZoneSchema.fromDb(dbPowerZoneSchemas.first);
return PowerZoneSchema._fromDb(dbPowerZoneSchemas.first);
return null;
}
static PowerZoneSchema exDb(DbPowerZoneSchema db) =>
PowerZoneSchema.fromDb(db);
PowerZoneSchema._fromDb(db);
}
......@@ -19,7 +19,7 @@ class Tag {
..name = name ?? 'my Tag'
..color = color ?? 0xFFFFc107;
}
Tag.fromDb(this._db);
Tag._fromDb(this._db);
DbTag _db;
bool selected = false;
......@@ -53,7 +53,7 @@ class Tag {
.toList())
.toList();
final List<Tag> tags =
dbTags.map((DbTag dbTag) => Tag.fromDb(dbTag)).toList();
dbTags.map(Tag.exDb).toList();
return tags;
} else {
return <Tag>[];
......@@ -92,7 +92,7 @@ class Tag {
..system = true;
await dbPowerTag.save();
}
return Tag.fromDb(dbPowerTag);
return Tag._fromDb(dbPowerTag);
}
static Future<Tag> autoHeartRateTag({
......@@ -123,6 +123,8 @@ class Tag {
..system = true;
await dbHeartRateTag.save();
}
return Tag.fromDb(dbHeartRateTag);
return Tag._fromDb(dbHeartRateTag);
}
static Tag exDb(DbTag db) => Tag._fromDb(db);
}
......@@ -17,7 +17,7 @@ class TagGroup {
..name = 'My Tag Group';
}
TagGroup.fromDb(this._db);
TagGroup._fromDb(this._db);
TagGroup.by(
{@required Athlete athlete,
......@@ -44,7 +44,7 @@ class TagGroup {
Future<List<Tag>> get tags async {
final List<DbTag> dbTags =
await _db.getDbTags().orderBy('sortOrder').orderBy('name').toList();
return dbTags.map((DbTag dbTag) => Tag.fromDb(dbTag)).toList();
return dbTags.map(Tag.exDb).toList();
}
@override
......@@ -66,7 +66,7 @@ class TagGroup {
.equals('Auto Power Zones')
.toSingle();
if (dbTagGroup != null)
return TagGroup.fromDb(dbTagGroup);
return TagGroup._fromDb(dbTagGroup);
else {
final TagGroup autoPowerTagGroup = TagGroup.by(
name: 'Auto Power Zones',
......@@ -93,7 +93,7 @@ class TagGroup {
.equals('Auto Heart Rate Zones')
.toSingle();
if (dbTagGroup != null)
return TagGroup.fromDb(dbTagGroup);
return TagGroup._fromDb(dbTagGroup);
else {
final TagGroup autoHeartRateTagGroup = TagGroup.by(
name: 'Auto Heart Rate Zones',
......@@ -160,5 +160,5 @@ class TagGroup {
await autoHeartRateTagGroup._db.getDbTags().delete();
}
static TagGroup exDb(DbTagGroup db) => TagGroup.fromDb(db);
static TagGroup exDb(DbTagGroup db) => TagGroup._fromDb(db);
}
......@@ -10,7 +10,7 @@ class Weight {
..value = 70
..date = DateTime.now();
}
Weight.fromDb(this._db);
Weight._fromDb(this._db);
DbWeight _db;
......@@ -37,8 +37,8 @@ class Weight {
.orderByDesc('date')
.top(1)
.toList();
return dbWeights.isNotEmpty ? Weight.fromDb(dbWeights.first) : null;
return dbWeights.isNotEmpty ? Weight._fromDb(dbWeights.first) : null;
}
static Weight exDb(DbWeight db) => Weight.fromDb(db);
static Weight exDb(DbWeight db) => Weight._fromDb(db);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment