feat: refactor server with shelf_static, return JSON responses, add API docs
This commit is contained in:
@@ -31,7 +31,7 @@ class AuthRoutes {
|
||||
|
||||
if (user == null || !BCrypt.checkpw(password, user.pwdHash)) {
|
||||
await database.createLog(login, 'Failed login attempt');
|
||||
return Response(401, body: 'Invalid credentials');
|
||||
return Response(401, body: jsonEncode({'error': 'Invalid credentials'}), headers: {'Content-Type': 'application/json'});
|
||||
}
|
||||
|
||||
// Генерация JWT токена
|
||||
@@ -44,7 +44,7 @@ class AuthRoutes {
|
||||
final token = jwt.sign(SecretKey(secret));
|
||||
|
||||
await database.createLog(login, 'Successful login');
|
||||
return Response(200, body: jsonEncode(token));
|
||||
return Response(200, body: jsonEncode({'token': token}), headers: {'Content-Type': 'application/json'});
|
||||
}
|
||||
|
||||
Future<Response> _register(Request request) async {
|
||||
@@ -56,7 +56,7 @@ class AuthRoutes {
|
||||
|
||||
await database.createUser(login, password);
|
||||
await database.createLog(login, 'User registration');
|
||||
return Response(201);
|
||||
return Response(201, body: jsonEncode({'message': 'User registered'}), headers: {'Content-Type': 'application/json'});
|
||||
}
|
||||
|
||||
Future<Response> _watch(Request request, String login) async {
|
||||
@@ -64,14 +64,14 @@ class AuthRoutes {
|
||||
|
||||
if (!database.isValidShareId(uniqueId!)) {
|
||||
await database.createLog(login, 'Accessed invalid share link');
|
||||
return Response(404, body: 'Share link not found');
|
||||
return Response(404, body: jsonEncode({'error': 'Share link not found'}), headers: {'Content-Type': 'application/json'});
|
||||
}
|
||||
|
||||
final position = await database.getLatestPosition();
|
||||
|
||||
if (position == null) {
|
||||
await database.createLog(login, 'Accessed share link - no position');
|
||||
return Response(404, body: 'No position available');
|
||||
return Response(404, body: jsonEncode({'error': 'No position available'}), headers: {'Content-Type': 'application/json'});
|
||||
}
|
||||
|
||||
await database.createLog(login, 'Accessed share link');
|
||||
@@ -80,6 +80,6 @@ class AuthRoutes {
|
||||
'y': position.yValue,
|
||||
'last_update': position.lastUpdate,
|
||||
'expires_at': position.expiresAt,
|
||||
}));
|
||||
}), headers: {'Content-Type': 'application/json'});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user