diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-12 18:05:04 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-12 18:05:04 +0100 |
commit | dfb72423ed82a293eec85b1b36d9e4c895d7b49c (patch) | |
tree | b3a84ac53039e1c46f75e37a875ca3d8081c8bb7 /src/main/java/io | |
parent | 4e78dad3ec73a6e342e5f2a0dbfd802810b7d330 (diff) | |
download | esper-testing-dfb72423ed82a293eec85b1b36d9e4c895d7b49c.tar.gz esper-testing-dfb72423ed82a293eec85b1b36d9e4c895d7b49c.tar.bz2 esper-testing-dfb72423ed82a293eec85b1b36d9e4c895d7b49c.tar.xz esper-testing-dfb72423ed82a293eec85b1b36d9e4c895d7b49c.zip |
o Implementing search on people page.
Diffstat (limited to 'src/main/java/io')
-rwxr-xr-x | src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java | 11 | ||||
-rwxr-xr-x | src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java | 5 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java index 8d74264..2b74771 100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java @@ -96,15 +96,24 @@ public class PersonDao { } } - public List<PersonDto> selectPersons(PageRequest pageRequest) throws SQLException { + public List<PersonDto> selectPersons(PageRequest pageRequest, Option<String> query) throws SQLException { String sql = "SELECT " + PERSON + " FROM person"; + if (query.isSome()) { + sql += " WHERE lower(name) LIKE '%' || ? || '%'"; + } + sql += orderBy(pageRequest.orderBy, "name", "created_date"); sql += " LIMIT ? OFFSET ?"; try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; + + if (query.isSome()) { + s.setString(i++, query.some()); + } + s.setInt(i++, pageRequest.count.orSome(10)); s.setInt(i, pageRequest.startIndex.orSome(0)); return toList(s, person); diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java index 83f5144..11935cf 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java @@ -33,11 +33,12 @@ public class CoreResource extends AbstractResource { @GET @Path("/person") - public List<PersonDetailJson> getPersons(@MagicParam final PageRequest pageRequest) throws Exception { + public List<PersonDetailJson> getPersons(@MagicParam final PageRequest pageRequest, + @QueryParam("query") final String query) throws Exception { return da.inTransaction(new CoreDaosCallback<List<PersonDetailJson>>() { protected List<PersonDetailJson> run() throws SQLException { List<PersonDetailJson> list = new ArrayList<>(); - for (PersonDto person : daos.personDao.selectPersons(pageRequest)) { + for (PersonDto person : daos.personDao.selectPersons(pageRequest, fromNull(query))) { list.add(super.getPersonDetailJson.apply(person)); } return list; |