|
@@ -1,26 +1,56 @@
|
|
|
package pl.sudra.controller;
|
|
package pl.sudra.controller;
|
|
|
|
|
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
|
+import org.springframework.web.bind.ServletRequestUtils;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
import pl.sudra.domain.AppUser;
|
|
import pl.sudra.domain.AppUser;
|
|
|
|
|
+import pl.sudra.service.AppUserService;
|
|
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
|
public class AppUserController {
|
|
public class AppUserController {
|
|
|
|
|
+
|
|
|
|
|
+ private AppUserService appUserService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ public AppUserController(AppUserService appUserService) {
|
|
|
|
|
+ this.appUserService = appUserService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@RequestMapping(value = "/appUsers")
|
|
@RequestMapping(value = "/appUsers")
|
|
|
- public ModelAndView showAppUsers() {
|
|
|
|
|
- return new ModelAndView("appUser", "appUser", new AppUser());
|
|
|
|
|
|
|
+ public String showAppUsers(Model model, HttpServletRequest request) {
|
|
|
|
|
+ int appUserId = ServletRequestUtils.getIntParameter(request, "appUserId", -1);
|
|
|
|
|
+ if (appUserId > 0) {
|
|
|
|
|
+ model.addAttribute("appUser", appUserService.getAppUser(appUserId));
|
|
|
|
|
+ } else
|
|
|
|
|
+ model.addAttribute("appUser", new AppUser());
|
|
|
|
|
+ model.addAttribute("appUserList", appUserService.listAppUser());
|
|
|
|
|
+ return "appUser";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/addAppUser", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/addAppUser", method = RequestMethod.POST)
|
|
|
public String addAppUser(@ModelAttribute("appUser") AppUser appUser) {
|
|
public String addAppUser(@ModelAttribute("appUser") AppUser appUser) {
|
|
|
- System.out.println("" +
|
|
|
|
|
- "First Name: " + appUser.getFirstName() +
|
|
|
|
|
- " Last Name: " + appUser.getLastName() +
|
|
|
|
|
- " Tel.: " + appUser.getTelephone() +
|
|
|
|
|
- " Email: " + appUser.getEmail());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("First Name: " + appUser.getFirstName() +
|
|
|
|
|
+ " Last Name: " + appUser.getLastName() + " Tel.: " +
|
|
|
|
|
+ appUser.getTelephone() + " Email: " + appUser.getEmail());
|
|
|
|
|
+
|
|
|
|
|
+ if (appUser.getId() == 0)
|
|
|
|
|
+ appUserService.addAppUser(appUser);
|
|
|
|
|
+ else
|
|
|
|
|
+ appUserService.editAppUser(appUser);
|
|
|
|
|
+
|
|
|
return "redirect:appUsers";
|
|
return "redirect:appUsers";
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping("/delete/{appUserId}")
|
|
|
|
|
+ public String deleteUser(@PathVariable("appUserId") Long appUserId) {
|
|
|
|
|
+ appUserService.removeAppUser(appUserId);
|
|
|
|
|
+ return "redirect:/appUsers";
|
|
|
|
|
+ }
|
|
|
|
|
+}
|