diff --git a/build.gradle b/build.gradle index 062988a..926a6cc 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,6 @@ jar { enabled = false } dependencies { - implementation(project(':FrontEnd')) implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-devtools' diff --git a/src/main/java/ru/ulstu/is/sbapp/User/controller/UserController.java b/src/main/java/ru/ulstu/is/sbapp/User/controller/UserController.java index c56f7ee..befae19 100644 --- a/src/main/java/ru/ulstu/is/sbapp/User/controller/UserController.java +++ b/src/main/java/ru/ulstu/is/sbapp/User/controller/UserController.java @@ -5,11 +5,12 @@ import org.springframework.web.bind.annotation.*; import ru.ulstu.is.sbapp.Post.model.PostDto; import ru.ulstu.is.sbapp.User.model.UserDto; import ru.ulstu.is.sbapp.User.service.UserService; +import ru.ulstu.is.sbapp.WebConfiguration; import java.util.List; @RestController -@RequestMapping("/user") +@RequestMapping(WebConfiguration.REST_API + "/user") public class UserController { private final UserService userService; public UserController(UserService userService) { diff --git a/src/main/java/ru/ulstu/is/sbapp/User/controller/UserMvcController.java b/src/main/java/ru/ulstu/is/sbapp/User/controller/UserMvcController.java new file mode 100644 index 0000000..053a8c3 --- /dev/null +++ b/src/main/java/ru/ulstu/is/sbapp/User/controller/UserMvcController.java @@ -0,0 +1,62 @@ +package ru.ulstu.is.sbapp.User.controller; + +import jakarta.validation.Valid; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import ru.ulstu.is.sbapp.User.model.UserDto; +import ru.ulstu.is.sbapp.User.service.UserService; + +@Controller +@RequestMapping("/user") +public class UserMvcController { + private final UserService userService; + public UserMvcController(UserService userService) + { + this.userService=userService; + } + @GetMapping + public String getUser(Model model) { + model.addAttribute("users", + userService.findAllUsers().stream() + .map(UserDto::new) + .toList()); + return "user"; + } + + @GetMapping(value = {"/edit", "/edit/{id}"}) + public String editUser(@PathVariable(required = false) Long id, + Model model) { + if (id == null || id <= 0) { + model.addAttribute("userDto", new UserDto()); + } else { + model.addAttribute("userId", id); + model.addAttribute("userDto", new UserDto(userService.findUser(id))); + } + return "user-edit"; + } + + @PostMapping(value = {"/", "/{id}"}) + public String saveUser(@PathVariable(required = false) Long id, + @ModelAttribute @Valid UserDto userDto, + BindingResult bindingResult, + Model model) { + if (bindingResult.hasErrors()) { + model.addAttribute("errors", bindingResult.getAllErrors()); + return "user-edit"; + } + if (id == null || id <= 0) { + userService.addUser(userDto.getFirstName(), userDto.getLastName(),userDto.getEmail()); + } else { + userService.updateUser(id, userDto.getFirstName(), userDto.getLastName(),userDto.getEmail()); + } + return "redirect:/user"; + } + + @PostMapping("/delete/{id}") + public String deleteUser(@PathVariable Long id) { + userService.deleteUser(id); + return "redirect:/user"; + } +} diff --git a/src/main/java/ru/ulstu/is/sbapp/User/model/UserDto.java b/src/main/java/ru/ulstu/is/sbapp/User/model/UserDto.java index 708dd1b..20b9ba4 100644 --- a/src/main/java/ru/ulstu/is/sbapp/User/model/UserDto.java +++ b/src/main/java/ru/ulstu/is/sbapp/User/model/UserDto.java @@ -52,4 +52,28 @@ public class UserDto { { return email; } + public void setEmail(String email) + { + this.email=email; + } + + public void setId(Long id) { + this.id = id; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public void setComments(List comments) { + this.comments = comments; + } + + public void setPosts(List posts) { + this.posts = posts; + } } diff --git a/src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java b/src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java index e94e27b..fa9fd8d 100644 --- a/src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java +++ b/src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java @@ -2,12 +2,20 @@ package ru.ulstu.is.sbapp; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebConfiguration implements WebMvcConfigurer { + public static final String REST_API = "/api"; + @Override - public void addCorsMappings(CorsRegistry registry) - { + public void addViewControllers(ViewControllerRegistry registry) { + WebMvcConfigurer.super.addViewControllers(registry); + } + + @Override + public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedMethods("*"); } + } diff --git a/src/main/resources/public/favicon.svg b/src/main/resources/public/favicon.svg new file mode 100644 index 0000000..419c76c --- /dev/null +++ b/src/main/resources/public/favicon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main/resources/public/img/Emblema.png b/src/main/resources/public/img/Emblema.png new file mode 100644 index 0000000..d15a19b Binary files /dev/null and b/src/main/resources/public/img/Emblema.png differ diff --git a/src/main/resources/public/style.css b/src/main/resources/public/style.css new file mode 100644 index 0000000..126df10 --- /dev/null +++ b/src/main/resources/public/style.css @@ -0,0 +1,146 @@ +html +{ + min-height: 100vh; +} +header .img-fluid +{ + width:232px; + height:100px; +} + +article .img-fluid +{ + height:250px; +} +article .img-fluid1 +{ + height:100%; + width: 96%; +} +.owl +{ + width:300px; +} +.pdf-size +{ + width:70px; +} +body +{ + min-height: 100vh; +} +.body_app +{ + display: grid; + grid-template-rows:auto 1fr auto; + min-height: 100vh; +} +.lp +{ + padding-left: 30px; +} +.img-school +{ + margin-right: 1em; + float: start; + +} +.Vnov +{ + margin-right: 1em; +} +.Vnov1 +{ + margin-right: 1em; +} +.Cont +{ + +} + +@media only screen and (max-width: 800px) { + .owl { + display:none; + } +} +@media only screen and (max-width: 1164px) { + .img-school + { + margin-right: 170px; + } +} +@media only screen and (max-width: 554px) { + .img-school + { + height: 20% !important; + width: 75%; + } +} +@media only screen and (max-width: 727px) { + .headers-problem + { + + flex-direction: column; + } + .navbar + { + align-items: flex-start !important; + } + +} +@media only screen and (max-width: 959px) { + .navbar + { + float:left !important; + } +} +@media only screen and (max-width: 463px) { + .Vnov + { + margin-right: 140px; + } +} +@media only screen and (max-width: 575px) { + .Vnov1 + { + margin-right: 200px; + } +} +@media only screen and (max-width: 585px) { + .Cont + { + margin-right: 200px; + } +} + + +#banner { + margin: 15px; + display: flex; + align-items: center; + flex-direction: column; + } + + #banner img { + border-radius: 5px; + } + + #banner img.show { + height: 40%; + width: 60%; + opacity: 1; + transition: opacity 1s, visibility 0s; + } + + #banner img.hide { + height: 0; + width: 0; + opacity: 0; + visibility: hidden; + transition: opacity 1s, visibility 0s 1s; + } + +.Pole_height +{ + height: 80px; +} \ No newline at end of file diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html new file mode 100644 index 0000000..036f9e1 --- /dev/null +++ b/src/main/resources/templates/default.html @@ -0,0 +1,45 @@ + + + + Школа + + + + + + + + +
+
Emblema +

Муниципальное бюджетное общеобразовательное учреждение средняя общеобразовательная школа №10

+
+ +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..f960e68 --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,13 @@ + + + + + +
+
+ На главную +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/user-edit.html b/src/main/resources/templates/user-edit.html new file mode 100644 index 0000000..f0062a4 --- /dev/null +++ b/src/main/resources/templates/user-edit.html @@ -0,0 +1,35 @@ + + + + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + + Назад + +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/user.html b/src/main/resources/templates/user.html new file mode 100644 index 0000000..29b8391 --- /dev/null +++ b/src/main/resources/templates/user.html @@ -0,0 +1,55 @@ + + + + + +
+
+ + + +
+
+ + + + + + + + + + + + + + + +
#IDИмяПочта
+ + + + +
+ + Изменить + + +
+
+ +
+
+
+
+ + \ No newline at end of file