diff --git a/src/main/java/com/maradona/backend/DefaultValueLoader.java b/src/main/java/com/maradona/backend/DefaultValueLoader.java index 09df26e..f66470c 100644 --- a/src/main/java/com/maradona/backend/DefaultValueLoader.java +++ b/src/main/java/com/maradona/backend/DefaultValueLoader.java @@ -35,11 +35,9 @@ public class DefaultValueLoader implements CommandLineRunner { @Override public void run(String... args) { - // Clear all tables - employeeRepository.deleteAll(); - secondarySkillRepository.deleteAll(); - primarySkillRepository.deleteAll(); - formOfAddressRepository.deleteAll(); + if (employeeRepository.count() > 0) { + return; + } // Create form of addresses FormOfAddress formOfAddress1 = new FormOfAddress(); @@ -48,9 +46,6 @@ public class DefaultValueLoader implements CommandLineRunner { FormOfAddress formOfAddress2 = new FormOfAddress(); formOfAddress2.setDescription("Frau"); - FormOfAddress formOfAddress3 = new FormOfAddress(); - formOfAddress3.setDescription("Einkaufstüte"); - formOfAddress1 = formOfAddressRepository.save(formOfAddress1); formOfAddress2 = formOfAddressRepository.save(formOfAddress2); diff --git a/src/main/java/com/maradona/backend/controllers/page/ErrorPage.java b/src/main/java/com/maradona/backend/controllers/page/ErrorPage.java new file mode 100644 index 0000000..b43024d --- /dev/null +++ b/src/main/java/com/maradona/backend/controllers/page/ErrorPage.java @@ -0,0 +1,58 @@ +package com.maradona.backend.controllers.page; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * Controller for routing to the error pages. + * + * List of endpoints: + * - GET /error/400 + * - GET /error/404 + * - GET /error/500 + */ +@Controller +@RequestMapping("/error") +public class ErrorPage { + /** + * Error page for 400 Bad Request. + * + * This page is displayed when the request is malformed and the server cannot + * process it. + * + * @return The 400 error page template. + */ + @GetMapping("/400") + public String error400() { + return "pages/error/400"; + } + + /** + * Error page for 404 Not Found. + * + * This page is displayed when the requested resource could not be found on the + * server. This can be due to a wrong URL or a deleted resource. The user should + * be informed that the resource is not available. + * + * @return The 404 error page template. + */ + @GetMapping("/404") + public String error404() { + return "pages/error/404"; + } + + /** + * Error page for 500 Internal Server Error. + * + * This page is displayed when the server encountered an unexpected condition + * that prevented it from fulfilling the request. The user should be informed + * that the server is experiencing problems and the request cannot be processed. + * + * @return The 500 error page template. + */ + @GetMapping("/500") + public String error500() { + return "pages/error/500"; + } +} diff --git a/src/main/java/com/maradona/backend/controllers/page/Page.java b/src/main/java/com/maradona/backend/controllers/page/Page.java index d252e55..18a74ac 100644 --- a/src/main/java/com/maradona/backend/controllers/page/Page.java +++ b/src/main/java/com/maradona/backend/controllers/page/Page.java @@ -4,24 +4,53 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +/** + * Controller for routing to the core pages. + * + * List of endpoints: + * - GET / + * - GET /impressum + * - GET /datenschutz + * - GET /notes + */ @Controller public class Page { - + /** + * Returns the home page. + * + * @param model The model with the data to be displayed. + * @return The home page template. + */ @GetMapping({ "/", "" }) public String home(Model model) { return "pages/core/home"; } + /** + * Returns the impressum page. + * + * @return The impressum page template. + */ @GetMapping("/impressum") public String impressum() { return "pages/core/impressum"; } + /** + * Returns the datenschutz page. + * + * @return The datenschutz page template. + */ @GetMapping("/datenschutz") public String datenschutz() { return "pages/core/datenschutz"; } + /** + * Returns the notes page. + * + * @return The notes page template. + */ @GetMapping("/notes") public String notes() { return "pages/core/notes"; diff --git a/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java b/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java index 3b298d3..207c98b 100644 --- a/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java +++ b/src/main/java/com/maradona/backend/controllers/page/SkillsPage.java @@ -52,7 +52,11 @@ public class SkillsPage { */ @GetMapping({ "/", "" }) public String profile(Model model) { - model.addAttribute("employee", employeeDetails.getEmployeeByEid(user).orElse(null)); + var employee = employeeDetails.getEmployeeByEid(user).orElse(null); + if (employee == null) { + return "/404"; + } + model.addAttribute("employee", employee); model.addAttribute("skills", skillService.getUserSkills(user)); return "/pages/skills/overview"; } diff --git a/src/main/java/com/maradona/backend/entities/Employee.java b/src/main/java/com/maradona/backend/entities/Employee.java index 9c85ae0..5cf719e 100644 --- a/src/main/java/com/maradona/backend/entities/Employee.java +++ b/src/main/java/com/maradona/backend/entities/Employee.java @@ -24,7 +24,7 @@ public class Employee { private String lastName; @ManyToOne - @JoinColumn(name = "FID", referencedColumnName = "fid") + @JoinColumn(name = "fid") private FormOfAddress formOfAddress; private LocalTime dStart;