diff --git a/src/main/java/org/workshop/coffee/repository/SearchRepository.java b/src/main/java/org/workshop/coffee/repository/SearchRepository.java index c425f4e7..6eb530a0 100644 --- a/src/main/java/org/workshop/coffee/repository/SearchRepository.java +++ b/src/main/java/org/workshop/coffee/repository/SearchRepository.java @@ -19,7 +19,18 @@ public class SearchRepository { DataSource dataSource; public List searchProduct (String input) { - return null; + // lowercase the input + var lowerInput = input.toLowerCase(Locale.ROOT); + + // create a query using named parameters that matches the lowerinput to the product description or product name + var query = em.createQuery("Select p from Product p where lower(p.description) like :input OR lower(p.productName) like :input", Product.class); + + // set the input parameter + query.setParameter("input", "%" + lowerInput + "%"); + + // get the result list + var resultList = (List) query.getResultList(); + return resultList; } } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 5e7e7073..f83f0ced 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -6,6 +6,11 @@
+ + + + +