global catastrofe

This commit is contained in:
Zakharov_Rostislav 2024-05-29 21:23:59 +04:00
parent 20bc1999f5
commit 451230933b
36 changed files with 87 additions and 111 deletions

View File

@ -12,14 +12,14 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.authors.service.AuthorService;
import com.ip.library.books.model.BookEntity;
import com.ip.library.books.service.BookService;
import com.ip.library.types.model.TypeEntity;
import com.ip.library.types.service.TypeService;
import com.ip.library.users.model.UserEntity;
import com.ip.library.users.service.UserService;
import com.ip.library.controllers.authors.AuthorEntity;
import com.ip.library.controllers.authors.AuthorService;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.controllers.books.BookService;
import com.ip.library.controllers.types.TypeEntity;
import com.ip.library.controllers.types.TypeService;
import com.ip.library.controllers.users.UserEntity;
import com.ip.library.controllers.users.UserService;
@SuppressWarnings("unused")

View File

@ -1,4 +1,4 @@
package com.ip.library.authors.api;
package com.ip.library.controllers.authors;
import java.util.List;
@ -13,10 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ip.library.controllers.users.UserRole;
import com.ip.library.core.configuration.Constants;
import com.ip.library.users.model.UserRole;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.authors.service.AuthorService;
import jakarta.validation.Valid;

View File

@ -1,4 +1,4 @@
package com.ip.library.authors.api;
package com.ip.library.controllers.authors;
import com.fasterxml.jackson.annotation.JsonProperty;

View File

@ -1,11 +1,11 @@
package com.ip.library.authors.model;
package com.ip.library.controllers.authors;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import com.ip.library.authors_books.model.AuthorsBooksEntity;
import com.ip.library.books.model.BookEntity;
import com.ip.library.controllers.authors_books.AuthorsBooksEntity;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.core.model.BaseEntity;
import jakarta.persistence.CascadeType;

View File

@ -1,12 +1,10 @@
package com.ip.library.authors.repository;
package com.ip.library.controllers.authors;
import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.ip.library.authors.model.AuthorEntity;
public interface AuthorRepository extends
CrudRepository<AuthorEntity, Long>,
PagingAndSortingRepository<AuthorEntity, Long> {

View File

@ -1,4 +1,4 @@
package com.ip.library.authors.service;
package com.ip.library.controllers.authors;
import java.util.List;
import java.util.stream.StreamSupport;
@ -7,8 +7,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ip.library.core.error.NotFoundException;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.authors.repository.AuthorRepository;
@Service
public class AuthorService {

View File

@ -1,9 +1,9 @@
package com.ip.library.authors_books.model;
package com.ip.library.controllers.authors_books;
import java.util.Objects;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.books.model.BookEntity;
import com.ip.library.controllers.authors.AuthorEntity;
import com.ip.library.controllers.books.BookEntity;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;

View File

@ -1,4 +1,4 @@
package com.ip.library.authors_books.model;
package com.ip.library.controllers.authors_books;
import java.util.Objects;
import java.util.Optional;

View File

@ -1,4 +1,4 @@
package com.ip.library.books.api;
package com.ip.library.controllers.books;
import java.util.List;
@ -14,11 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ip.library.books.model.BookEntity;
import com.ip.library.books.service.BookService;
import com.ip.library.controllers.types.TypeService;
import com.ip.library.controllers.users.UserRole;
import com.ip.library.core.configuration.Constants;
import com.ip.library.types.service.TypeService;
import com.ip.library.users.model.UserRole;
import jakarta.validation.Valid;

View File

@ -1,4 +1,4 @@
package com.ip.library.books.api;
package com.ip.library.controllers.books;
import java.util.List;

View File

@ -1,11 +1,10 @@
package com.ip.library.books.model;
package com.ip.library.controllers.books;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import com.ip.library.core.model.BaseEntity;
import com.ip.library.types.model.TypeEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
@ -17,8 +16,9 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.authors_books.model.AuthorsBooksEntity;
import com.ip.library.controllers.authors.AuthorEntity;
import com.ip.library.controllers.authors_books.AuthorsBooksEntity;
import com.ip.library.controllers.types.TypeEntity;
@Entity
@Table(name = "books")

View File

@ -1,4 +1,4 @@
package com.ip.library.books.repository;
package com.ip.library.controllers.books;
import java.util.List;
import java.util.Optional;
@ -9,8 +9,6 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.ip.library.books.model.BookEntity;
public interface BookRepository extends
CrudRepository<BookEntity, Long>,
PagingAndSortingRepository<BookEntity, Long> {

View File

@ -1,4 +1,4 @@
package com.ip.library.books.service;
package com.ip.library.controllers.books;
import java.util.List;
import java.util.stream.StreamSupport;
@ -8,10 +8,8 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.authors.service.AuthorService;
import com.ip.library.books.model.BookEntity;
import com.ip.library.books.repository.BookRepository;
import com.ip.library.controllers.authors.AuthorEntity;
import com.ip.library.controllers.authors.AuthorService;
import com.ip.library.core.error.NotFoundException;
@Service

View File

@ -1,9 +1,9 @@
package com.ip.library.favorites.model;
package com.ip.library.controllers.favorites;
import java.util.Objects;
import com.ip.library.books.model.BookEntity;
import com.ip.library.users.model.UserEntity;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.controllers.users.UserEntity;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;

View File

@ -1,4 +1,4 @@
package com.ip.library.favorites.model;
package com.ip.library.controllers.favorites;
import java.util.Objects;
import java.util.Optional;

View File

@ -1,4 +1,4 @@
package com.ip.library.types.api;
package com.ip.library.controllers.types;
import java.util.List;
@ -13,10 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ip.library.controllers.users.UserRole;
import com.ip.library.core.configuration.Constants;
import com.ip.library.types.model.TypeEntity;
import com.ip.library.types.service.TypeService;
import com.ip.library.users.model.UserRole;
import jakarta.validation.Valid;

View File

@ -1,4 +1,4 @@
package com.ip.library.types.api;
package com.ip.library.controllers.types;
import com.fasterxml.jackson.annotation.JsonProperty;

View File

@ -1,4 +1,4 @@
package com.ip.library.types.model;
package com.ip.library.controllers.types;
import java.util.Objects;

View File

@ -1,11 +1,9 @@
package com.ip.library.types.repository;
package com.ip.library.controllers.types;
import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
import com.ip.library.types.model.TypeEntity;
public interface TypeRepository extends CrudRepository<TypeEntity, Long> {
Optional<TypeEntity> findByNameIgnoreCase(String name);
}

View File

@ -1,4 +1,4 @@
package com.ip.library.types.service;
package com.ip.library.controllers.types;
import java.util.List;
import java.util.stream.StreamSupport;
@ -7,8 +7,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ip.library.core.error.NotFoundException;
import com.ip.library.types.model.TypeEntity;
import com.ip.library.types.repository.TypeRepository;
@Service
public class TypeService {

View File

@ -1,4 +1,4 @@
package com.ip.library.users.api;
package com.ip.library.controllers.users;
import java.util.Objects;
@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ip.library.core.configuration.Constants;
import com.ip.library.users.model.UserEntity;
import com.ip.library.users.service.UserService;
@RestController
public class LoginController {

View File

@ -1,4 +1,4 @@
package com.ip.library.users.api;
package com.ip.library.controllers.users;
import java.util.List;
@ -10,11 +10,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ip.library.books.api.BookDto;
import com.ip.library.books.model.BookEntity;
import com.ip.library.controllers.books.BookDto;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.core.configuration.Constants;
import com.ip.library.users.model.UserRole;
import com.ip.library.users.service.UserService;
@RestController
@Secured(value = { UserRole.Secured.USER, UserRole.Secured.ADMIN })

View File

@ -1,4 +1,4 @@
package com.ip.library.users.api;
package com.ip.library.controllers.users;
import org.modelmapper.ModelMapper;
import org.springframework.security.access.annotation.Secured;
@ -15,9 +15,6 @@ import org.springframework.web.bind.annotation.RestController;
import com.ip.library.core.api.PageDto;
import com.ip.library.core.api.PageDtoMapper;
import com.ip.library.core.configuration.Constants;
import com.ip.library.users.model.UserEntity;
import com.ip.library.users.model.UserRole;
import com.ip.library.users.service.UserService;
import jakarta.validation.Valid;

View File

@ -1,4 +1,4 @@
package com.ip.library.users.api;
package com.ip.library.controllers.users;
import com.fasterxml.jackson.annotation.JsonProperty;

View File

@ -1,12 +1,12 @@
package com.ip.library.users.model;
package com.ip.library.controllers.users;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import com.ip.library.books.model.BookEntity;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.controllers.favorites.FavoriteEntity;
import com.ip.library.core.model.BaseEntity;
import com.ip.library.favorites.model.FavoriteEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;

View File

@ -1,4 +1,4 @@
package com.ip.library.users.repository;
package com.ip.library.controllers.users;
import java.util.List;
import java.util.Optional;
@ -9,8 +9,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.ip.library.books.model.BookEntity;
import com.ip.library.users.model.UserEntity;
import com.ip.library.controllers.books.BookEntity;
public interface UserRepository extends
CrudRepository<UserEntity, Long>,

View File

@ -1,4 +1,4 @@
package com.ip.library.users.model;
package com.ip.library.controllers.users;
import org.springframework.security.core.GrantedAuthority;

View File

@ -1,4 +1,4 @@
package com.ip.library.users.service;
package com.ip.library.controllers.users;
import java.util.List;
import java.util.Optional;
@ -14,16 +14,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import com.ip.library.books.model.BookEntity;
import com.ip.library.books.service.BookService;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.controllers.books.BookService;
import com.ip.library.core.configuration.Constants;
import com.ip.library.core.error.NotFoundException;
import com.ip.library.core.jwt.JwtException;
import com.ip.library.core.jwt.JwtProvider;
import com.ip.library.core.security.UserPrincipal;
import com.ip.library.users.model.UserEntity;
import com.ip.library.users.model.UserRole;
import com.ip.library.users.repository.UserRepository;
@Service
public class UserService implements UserDetailsService{
@ -77,6 +74,8 @@ public class UserService implements UserDetailsService{
public UserEntity create(UserEntity entity) {
if (entity == null)
throw new IllegalArgumentException("Entity is null");
if (entity.getPassword() == null)
throw new IllegalArgumentException("Entity.GetPassword is null");
checkLoginUniqueness(entity.getLogin());
final String password = Optional.ofNullable(entity.getPassword()).orElse("");
entity.setPassword(

View File

@ -10,7 +10,7 @@ import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
import com.ip.library.users.service.UserService;
import com.ip.library.controllers.users.UserService;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;

View File

@ -21,11 +21,11 @@ import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import com.ip.library.controllers.users.UserRole;
import com.ip.library.controllers.users.UserService;
import com.ip.library.core.configuration.Constants;
import com.ip.library.core.error.AdviceController;
import com.ip.library.core.jwt.JwtFilter;
import com.ip.library.users.model.UserRole;
import com.ip.library.users.service.UserService;
@Configuration
@EnableWebSecurity

View File

@ -6,7 +6,7 @@ import java.util.Set;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import com.ip.library.users.model.UserEntity;
import com.ip.library.controllers.users.UserEntity;
public class UserPrincipal implements UserDetails {
private final long id;

View File

@ -8,9 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import com.ip.library.controllers.authors.AuthorEntity;
import com.ip.library.controllers.authors.AuthorService;
import com.ip.library.core.error.NotFoundException;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.authors.service.AuthorService;
@SpringBootTest
class AuthorsTests {

View File

@ -11,12 +11,12 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import com.ip.library.core.error.NotFoundException;
import com.ip.library.types.model.TypeEntity;
import com.ip.library.types.service.TypeService;
import com.ip.library.authors.model.AuthorEntity;
import com.ip.library.authors.service.AuthorService;
import com.ip.library.books.model.BookEntity;
import com.ip.library.books.service.BookService;
import com.ip.library.controllers.authors.AuthorEntity;
import com.ip.library.controllers.authors.AuthorService;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.controllers.books.BookService;
import com.ip.library.controllers.types.TypeEntity;
import com.ip.library.controllers.types.TypeService;
@SpringBootTest
class BooksTests {

View File

@ -9,12 +9,12 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.ip.library.books.model.BookEntity;
import com.ip.library.books.service.BookService;
import com.ip.library.types.model.TypeEntity;
import com.ip.library.types.service.TypeService;
import com.ip.library.users.model.UserEntity;
import com.ip.library.users.service.UserService;
import com.ip.library.controllers.books.BookEntity;
import com.ip.library.controllers.books.BookService;
import com.ip.library.controllers.types.TypeEntity;
import com.ip.library.controllers.types.TypeService;
import com.ip.library.controllers.users.UserEntity;
import com.ip.library.controllers.users.UserService;
@SpringBootTest
class FavoritesTests {

View File

@ -8,9 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import com.ip.library.controllers.types.TypeEntity;
import com.ip.library.controllers.types.TypeService;
import com.ip.library.core.error.NotFoundException;
import com.ip.library.types.model.TypeEntity;
import com.ip.library.types.service.TypeService;
@SpringBootTest
class TypesTests {

View File

@ -7,16 +7,19 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.security.crypto.password.PasswordEncoder;
import com.ip.library.controllers.users.UserEntity;
import com.ip.library.controllers.users.UserRole;
import com.ip.library.controllers.users.UserService;
import com.ip.library.core.error.NotFoundException;
import com.ip.library.users.model.UserEntity;
import com.ip.library.users.model.UserRole;
import com.ip.library.users.service.UserService;
@SpringBootTest
class UsersTests {
@Autowired
private UserService userService;
@Autowired
private PasswordEncoder passwordEncoder;
private UserEntity user;
@AfterEach
@ -36,7 +39,7 @@ class UsersTests {
void createTest() {
Assertions.assertEquals(3, userService.getAll().size());
Assertions.assertEquals("user3", user.getLogin());
Assertions.assertEquals("aqw2sed45", user.getPassword());
Assertions.assertTrue(passwordEncoder.matches("aqw2sed45", user.getPassword()));
Assertions.assertEquals(UserRole.USER, user.getRole());
Assertions.assertEquals(0, user.getFavorites().size());
}
@ -102,7 +105,7 @@ class UsersTests {
@Test
void nullPasswordTest() {
Assertions.assertThrows(
DataIntegrityViolationException.class,
IllegalArgumentException.class,
() -> userService.create(new UserEntity(user.getLogin() + "TEST", null))
);
Assertions.assertThrows(