5 lab user work (осталось самое сложное)
This commit is contained in:
parent
f0784bdfcb
commit
cbd7fa1127
@ -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'
|
||||
|
@ -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) {
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
@ -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<Comment> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public void setPosts(List<Post> posts) {
|
||||
this.posts = posts;
|
||||
}
|
||||
}
|
||||
|
@ -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("*");
|
||||
}
|
||||
|
||||
}
|
||||
|
1
src/main/resources/public/favicon.svg
Normal file
1
src/main/resources/public/favicon.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M96 0C43 0 0 43 0 96V416c0 53 43 96 96 96H384h32c17.7 0 32-14.3 32-32s-14.3-32-32-32V384c17.7 0 32-14.3 32-32V32c0-17.7-14.3-32-32-32H384 96zm0 384H352v64H96c-17.7 0-32-14.3-32-32s14.3-32 32-32zm32-240c0-8.8 7.2-16 16-16H336c8.8 0 16 7.2 16 16s-7.2 16-16 16H144c-8.8 0-16-7.2-16-16zm16 48H336c8.8 0 16 7.2 16 16s-7.2 16-16 16H144c-8.8 0-16-7.2-16-16s7.2-16 16-16z"/></svg>
|
After Width: | Height: | Size: 611 B |
BIN
src/main/resources/public/img/Emblema.png
Normal file
BIN
src/main/resources/public/img/Emblema.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
146
src/main/resources/public/style.css
Normal file
146
src/main/resources/public/style.css
Normal file
@ -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;
|
||||
}
|
45
src/main/resources/templates/default.html
Normal file
45
src/main/resources/templates/default.html
Normal file
@ -0,0 +1,45 @@
|
||||
<html lang="ru"
|
||||
xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>Школа</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<link rel="icon" href="/favicon.svg">
|
||||
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
|
||||
<link rel="stylesheet" href="/style.css"/>
|
||||
</head>
|
||||
<body class="body_app">
|
||||
<header class="fs-4 fw-bold p-1 text-white bg-primary bg-gradient">
|
||||
<div><img class="img-fluid float-start" src="../img/Emblema.png" alt="Emblema"/>
|
||||
<p class="fs-5 Cont">Муниципальное бюджетное общеобразовательное учреждение средняя общеобразовательная школа №10</p>
|
||||
</div>
|
||||
<nav class="navbar navbar-expand-md navbar-dark">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span className="navbar-toggler-icon"></span></button>
|
||||
<nav class="headers-problem navbar navbar-expand-lg d-flex">
|
||||
<button class="navbar-toggler" type="button"
|
||||
data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
<a class="btn btn-outline-light mx-1" href="/user"> Авторизация </a>
|
||||
<a class="btn btn-outline-light mx-1" href="/news">Новости</a>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="d-flex text-white bg-info bg-gradient fw-bold">
|
||||
<div class="container container-padding" layout:fragment="content">
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
</th:block>
|
||||
</html>
|
13
src/main/resources/templates/error.html
Normal file
13
src/main/resources/templates/error.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div><span th:text="${error}"></span></div>
|
||||
<a href="/">На главную</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
35
src/main/resources/templates/user-edit.html
Normal file
35
src/main/resources/templates/user-edit.html
Normal file
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/user/{id}(id=${id})}" th:object="${userDto}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="firstName" class="form-label">Имя</label>
|
||||
<input type="text" class="form-control" id="firstName" th:field="${userDto.firstName}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="lastName" class="form-label">Фамилия</label>
|
||||
<input type="text" class="form-control" id="lastName" th:field="${userDto.lastName}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Почта</label>
|
||||
<input type="text" class="form-control" id="email" th:field="${userDto.email}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${id == null}">Добавить</span>
|
||||
<span th:if="${id != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/user}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
55
src/main/resources/templates/user.html
Normal file
55
src/main/resources/templates/user.html
Normal file
@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-outline-light text-center mx-2 my-2"
|
||||
th:href="@{/user/edit}">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">ID</th>
|
||||
<th scope="col">Имя</th>
|
||||
<th scope="col">Почта</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="user, iterator: ${users}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${user.id}"/>
|
||||
<td th:text="${user.firstName} + ' ' + ${user.lastName}" style="width: 60%"/>
|
||||
<td th:text="${user.email}" style="width: 60%"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-outline-light text-center mx-2"
|
||||
th:href="@{/user/edit/{id}(id=${user.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-outline-light text-center mx-2"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${user.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/user/delete/{id}(id=${user.id})}" method="post">
|
||||
<button th:id="'remove-' + ${user.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user