Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/club/ttg/dnd5/dictionary/beastiary/CreatureType.java
#	src/main/java/club/ttg/dnd5/utills/Converter.java
  • Loading branch information
ProtectorRTD committed Jan 16, 2025
2 parents 4ecc5a1 + e0279ed commit 7815c67
Show file tree
Hide file tree
Showing 112 changed files with 4,670 additions and 1,131 deletions.
33 changes: 33 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
<tag/>
<url/>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-dependencies</artifactId>
<version>3.0.0-RC2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -36,6 +47,9 @@
<mapstruct.version>1.6.0.Beta2</mapstruct.version>
<mapstruct-processor.version>1.5.5.Final</mapstruct-processor.version>
<liqui-base.version>4.24.0</liqui-base.version>
<slugify.version>3.0.7</slugify.version>
<icu4j.version>76.1</icu4j.version>
<commons-io.version>2.18.0</commons-io.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -117,6 +131,25 @@
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-s3</artifactId>
</dependency>
<dependency>
<groupId>com.github.slugify</groupId>
<artifactId>slugify</artifactId>
<version>${slugify.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>${icu4j.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
55 changes: 42 additions & 13 deletions src/main/java/club/ttg/dnd5/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package club.ttg.dnd5.config;

import club.ttg.dnd5.security.JwtAuthFilter;
import club.ttg.dnd5.service.user.UserService;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;

import java.util.Arrays;
import java.util.List;

import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
Expand All @@ -29,32 +34,54 @@
)
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
@RequiredArgsConstructor
@EnableMethodSecurity(securedEnabled = true)
public class SecurityConfig {
private final UserDetailsService userDetailsService;
private final UserService userService;
private final JwtAuthFilter jwtAuthFilter;

private final String[] ignored = Arrays
.asList(
"/v3/api-docs/**",
"/swagger-ui.html",
"/swagger-ui/**",
"/scalar-ui.html",
"/api/auth/**",
"/api/v2/**"
)
.toArray(String[]::new);

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(AbstractHttpConfigurer::disable)
.cors(cors -> cors.configurationSource(this::getCorsConfigurer))
.authorizeHttpRequests(request -> request
.requestMatchers("/**").permitAll()
.requestMatchers(ignored).permitAll()
.anyRequest().authenticated()
)
.sessionManagement(manager -> manager.sessionCreationPolicy(STATELESS))
.authenticationProvider(authenticationProvider());
.authenticationProvider(authenticationProvider())
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);

http.httpBasic(AbstractHttpConfigurer::disable);

return http.build();
}

@Bean
AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService);
provider.setPasswordEncoder(passwordEncoder());
return provider;
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();

authProvider.setUserDetailsService(userService.userDetailsService());
authProvider.setPasswordEncoder(passwordEncoder());

return authProvider;
}

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager();
}

@Bean
Expand All @@ -63,11 +90,13 @@ public BCryptPasswordEncoder passwordEncoder(){
}

CorsConfiguration getCorsConfigurer(final HttpServletRequest httpServletRequest) {
var corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowedOrigins(List.of("*"));
CorsConfiguration corsConfiguration = new CorsConfiguration();

corsConfiguration.setAllowedOriginPatterns(List.of("*"));
corsConfiguration.setAllowedMethods(List.of("*"));
corsConfiguration.setAllowedHeaders(List.of("*"));
corsConfiguration.setAllowCredentials(false);
corsConfiguration.setAllowCredentials(true);

return corsConfiguration;
}
}
61 changes: 0 additions & 61 deletions src/main/java/club/ttg/dnd5/controller/MenuApiController.java

This file was deleted.

110 changes: 110 additions & 0 deletions src/main/java/club/ttg/dnd5/controller/book/BookController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package club.ttg.dnd5.controller.book;

import club.ttg.dnd5.dto.book.SourceBookDTO;
import club.ttg.dnd5.service.book.BookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v2/books")
@RequiredArgsConstructor
@Tag(name = "Книги", description = "Контроллер для управления книгами и их поиском")
public class BookController {
private final BookService bookService;

/**
* Создание новой книги.
*
* @param sourceBookDTO данные новой книги
* @return созданная книга
*/
@PostMapping("/create")
@Operation(summary = "Создать книгу", description = "Позволяет создать новую книгу.")
public ResponseEntity<SourceBookDTO> createBook(@RequestBody SourceBookDTO sourceBookDTO) {
SourceBookDTO createdBook = bookService.createBook(sourceBookDTO);
return ResponseEntity.status(HttpStatus.CREATED).body(createdBook);
}

/**
* Получение всех книг.
*
*
* @return список книг
*/
@PostMapping("/search")
@Operation(summary = "Получить книги", description = "Возвращает список книги")
public ResponseEntity<List<SourceBookDTO>> getBooksByType() {
List<SourceBookDTO> books = bookService.getAllBooks();
return ResponseEntity.ok(books);
}

/**
* Поиск книг по типу.
*
* @param typeName имя типа книги
* @return список книг соответствующего типа
*/
@PostMapping("/search/type")
@Operation(summary = "Получить книги по типу", description = "Возвращает список книг определённого типа.")
public ResponseEntity<List<SourceBookDTO>> getBooksByType(
@Parameter(description = "Имя типа книги для поиска", example = "Базовые") @RequestParam String typeName) {
List<SourceBookDTO> books = bookService.getBooksByType(typeName);
return ResponseEntity.ok(books);
}

@PostMapping("/by-book-tag-type")
@Operation(summary = "Получить книги по типу тега", description = "Возвращает книги, связанные с тегами типа TAG_BOOK")
public ResponseEntity<List<SourceBookDTO>> getBooksByBookTagType() {
List<SourceBookDTO> books = bookService.getBooksByBookTagType();
return ResponseEntity.ok(books);
}

/**
* Получение книги по акрониму источника.
*
* @param acronym акроним источника книги
* @return данные книги или 404, если книга не найдена
*/
@GetMapping("/{acronym}")
@Operation(summary = "Получить книгу по акрониму источника", description = "Возвращает книгу по указанному акрониму источника.")
public ResponseEntity<SourceBookDTO> getBookBySourceAcronym(
@Parameter(description = "Акроним источника книги", example = "PHB") @PathVariable String acronym) {
return bookService.getBookBySourceAcronym(acronym)
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());
}

/**
* Получение всех типов книг.
*
* @return список всех доступных типов книг
*/
@GetMapping("/dictionary/book-types")
@Operation(summary = "Получить все типы книг", description = "Возвращает список всех типов книг.")
public ResponseEntity<List<String>> getAllBookTypes() {
List<String> bookTypes = bookService.getAllBookTypes();
return ResponseEntity.ok(bookTypes);
}

/**
* Поиск книг по тегу.
*
* @param tagName имя тега
* @return список книг с указанным тегом
*/
@GetMapping("/search/by-tag")
@Operation(summary = "Получить книги по тегу", description = "Возвращает список книг, связанных с указанным тегом.")
public ResponseEntity<List<SourceBookDTO>> getBooksByTag(
@Parameter(description = "Имя тега для поиска", example = "Официальные") @RequestParam String tagName) {
List<SourceBookDTO> books = bookService.getBooksByTag(tagName);
return ResponseEntity.ok(books);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ClassDto getClass(@PathVariable String url) {
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@ResponseStatus(HttpStatus.CREATED)
@Secured("ROLE_ADMIN")
@Secured("ADMIN")
@PostMapping
public ClassDto addClass(@RequestBody final ClassDto request) {
return classService.addClass(request);
Expand Down Expand Up @@ -106,7 +106,7 @@ public ClassDto addFeature(
@ApiResponse(responseCode = "404", description = "Класс не найден"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@Secured("ROLE_ADMIN")
@Secured("ADMIN")
@PutMapping("/{url}")
public ClassDto updateClass(
@PathVariable final String url,
Expand Down

This file was deleted.

Loading

0 comments on commit 7815c67

Please sign in to comment.