Return corrected username in GET /lookup/byName
This commit is contained in:
parent
30ece4a60f
commit
af8dd4d925
@ -1,5 +1,7 @@
|
|||||||
package net.frozenorb.apiv3.route.lookup;
|
package net.frozenorb.apiv3.route.lookup;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import com.mongodb.async.client.MongoCollection;
|
import com.mongodb.async.client.MongoCollection;
|
||||||
import io.vertx.core.Handler;
|
import io.vertx.core.Handler;
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
@ -28,7 +30,7 @@ public class GETLookupByName implements Handler<RoutingContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Document query = new Document("lastUsernameLower", new Document("$in", originalCase.keySet()));
|
Document query = new Document("lastUsernameLower", new Document("$in", originalCase.keySet()));
|
||||||
Document project = new Document("lastUsernameLower", 1); // includes _id automatically
|
Document project = new Document("lastUsernameLower", 1).append("lastUsername", 1); // includes _id automatically
|
||||||
List<Document> into = new ArrayList<>();
|
List<Document> into = new ArrayList<>();
|
||||||
|
|
||||||
usersCollection.find(query).projection(project).into(into, SyncUtils.vertxWrap((users, error) -> {
|
usersCollection.find(query).projection(project).into(into, SyncUtils.vertxWrap((users, error) -> {
|
||||||
@ -37,13 +39,16 @@ public class GETLookupByName implements Handler<RoutingContext> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> result = new HashMap<>();
|
Map<String, Map<String, String>> result = new HashMap<>();
|
||||||
|
|
||||||
users.forEach(doc -> {
|
users.forEach(doc -> {
|
||||||
String lowerName = doc.getString("lastUsernameLower");
|
String lowerName = doc.getString("lastUsernameLower");
|
||||||
String clientUuid = originalCase.get(lowerName);
|
String clientUuid = originalCase.get(lowerName);
|
||||||
|
|
||||||
result.put(clientUuid, doc.getString("_id"));
|
result.put(clientUuid, ImmutableMap.of(
|
||||||
|
"uuid", doc.getString("_id"),
|
||||||
|
"username", doc.getString("lastUsername")
|
||||||
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
APIv3.respondJson(ctx, 200, result);
|
APIv3.respondJson(ctx, 200, result);
|
||||||
|
Loading…
Reference in New Issue
Block a user