mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-03 02:24:30 +01:00
Use UUIDv7, as in the backend
This commit is contained in:
@@ -49,6 +49,7 @@ class MeasurementEntryTable extends Table {
|
||||
TextColumn get categoryId =>
|
||||
text().named('category_id').references(MeasurementCategoryTable, #id)();
|
||||
|
||||
// DateTimeColumn get date => dateTime().map(const DatetimeToYYYYMMDDConverter())();
|
||||
DateTimeColumn get date => dateTime()();
|
||||
RealColumn get value => real()();
|
||||
TextColumn get notes => text()();
|
||||
|
||||
@@ -30,7 +30,7 @@ class WorkoutLogTable extends Table {
|
||||
@override
|
||||
String get tableName => 'manager_workoutlog';
|
||||
|
||||
TextColumn get id => text().clientDefault(() => ps.uuid.v4())();
|
||||
TextColumn get id => text().clientDefault(() => ps.uuid.v7())();
|
||||
IntColumn get exerciseId => integer().named('exercise_id')();
|
||||
IntColumn get routineId => integer().named('routine_id')();
|
||||
IntColumn get sessionId => integer().named('session_id').nullable()();
|
||||
@@ -84,7 +84,7 @@ class WorkoutSessionTable extends Table {
|
||||
@override
|
||||
String get tableName => 'manager_workoutsession';
|
||||
|
||||
TextColumn get id => text().clientDefault(() => ps.uuid.v4())();
|
||||
TextColumn get id => text().clientDefault(() => ps.uuid.v7())();
|
||||
IntColumn get routineId => integer().named('routine_id').nullable()();
|
||||
IntColumn get dayId => integer().named('day_id').nullable()();
|
||||
DateTimeColumn get date => dateTime()();
|
||||
@@ -98,7 +98,7 @@ class WorkoutSessionTable extends Table {
|
||||
const PowersyncWorkoutSessionTable = ps.Table(
|
||||
'manager_workoutsession',
|
||||
[
|
||||
ps.Column.text('uuid'),
|
||||
ps.Column.text('id'),
|
||||
ps.Column.integer('routine_id'),
|
||||
ps.Column.integer('day_id'),
|
||||
ps.Column.text('date'),
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import 'package:drift/drift.dart' as drift;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:powersync/powersync.dart' show uuid;
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/helpers/i18n.dart';
|
||||
@@ -35,7 +36,7 @@ enum LogTargetStatus {
|
||||
}
|
||||
|
||||
class Log {
|
||||
String? id;
|
||||
String id;
|
||||
|
||||
late int exerciseId;
|
||||
late Exercise exerciseObj;
|
||||
@@ -60,7 +61,7 @@ class Log {
|
||||
late DateTime date;
|
||||
|
||||
Log({
|
||||
this.id,
|
||||
String? id,
|
||||
required this.exerciseId,
|
||||
this.iteration,
|
||||
this.slotEntryId,
|
||||
@@ -76,9 +77,11 @@ class Log {
|
||||
this.weightUnitId = WEIGHT_UNIT_KG,
|
||||
this.weightUnitObj,
|
||||
DateTime? date,
|
||||
}) : date = date ?? DateTime.now();
|
||||
}) : id = id ?? uuid.v7(),
|
||||
date = date ?? DateTime.now();
|
||||
|
||||
Log.fromSetConfigData(SetConfigData setConfig, {int? routineId, this.iteration}) {
|
||||
Log.fromSetConfigData(SetConfigData setConfig, {int? routineId, this.iteration})
|
||||
: id = uuid.v7() {
|
||||
date = DateTime.now();
|
||||
sessionId = null;
|
||||
|
||||
@@ -157,9 +160,9 @@ class Log {
|
||||
return out;
|
||||
}
|
||||
|
||||
WorkoutLogTableCompanion toCompanion({bool includeId = false}) {
|
||||
WorkoutLogTableCompanion toCompanion() {
|
||||
return WorkoutLogTableCompanion(
|
||||
id: includeId && id != null ? drift.Value(id!) : const drift.Value.absent(),
|
||||
id: drift.Value(id),
|
||||
exerciseId: drift.Value(exerciseId),
|
||||
routineId: drift.Value(routineId),
|
||||
sessionId: sessionId != null ? drift.Value(sessionId) : const drift.Value.absent(),
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart' as drift;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:powersync/powersync.dart' show uuid;
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
@@ -31,10 +32,10 @@ const IMPRESSION_MAP = {1: 'bad', 2: 'neutral', 3: 'good'};
|
||||
class WorkoutSession {
|
||||
final _logger = Logger('WorkoutSession');
|
||||
|
||||
String? id;
|
||||
String id;
|
||||
late int? routineId;
|
||||
int? dayId;
|
||||
late DateTime date;
|
||||
DateTime date;
|
||||
late int impression;
|
||||
late String? notes;
|
||||
late TimeOfDay? timeStart;
|
||||
@@ -43,7 +44,7 @@ class WorkoutSession {
|
||||
List<Log> logs = [];
|
||||
|
||||
WorkoutSession({
|
||||
this.id,
|
||||
String? id,
|
||||
this.dayId,
|
||||
required this.routineId,
|
||||
this.impression = DEFAULT_IMPRESSION,
|
||||
@@ -52,13 +53,12 @@ class WorkoutSession {
|
||||
this.timeEnd,
|
||||
this.logs = const [],
|
||||
DateTime? date,
|
||||
}) {
|
||||
this.date = date ?? clock.now();
|
||||
}
|
||||
}) : id = id ?? uuid.v7(),
|
||||
date = date ?? clock.now();
|
||||
|
||||
WorkoutSessionTableCompanion toCompanion({bool includeId = false}) {
|
||||
return WorkoutSessionTableCompanion(
|
||||
id: includeId && id != null ? drift.Value(id!) : const drift.Value.absent(),
|
||||
id: drift.Value(id),
|
||||
routineId: routineId != null ? drift.Value(routineId) : const drift.Value.absent(),
|
||||
dayId: dayId != null ? drift.Value(dayId) : const drift.Value.absent(),
|
||||
date: drift.Value(date.toUtc()),
|
||||
|
||||
@@ -40,11 +40,11 @@ class MeasurementEntriesScreen extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final categoryUuid = ModalRoute.of(context)!.settings.arguments as String;
|
||||
final categoryId = ModalRoute.of(context)!.settings.arguments as String;
|
||||
final notifier = ref.read(measurementProvider.notifier);
|
||||
|
||||
return StreamBuilder<MeasurementCategory?>(
|
||||
stream: notifier.watchCategoryById(categoryUuid),
|
||||
stream: notifier.watchCategoryById(categoryId),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const BoxedProgressIndicator();
|
||||
@@ -104,7 +104,7 @@ class MeasurementEntriesScreen extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
// Confirmed, delete the workout
|
||||
// Confirmed, delete the category
|
||||
notifier.deleteCategory(category.id);
|
||||
|
||||
// Close the popup
|
||||
@@ -154,7 +154,7 @@ class MeasurementEntriesScreen extends ConsumerWidget {
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).newEntry,
|
||||
MeasurementEntryForm(categoryUuid),
|
||||
MeasurementEntryForm(categoryId),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -125,14 +125,14 @@ class MeasurementCategoryForm extends ConsumerWidget {
|
||||
|
||||
class MeasurementEntryForm extends ConsumerWidget {
|
||||
final _form = GlobalKey<FormState>();
|
||||
final String _categoryUuid;
|
||||
final String _categoryId;
|
||||
final _valueController = TextEditingController();
|
||||
final _dateController = TextEditingController(text: '');
|
||||
final _notesController = TextEditingController();
|
||||
|
||||
late final Map<String, dynamic> _entryData;
|
||||
|
||||
MeasurementEntryForm(this._categoryUuid, [MeasurementEntry? entry]) {
|
||||
MeasurementEntryForm(this._categoryId, [MeasurementEntry? entry]) {
|
||||
_entryData = {
|
||||
'id': null,
|
||||
'date': DateTime.now(),
|
||||
@@ -156,7 +156,7 @@ class MeasurementEntryForm extends ConsumerWidget {
|
||||
final dateFormat = DateFormat.yMd(Localizations.localeOf(context).languageCode);
|
||||
|
||||
final notifier = ref.read(measurementProvider.notifier);
|
||||
final Future<MeasurementCategory?> categoryFuture = notifier.getCategoryById(_categoryUuid);
|
||||
final Future<MeasurementCategory?> categoryFuture = notifier.getCategoryById(_categoryId);
|
||||
|
||||
if (_dateController.text.isEmpty) {
|
||||
_dateController.text = dateFormat.format(_entryData['date']);
|
||||
|
||||
Reference in New Issue
Block a user