feat: add Docker support, refactor DB layer, update API responses
This commit is contained in:
@@ -44,10 +44,7 @@ class AuthRoutes {
|
||||
final token = jwt.sign(SecretKey(secret));
|
||||
|
||||
await database.createLog(login, 'Successful login');
|
||||
return Response(200, body: jsonEncode({
|
||||
'user': user.toMap(),
|
||||
'token': token
|
||||
}));
|
||||
return Response(200, body: jsonEncode(token));
|
||||
}
|
||||
|
||||
Future<Response> _register(Request request) async {
|
||||
@@ -57,9 +54,9 @@ class AuthRoutes {
|
||||
final login = data['login'];
|
||||
final password = data['password'];
|
||||
|
||||
final user = await database.createUser(login, password);
|
||||
await database.createUser(login, password);
|
||||
await database.createLog(login, 'User registration');
|
||||
return Response(201, body: jsonEncode(user.toMap()));
|
||||
return Response(201);
|
||||
}
|
||||
|
||||
Future<Response> _watch(Request request, String login) async {
|
||||
@@ -78,6 +75,11 @@ class AuthRoutes {
|
||||
}
|
||||
|
||||
await database.createLog(login, 'Accessed share link');
|
||||
return Response(200, body: jsonEncode(position.toJson()));
|
||||
return Response(200, body: jsonEncode({
|
||||
'x': position.xValue,
|
||||
'y': position.yValue,
|
||||
'last_update': position.lastUpdate,
|
||||
'expires_at': position.expiresAt,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class GeoRoutes {
|
||||
return router;
|
||||
}
|
||||
|
||||
Future<Response> _updatePosition(Request request) async {
|
||||
Future<Response> _updatePosition(Request request, String login) async {
|
||||
final id = int.parse(request.url.queryParameters['id']!);
|
||||
final body = await request.readAsString();
|
||||
final data = jsonDecode(body);
|
||||
@@ -24,11 +24,12 @@ class GeoRoutes {
|
||||
final x = data['x'];
|
||||
final y = data['y'];
|
||||
|
||||
final position = await database.updatePosition(id, x, y);
|
||||
return Response(200, body: position.toJson());
|
||||
await database.updatePosition(id, x, y);
|
||||
await database.createLog(login, 'Updated position id=$id');
|
||||
return Response(200);
|
||||
}
|
||||
|
||||
Future<Response> _createShare(Request request) async {
|
||||
Future<Response> _createShare(Request request, String login) async {
|
||||
final body = await request.readAsString();
|
||||
final data = jsonDecode(body);
|
||||
|
||||
@@ -38,6 +39,7 @@ class GeoRoutes {
|
||||
final position = await database.createPosition(x, y);
|
||||
final shareId = database.createShareId();
|
||||
|
||||
await database.createLog(login, 'Created share link geo_id=${position.id}');
|
||||
return Response(201, body: jsonEncode({
|
||||
'geo_id': position.id,
|
||||
'share_id': shareId
|
||||
|
||||
Reference in New Issue
Block a user