add json format to route /admin/get-all-users
continuous-integration/drone/push Build is passing Details

adminDb
remrem 3 years ago
parent b5c7a186c7
commit 6b76803443

@ -123,7 +123,7 @@ class API {
static Future<Response> getAllUsers(Request req) async {
PostgreSQLResult res = await AccountsToPostgres.getAllUsers();
String json = DB2API.map2Json(res);
String json = DB2API.allUsersToJson(res);
return Response.ok(json);
}
}

@ -121,6 +121,7 @@ class AccountsToPostgres {
static Future<PostgreSQLResult> getAllUsers() async {
PostgreSQLResult res =
await connection.query("SELECT id, hash, salt from \"Account\"");
print("🟥 ADMIN: get all users");
return res;
}
}

@ -1,8 +1,18 @@
import 'dart:convert';
import 'package:postgres/postgres.dart';
class DB2API {
static String map2Json(PostgreSQLResult data) {
return jsonEncode(data);
static String allUsersToJson(PostgreSQLResult data) {
String body = "";
int count = 0;
for (final row in data) {
body += userToString(row[0], row[1], row[2]);
count++;
if (count != data.length) body += ",";
}
return "[$body]";
}
static String userToString(String email, String hash, String salt) {
return """{"email" : "$email", "hash" : "$hash", "salt" : "$salt"}""";
}
}

@ -5,7 +5,7 @@ import 'package:passworld_api/db_to_api.dart';
void main() async {
await AccountsToPostgres.createAccountTable();
await AccountsToPostgres.create("remremc@gmail.com", "hehehe", "tameare");
//await AccountsToPostgres.create("remremj@gmail.com", "hehehe", "tameare");
var res = await AccountsToPostgres.getAllUsers();
for (final row in res) {
stdout.write(row[0]);
@ -13,7 +13,7 @@ void main() async {
print(row[2]);
}
//print(res.runtimeType);
String json = DB2API.map2Json(res);
String json = DB2API.allUsersToJson(res);
print(json);
AccountsToPostgres.closeConnection();
return;

Loading…
Cancel
Save