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(
|
||||
int id,
|
||||
double x,
|
||||
double y,
|
||||
) async {
|
||||
@@ -238,11 +239,13 @@ class DatabaseProvider {
|
||||
|
||||
final results = await _dbConnection.execute(
|
||||
Sql.named('''
|
||||
INSERT INTO geopositions (x_value, y_value, last_update, expires_at)
|
||||
VALUES (@xValue, @yValue, NOW(), @expiresAt)
|
||||
UPDATE geopositions
|
||||
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
|
||||
'''),
|
||||
parameters: {
|
||||
'id': id,
|
||||
'xValue': x,
|
||||
'yValue': y,
|
||||
'expiresAt': expiresAt.toIso8601String(),
|
||||
|
||||
@@ -29,19 +29,30 @@ class GeoRoutes {
|
||||
}
|
||||
|
||||
Future<Response> _updatePosition(Request request) async {
|
||||
final id = int.parse(request.url.queryParameters['id']!);
|
||||
final body = await request.readAsString();
|
||||
final data = jsonDecode(body);
|
||||
|
||||
final x = data['x'];
|
||||
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());
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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