Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавление тестовых данных на Dev + раннер Скриптов #28

Merged
merged 5 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/main/java/club/ttg/dnd5/config/OpenApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenApiConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI().addSecurityItem(new SecurityRequirement().
addList("Bearer Authentication"))
.components(new Components().addSecuritySchemes
("Bearer Authentication", createAPIKeyScheme()))
.info(new Info().title("TTG REST API"));
return new OpenAPI()
.addSecurityItem(new SecurityRequirement()
.addList("Bearer Authentication"))
.components(new Components()
.addSecuritySchemes("Bearer Authentication", createAPIKeyScheme()))
.info(createApiInfo())
.addServersItem(new Server().url("/").description("Default Server URL"));
}

private SecurityScheme createAPIKeyScheme() {
return new SecurityScheme().type(SecurityScheme.Type.HTTP)
return new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.bearerFormat("JWT")
.scheme("bearer");
}

private Info createApiInfo() {
return new Info()
.title("TTG REST API")
.version("2.0")
.description("This is the API documentation for the TTG application.")
.contact(new Contact()
.name("Support Team")
.email("support@ttg.club")
.url("https://ttg.club"));
}
}
29 changes: 29 additions & 0 deletions src/main/java/club/ttg/dnd5/config/SqlScriptRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package club.ttg.dnd5.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;

import javax.sql.DataSource;

@Configuration
public class SqlScriptRunner {

@Bean
public DataSourceInitializer dataSourceInitializer(@Qualifier("dataSource") final DataSource dataSource) {
try {
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
resourceDatabasePopulator.addScript(new ClassPathResource("/scripts/setup.sql"));
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
dataSourceInitializer.setDataSource(dataSource);
dataSourceInitializer.setDatabasePopulator(resourceDatabasePopulator);
return dataSourceInitializer;
} catch (Exception sqlException) {
sqlException.printStackTrace();
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
public class SpeciesController {
private final SpeciesService speciesService;

@GetMapping("species")
@Operation(summary = "Получение всех видов", description = "Виды будут не детальные, будет возвращать списков с указанным имени и урл")
public ResponseEntity<List<SpeciesDto>> getAllSpecies() {
return ResponseEntity.ok(speciesService.getAllSpecies());
}

@GetMapping("/{parentUrl}/subspecies")
@Operation(summary = "Получить подвиды по URL родительского вида",
description = "Возвращает список подвидов, связанных с указанным родительским видом по его URL.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public SpeciesDto findById(String url) {
.orElseThrow(() -> new EntityNotFoundException(url));
}

public List<SpeciesDto> getAllSpecies() {
return speciesRepository.findAll()
.stream()
.map(species -> toDTO(species, true))
.toList();
}

@Transactional
public SpeciesDto save(CreateSpeciesDto createSpeciesDTO) {
Species species = new Species();
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
spring.application.name=ttg.club
spring.main.banner-mode=off

spring.jpa.show-sql=false
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.use_sql_comments = true
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.ddl-auto = create-drop


spring.datasource.url=jdbc:mysql://${dbhost}:${dbport:3306}/${dbname:ttg}?ssl=false&characterEncoding=UTF-8
spring.datasource.username = ${dbuser}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/scripts/books.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
INSERT INTO books
VALUES ('PHB', null, null, 'ПХБ', 'S', 'PHB', 'Player Hands Book', 'OFFICIAL', 2024);
INSERT INTO books (source_acronym, name, alt_name, english_name, description, type, year)
VALUES ('PHB', 'ПХБ', 'S', 'PHB', 'Player Hands Book', 'OFFICIAL', 2024);
12 changes: 12 additions & 0 deletions src/main/resources/scripts/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
INSERT INTO books (source_acronym, name, alt_name, english_name, description, type, year)
VALUES ('PHB', 'ПХБ', 'S', 'PHB', 'Player Hands Book', 'OFFICIAL', 2024);

INSERT INTO sources (id, created_at, updated_at, page, book_info_id) VALUES (1, '2024-11-07 20:10:00.731818', '2024-11-07 20:10:00.731818', 155, 'PHB');
INSERT INTO sources (id, created_at, updated_at, page, book_info_id) VALUES (2, '2024-11-07 20:10:00.808714', '2024-11-07 20:10:00.808714', 156, 'PHB');

INSERT INTO species (url, created_at, updated_at, alternative, description, english, image_url, is_hidden_entity, name, climb, dark_vision, fly, size, speed, swim, type, parent_id, source) VALUES ('assimar', '2024-11-07 20:10:00.839712', '2024-11-07 20:10:00.850710', 'Angel-blooded', 'Aasimar are mortals with celestial heritage. They have traits hinting at their divine ancestry, like glowing eyes or metallic freckles.', 'Aasimar', 'assimar/picture', false, 'Aasimar', 0, 60, 0, 'MEDIUM', 30, 0, 'HUMANOID', 'assimar', 1);
INSERT INTO species_features (url, created_at, updated_at, alternative, description, english, image_url, is_hidden_entity, name, feature_description, source, species_url) VALUES ('assimar/light-bearer', '2024-11-07 20:10:00.820711', '2024-11-07 20:10:00.847710', 'Light Carrier', 'You know the Light cantrip, allowing you to emit light to brighten your surroundings.', 'Light Bearer', 'assimar/picture', false, 'Light Bearer', 'This feature allows the aasimar to use the Light cantrip at will.', 2, 'assimar');

INSERT INTO entity_tags (entity_url, tag_value, tag_key) VALUES ('assimar/light-bearer', 'racial feature', 'aasimar');
INSERT INTO entity_tags (entity_url, tag_value, tag_key) VALUES ('assimar/light-bearer', 'illumination', 'light');
INSERT INTO entity_tags (entity_url, tag_value, tag_key) VALUES ('assimar/light-bearer', 'cantrip', 'magic');
Loading