Change /share to create geoposition, /geo?id to update by id
This commit is contained in:
@@ -231,6 +231,7 @@ class DatabaseProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Geoposition> updatePosition(
|
Future<Geoposition> updatePosition(
|
||||||
|
int id,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
) async {
|
) async {
|
||||||
@@ -238,11 +239,13 @@ class DatabaseProvider {
|
|||||||
|
|
||||||
final results = await _dbConnection.execute(
|
final results = await _dbConnection.execute(
|
||||||
Sql.named('''
|
Sql.named('''
|
||||||
INSERT INTO geopositions (x_value, y_value, last_update, expires_at)
|
UPDATE geopositions
|
||||||
VALUES (@xValue, @yValue, NOW(), @expiresAt)
|
SET x_value = @xValue, y_value = @yValue, last_update = NOW(), expires_at = @expiresAt
|
||||||
|
WHERE id = @id
|
||||||
RETURNING id, x_value, y_value, last_update, expires_at
|
RETURNING id, x_value, y_value, last_update, expires_at
|
||||||
'''),
|
'''),
|
||||||
parameters: {
|
parameters: {
|
||||||
|
'id': id,
|
||||||
'xValue': x,
|
'xValue': x,
|
||||||
'yValue': y,
|
'yValue': y,
|
||||||
'expiresAt': expiresAt.toIso8601String(),
|
'expiresAt': expiresAt.toIso8601String(),
|
||||||
|
|||||||
@@ -29,19 +29,30 @@ class GeoRoutes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> _updatePosition(Request request) async {
|
Future<Response> _updatePosition(Request request) async {
|
||||||
|
final id = int.parse(request.url.queryParameters['id']!);
|
||||||
final body = await request.readAsString();
|
final body = await request.readAsString();
|
||||||
final data = jsonDecode(body);
|
final data = jsonDecode(body);
|
||||||
|
|
||||||
final x = data['x'];
|
final x = data['x'];
|
||||||
final y = data['y'];
|
final y = data['y'];
|
||||||
|
|
||||||
final position = await database.updatePosition(x, y);
|
final position = await database.updatePosition(id, x, y);
|
||||||
return Response(200, body: position.toJson());
|
return Response(200, body: position.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> _createShare(Request request) async {
|
Future<Response> _createShare(Request request) async {
|
||||||
|
final body = await request.readAsString();
|
||||||
|
final data = jsonDecode(body);
|
||||||
|
|
||||||
|
final x = data['x'];
|
||||||
|
final y = data['y'];
|
||||||
|
|
||||||
|
final position = await database.createPosition(x, y);
|
||||||
final shareId = database.createShareId();
|
final shareId = database.createShareId();
|
||||||
|
|
||||||
return Response(200, body: jsonEncode({'share_id': shareId}));
|
return Response(201, body: jsonEncode({
|
||||||
|
'geo_id': position.id,
|
||||||
|
'share_id': shareId
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user