начинаю делать пагинацию
This commit is contained in:
parent
23789c477e
commit
b04eacffd1
@ -1,61 +1,61 @@
|
||||
// package com.example.backend.users.api;
|
||||
package com.example.backend.users.api;
|
||||
|
||||
// import org.modelmapper.ModelMapper;
|
||||
// import org.springframework.stereotype.Controller;
|
||||
// import org.springframework.ui.Model;
|
||||
// import org.springframework.validation.BindingResult;
|
||||
// import org.springframework.web.bind.annotation.GetMapping;
|
||||
// import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
// import org.springframework.web.bind.annotation.PostMapping;
|
||||
// import org.springframework.web.bind.annotation.RequestMapping;
|
||||
// import org.springframework.web.bind.annotation.RestController;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
// import com.example.backend.core.configurations.Constants;
|
||||
// import com.example.backend.users.model.UserEntity;
|
||||
// import com.example.backend.users.service.UserService;
|
||||
import com.example.backend.core.configurations.Constants;
|
||||
import com.example.backend.users.model.UserEntity;
|
||||
import com.example.backend.users.service.UserService;
|
||||
|
||||
// import jakarta.validation.Valid;
|
||||
// import org.springframework.web.bind.annotation.RequestBody;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
// @Controller
|
||||
// // @RequestMapping(Constants.API_URL + "/user")
|
||||
// public class UserController {
|
||||
@Controller
|
||||
// @RequestMapping(Constants.API_URL + "/user")
|
||||
public class UserController {
|
||||
|
||||
// private static final String CATEGORIES_VIEW = "categories";
|
||||
// private static final String LOGIN_VIEW = "login";
|
||||
// private static final String USER_ATTRIBUTE = "user";
|
||||
private static final String CATEGORIES_VIEW = "categories";
|
||||
private static final String LOGIN_VIEW = "login";
|
||||
private static final String USER_ATTRIBUTE = "user";
|
||||
|
||||
// private final UserService userService;
|
||||
// private final ModelMapper modelMapper;
|
||||
private final UserService userService;
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
// public UserController(UserService userService, ModelMapper modelMapper) {
|
||||
// this.modelMapper = modelMapper;
|
||||
// this.userService = userService;
|
||||
// }
|
||||
public UserController(UserService userService, ModelMapper modelMapper) {
|
||||
this.modelMapper = modelMapper;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
// private UserEntity toEntity(UserDTO dto) {
|
||||
// return modelMapper.map(dto, UserEntity.class);
|
||||
// }
|
||||
private UserEntity toEntity(UserDTO dto) {
|
||||
return modelMapper.map(dto, UserEntity.class);
|
||||
}
|
||||
|
||||
// private UserDTO toDto(UserEntity entity) {
|
||||
// return modelMapper.map(entity, UserDTO.class);
|
||||
// }
|
||||
private UserDTO toDto(UserEntity entity) {
|
||||
return modelMapper.map(entity, UserDTO.class);
|
||||
}
|
||||
|
||||
// @GetMapping("/edit/")
|
||||
// public String create(Model model) {
|
||||
// model.addAttribute(CATEGORIES_VIEW, new UserDTO());
|
||||
// return LOGIN_VIEW;
|
||||
// }
|
||||
@GetMapping("/edit/")
|
||||
public String create(Model model) {
|
||||
model.addAttribute(CATEGORIES_VIEW, new UserDTO());
|
||||
return LOGIN_VIEW;
|
||||
}
|
||||
|
||||
// @PostMapping("/edit/")
|
||||
// public String create(
|
||||
// @ModelAttribute(name = USER_ATTRIBUTE) @Valid UserDTO userDTO,
|
||||
// BindingResult bindingResult,
|
||||
// Model model) {
|
||||
// if (bindingResult.hasErrors()) {
|
||||
// return LOGIN_VIEW + "/login";
|
||||
// }
|
||||
// userService.create(toEntity(userDTO));
|
||||
// return Constants.REDIRECT_VIEW + "/user";
|
||||
// }
|
||||
// }
|
||||
@PostMapping("/edit/")
|
||||
public String create(
|
||||
@ModelAttribute(name = USER_ATTRIBUTE) @Valid UserDTO userDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return LOGIN_VIEW + "/login";
|
||||
}
|
||||
userService.create(toEntity(userDTO));
|
||||
return Constants.REDIRECT_VIEW + "/user";
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,11 @@ package com.example.backend.users.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
import com.example.backend.users.model.UserEntity;
|
||||
|
||||
public interface UserRepository extends CrudRepository<UserEntity, Integer> {
|
||||
public interface UserRepository
|
||||
extends CrudRepository<UserEntity, Integer>, PagingAndSortingRepository<UserEntity, Integer> {
|
||||
Optional<UserEntity> findByLoginIgnoreCase(String login);
|
||||
}
|
||||
|
@ -32,18 +32,28 @@
|
||||
<div class="collapse navbar-collapse" id="main-navbar">
|
||||
<ul class="navbar-nav me-auto link" th:with="activeLink=${#objects.nullSafe(servletPath, '')}">
|
||||
<th:block sec:authorize="hasRole('ADMIN')">
|
||||
<a class="nav-link" href="/admin/categories" th:classappend="${activeLink.startsWith('/admin/movies')
|
||||
? 'active' : '' }">
|
||||
Категории
|
||||
</a>
|
||||
<a class="nav-link" href="/admin/movies" th:classappend="${activeLink.startsWith('/admin/movies')
|
||||
? 'active' : '' }">
|
||||
Фильмы
|
||||
</a>
|
||||
<a class="nav-link" href="/admin/users"
|
||||
th:classappend="${activeLink.startsWith('/admin/users')? 'active' : '' }">Пользователи</a>
|
||||
<a class="nav-link" href="/admin/categories"
|
||||
th:classappend="${activeLink.startsWith('/admin/categories')? 'active' : '' }">Категории</a>
|
||||
<a class="nav-link" href="/admin/movies"
|
||||
th:classappend="${activeLink.startsWith('/admin/movies') ? 'active' : '' }">Фильмы</a>
|
||||
<a class="nav-link" href="/admin/favorites"
|
||||
th:classappend="${activeLink.startsWith('/admin/favorites') ? 'active' : '' }">Избранные</a>
|
||||
<a class="nav-link" href="/admin/viewed"
|
||||
th:classappend="${activeLink.startsWith('/admin/viewed') ? 'active' : '' }">Просмотренные</a>
|
||||
<a class="nav-link" href="/h2-console/" target="_blank">Консоль H2</a>
|
||||
</th:block>
|
||||
<a class="nav-link" href="/categories"
|
||||
th:classappend="${activeLink.startsWith('/categories') ? 'active' : '' }"></a>
|
||||
<th:block sec:authorize="hasRole('USER')">
|
||||
<a class="nav-link" href="/categories"
|
||||
th:classappend="${activeLink.startsWith('/categories') ? 'active' : '' }">Категории</a>
|
||||
<a class="nav-link" href="/movies"
|
||||
th:classappend="${activeLink.startsWith('/movies') ? 'active' : '' }">Фильмы</a>
|
||||
<a class="nav-link" href="/favorites"
|
||||
th:classappend="${activeLink.startsWith('/favorites') ? 'active' : '' }">Избранные</a>
|
||||
<a class="nav-link" href="/viewed"
|
||||
th:classappend="${activeLink.startsWith('/viewed') ? 'active' : '' }">Просмотренные</a>
|
||||
</th:block>
|
||||
</ul>
|
||||
<ul class="navbar-nav" th:if="${not #strings.isEmpty(userName)}">
|
||||
<form th:action="@{/logout}" method="post">
|
||||
|
15
backend/src/main/resources/templates/favorites.html
Normal file
15
backend/src/main/resources/templates/favorites.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
|
||||
|
||||
|
||||
<head>
|
||||
<title>Просмотренные</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main layout:fragment="content">
|
||||
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user