Fixed user search

This commit is contained in:
DieGurke 2020-02-08 14:27:21 +01:00
parent 1630b3aede
commit b4a5435b5f
3 changed files with 11 additions and 4 deletions

View File

@ -10,7 +10,12 @@ import envoy.server.data.ConfigItem;
import envoy.server.database.PersistenceManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
import envoy.server.processors.*;
import envoy.server.processors.ContactsRequestProcesor;
import envoy.server.processors.IdGeneratorRequestProcessor;
import envoy.server.processors.LoginCredentialProcessor;
import envoy.server.processors.MessageProcessor;
import envoy.server.processors.MessageStatusChangeProcessor;
import envoy.server.processors.UserStatusChangeProcessor;
/**
* Starts the server.<br>
@ -38,6 +43,7 @@ public class Startup {
processors.add(new MessageStatusChangeProcessor());
processors.add(new UserStatusChangeProcessor());
processors.add(new IdGeneratorRequestProcessor());
processors.add(new ContactsRequestProcesor());
Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
initializeCurrentMessageId();

View File

@ -177,7 +177,7 @@ public class PersistenceManager {
}
public List<User> searchUsers(String searchPhrase) {
return entityManager.createNamedQuery("searchUsers").setParameter("searchPhrase", searchPhrase).getResultList();
return entityManager.createNamedQuery("searchUsers").setParameter("searchPhrase", searchPhrase + "%").getResultList();
}
/**

View File

@ -3,6 +3,7 @@ package envoy.server.processors;
import java.io.IOException;
import java.util.stream.Collectors;
import envoy.data.Contacts;
import envoy.event.ContactsRequest;
import envoy.server.ObjectProcessor;
import envoy.server.database.PersistenceManager;
@ -21,11 +22,11 @@ public class ContactsRequestProcesor implements ObjectProcessor<ContactsRequest>
@Override
public void process(ContactsRequest request, long socketId, ObjectWriteProxy writeProxy) throws IOException {
writeProxy.write(socketId,
PersistenceManager.getPersistenceManager()
new Contacts(PersistenceManager.getPersistenceManager()
.searchUsers(request.get())
.stream()
.map(envoy.server.data.User::toCommonUser)
.collect(Collectors.toList()));
.collect(Collectors.toList())));
}
@Override