Fix: link share_id to geo_id so /watch returns correct position
This commit is contained in:
@@ -12,7 +12,7 @@ import '../models/log.dart';
|
||||
class DatabaseProvider {
|
||||
late Connection _dbConnection;
|
||||
|
||||
final Map<String, bool> _shareLinks = {};
|
||||
final Map<String, String> _shareLinks = {};
|
||||
final _uuid = const Uuid();
|
||||
|
||||
Future<void> initialize() async {
|
||||
@@ -284,6 +284,28 @@ Future<Geoposition?> getLatestPosition() async {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Geoposition?> getPositionById(String id) async {
|
||||
final results = await _dbConnection.execute(
|
||||
Sql.named('''
|
||||
SELECT id, x_value, y_value, last_update, expires_at
|
||||
FROM geopositions
|
||||
WHERE id = @id AND expires_at > NOW()
|
||||
'''),
|
||||
parameters: {'id': id},
|
||||
);
|
||||
|
||||
if (results.isEmpty) return null;
|
||||
|
||||
final row = results.first;
|
||||
return Geoposition(
|
||||
id: row[0].toString(),
|
||||
xValue: double.parse(row[1].toString()),
|
||||
yValue: double.parse(row[2].toString()),
|
||||
lastUpdate: DateTime.parse(row[3].toString()),
|
||||
expiresAt: DateTime.parse(row[4].toString()),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> cleanupExpired() async {
|
||||
await _dbConnection.execute(
|
||||
Sql.named('DELETE FROM geopositions WHERE expires_at < NOW()'),
|
||||
@@ -292,14 +314,14 @@ Future<Geoposition?> getLatestPosition() async {
|
||||
|
||||
// ==================== Share operations ====================
|
||||
|
||||
String createShareId() {
|
||||
String createShareId(String geoId) {
|
||||
final uniqueId = _uuid.v4();
|
||||
_shareLinks[uniqueId] = true;
|
||||
_shareLinks[uniqueId] = geoId;
|
||||
return uniqueId;
|
||||
}
|
||||
|
||||
bool isValidShareId(String uniqueId) {
|
||||
return _shareLinks[uniqueId] == true;
|
||||
String? getGeoIdByShareId(String uniqueId) {
|
||||
return _shareLinks[uniqueId];
|
||||
}
|
||||
|
||||
// ==================== Log operations ====================
|
||||
|
||||
Reference in New Issue
Block a user