use findByParameter() in UsersModule

Tue, 19 May 2020 16:51:08 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 19 May 2020 16:51:08 +0200
changeset 66
635ae67e73b5
parent 65
9861a68a4612
child 67
d15779cf3982

use findByParameter() in UsersModule

src/main/java/de/uapcore/lightpit/modules/UsersModule.java file | annotate | diff | comparison | revisions
--- a/src/main/java/de/uapcore/lightpit/modules/UsersModule.java	Tue May 19 16:50:05 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/modules/UsersModule.java	Tue May 19 16:51:08 2020 +0200
@@ -39,7 +39,6 @@
 import javax.servlet.http.HttpServletRequest;
 import java.sql.SQLException;
 import java.util.NoSuchElementException;
-import java.util.Optional;
 
 @LightPITModule(
         bundleBaseName = "localization.users",
@@ -66,14 +65,9 @@
 
     @RequestMapping(requestPath = "edit", method = HttpMethod.GET)
     public ResponseType edit(HttpServletRequest req, DataAccessObjects dao) throws SQLException {
-        final var userDao = dao.getUserDao();
 
-        Optional<Integer> id = getParameter(req, Integer.class, "id");
-        if (id.isPresent()) {
-            req.setAttribute("user", Optional.ofNullable(userDao.find(id.get())).orElse(new User(-1)));
-        } else {
-            req.setAttribute("user", new User(-1));
-        }
+        req.setAttribute("user", findByParameter(req, Integer.class, "id",
+                dao.getUserDao()::find).orElse(new User(-1)));
 
         setDynamicFragment(req, "user-form");
 

mercurial