Return corrected username in GET /lookup/byName

This commit is contained in:
Colin McDonald 2016-10-23 00:50:37 -04:00
parent 30ece4a60f
commit af8dd4d925
1 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,7 @@
package net.frozenorb.apiv3.route.lookup;
import com.google.common.collect.ImmutableMap;
import com.mongodb.async.client.MongoCollection;
import io.vertx.core.Handler;
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 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<>();
usersCollection.find(query).projection(project).into(into, SyncUtils.vertxWrap((users, error) -> {
@ -37,13 +39,16 @@ public class GETLookupByName implements Handler<RoutingContext> {
return;
}
Map<String, String> result = new HashMap<>();
Map<String, Map<String, String>> result = new HashMap<>();
users.forEach(doc -> {
String lowerName = doc.getString("lastUsernameLower");
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);