mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
55 lines
1.4 KiB
Java
55 lines
1.4 KiB
Java
|
package catering.users;
|
||
|
|
||
|
import org.springframework.ui.Model;
|
||
|
import org.springframework.stereotype.Controller;
|
||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||
|
|
||
|
@Controller
|
||
|
public class UserController {
|
||
|
|
||
|
private final UserManagement userManagement;
|
||
|
|
||
|
UserController(UserManagement userManagerment){
|
||
|
this.userManagement = userManagerment;
|
||
|
};
|
||
|
|
||
|
@GetMapping("/profile")
|
||
|
public String index(Model model) {
|
||
|
|
||
|
model.addAttribute("user", userManagement.getUsers().findAll().toList().get(0));
|
||
|
|
||
|
return "profile";
|
||
|
}
|
||
|
|
||
|
@PostMapping("/profile")
|
||
|
public String editProfile(@RequestParam String password, @RequestParam String address, @RequestParam String username) {
|
||
|
|
||
|
User userAccount = userManagement.getUsers().findAll().toList().get(0);
|
||
|
|
||
|
if (!username.isBlank()){
|
||
|
userAccount.setUsername(username);
|
||
|
}
|
||
|
|
||
|
if (!address.isBlank()){
|
||
|
userAccount.setAddress(address);
|
||
|
}
|
||
|
|
||
|
if (!password.isBlank()){
|
||
|
userManagement.setPassword(password, userAccount.getUserAccount());
|
||
|
}
|
||
|
|
||
|
userManagement.save(userAccount);
|
||
|
|
||
|
return "redirect:/profile";
|
||
|
}
|
||
|
|
||
|
@GetMapping("/profile/delete")
|
||
|
public String deleteUser() {
|
||
|
User userAccount = userManagement.getUsers().findAll().toList().get(0);
|
||
|
userManagement.deleteUser(userAccount);
|
||
|
return "redirect:/";
|
||
|
}
|
||
|
}
|