diff --git a/src/main/java/club/ttg/dnd5/dto/base/HasSourceDTO.java b/src/main/java/club/ttg/dnd5/dto/base/HasSourceDTO.java deleted file mode 100644 index 9553b0a4..00000000 --- a/src/main/java/club/ttg/dnd5/dto/base/HasSourceDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package club.ttg.dnd5.dto.base; - - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -/** - * Интерфейс `HasSourceDTO` определяет контракт для объектов, которые ссылаются на источник - * (например, книгу правил или справочные материалы) и конкретную страницу в этом источнике. - * - * В данном контексте термин "source" обычно представлен акронимом, например: - * - "PHB" (Player's Handbook — Книга игрока) - * - "DMG" (Dungeon Master's Guide — Руководство мастера подземелий) - * и т.д. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public interface HasSourceDTO { - String getSource(); - Short getPage(); - void setPage(Short page); - void setSource(String source); -} diff --git a/src/main/java/club/ttg/dnd5/dto/base/SourceResponse.java b/src/main/java/club/ttg/dnd5/dto/base/SourceResponse.java index 7e3826c0..a20b776c 100644 --- a/src/main/java/club/ttg/dnd5/dto/base/SourceResponse.java +++ b/src/main/java/club/ttg/dnd5/dto/base/SourceResponse.java @@ -14,18 +14,9 @@ @AllArgsConstructor @NoArgsConstructor @JsonRootName("source") -public class SourceResponse implements HasSourceDTO { +public class SourceResponse { private NameBasedDTO name = new NameBasedDTO(); private Short page; - @Override - public String getSource() { - return name.getShortName(); - } - - @Override - public void setSource(String sourceArcronym) { - this.name.setShortName(sourceArcronym); - } private boolean homebrew = false; private boolean thirdParty = false; } \ No newline at end of file diff --git a/src/main/java/club/ttg/dnd5/dto/species/CreateSpeciesDto.java b/src/main/java/club/ttg/dnd5/dto/species/CreateSpeciesDto.java index abc33c32..24d51afc 100644 --- a/src/main/java/club/ttg/dnd5/dto/species/CreateSpeciesDto.java +++ b/src/main/java/club/ttg/dnd5/dto/species/CreateSpeciesDto.java @@ -1,8 +1,6 @@ package club.ttg.dnd5.dto.species; import club.ttg.dnd5.dto.base.BaseDTO; -import club.ttg.dnd5.dto.base.HasSourceDTO; -import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -15,29 +13,7 @@ @Setter @AllArgsConstructor @RequiredArgsConstructor -public class CreateSpeciesDto extends BaseDTO implements HasSourceDTO { +public class CreateSpeciesDto extends BaseDTO { private CreaturePropertiesDto creatureProperties = new CreaturePropertiesDto(); private Collection features = new ArrayList<>(); - - @JsonIgnore - @Override - public Short getPage() { - return (this.getSource() != null) ? this.getSourceDTO().getPage() : -1; - } - - @Override - public void setPage(Short page) { - this.getSourceDTO().setPage(page); - } - - @JsonIgnore - @Override - public String getSource() { - return this.getSourceDTO().getSource(); - } - - @Override - public void setSource(String source) { - this.getSourceDTO().setSource(source); - } } diff --git a/src/main/java/club/ttg/dnd5/dto/species/SpeciesDto.java b/src/main/java/club/ttg/dnd5/dto/species/SpeciesDto.java index 629a3dc8..b2416255 100644 --- a/src/main/java/club/ttg/dnd5/dto/species/SpeciesDto.java +++ b/src/main/java/club/ttg/dnd5/dto/species/SpeciesDto.java @@ -2,7 +2,6 @@ import club.ttg.dnd5.dto.base.BaseDTO; import club.ttg.dnd5.dto.base.DetailableDTO; -import club.ttg.dnd5.dto.base.HasSourceDTO; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; @@ -18,7 +17,7 @@ @Setter @AllArgsConstructor @RequiredArgsConstructor -public class SpeciesDto extends BaseDTO implements DetailableDTO, HasSourceDTO{ +public class SpeciesDto extends BaseDTO implements DetailableDTO{ // Включаем свойства существа через DTO private CreaturePropertiesDto creatureProperties = new CreaturePropertiesDto(); // Связанные сущности @@ -37,25 +36,5 @@ public void hideDetails() { this.features = null; } } - - @Override - public String getSource() { - return this.getSourceDTO().getSource(); - } - - @Override - public Short getPage() { - return this.getSourceDTO().getPage(); - } - - @Override - public void setPage(Short page) { - this.getSourceDTO().setPage(page); - } - - @Override - public void setSource(String source) { - this.getSourceDTO().setSource(source); - } } diff --git a/src/main/java/club/ttg/dnd5/dto/species/SpeciesFeatureDto.java b/src/main/java/club/ttg/dnd5/dto/species/SpeciesFeatureDto.java index 29f4bce2..54b72379 100644 --- a/src/main/java/club/ttg/dnd5/dto/species/SpeciesFeatureDto.java +++ b/src/main/java/club/ttg/dnd5/dto/species/SpeciesFeatureDto.java @@ -1,7 +1,6 @@ package club.ttg.dnd5.dto.species; import club.ttg.dnd5.dto.base.BaseDTO; -import club.ttg.dnd5.dto.base.HasSourceDTO; import club.ttg.dnd5.dto.base.TagDto; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -14,27 +13,7 @@ @JsonInclude(JsonInclude.Include.NON_NULL) @Getter @Setter -public class SpeciesFeatureDto extends BaseDTO implements HasSourceDTO { +public class SpeciesFeatureDto extends BaseDTO { @JsonProperty("tags") private Collection tags = new ArrayList<>(); - - @Override - public String getSource() { - return this.getSourceDTO().getSource(); - } - - @Override - public Short getPage() { - return this.getSourceDTO().getPage(); - } - - @Override - public void setPage(Short page) { - this.getSourceDTO().setPage(page); - } - - @Override - public void setSource(String source) { - this.getSourceDTO().setSource(source); - } } \ No newline at end of file diff --git a/src/main/java/club/ttg/dnd5/service/species/SpeciesService.java b/src/main/java/club/ttg/dnd5/service/species/SpeciesService.java index 06335b94..771cb7e4 100644 --- a/src/main/java/club/ttg/dnd5/service/species/SpeciesService.java +++ b/src/main/java/club/ttg/dnd5/service/species/SpeciesService.java @@ -52,7 +52,7 @@ public SpeciesDto save(CreateSpeciesDto createSpeciesDTO) { Species species = new Species(); Converter.MAP_BASE_DTO_TO_ENTITY_NAME.apply(createSpeciesDTO, species); Converter.MAP_CREATURE_PROPERTIES_DTO_TO_ENTITY.apply(createSpeciesDTO.getCreatureProperties(), species); - Converter.MAP_DTO_SOURCE_TO_ENTITY_SOURCE.apply(createSpeciesDTO, species); + Converter.MAP_DTO_SOURCE_TO_ENTITY_SOURCE.apply(createSpeciesDTO.getSourceDTO(), species); validateAndSaveSource(species.getSource()); saveSpeciesFeatures(createSpeciesDTO, species); diff --git a/src/main/java/club/ttg/dnd5/utills/Converter.java b/src/main/java/club/ttg/dnd5/utills/Converter.java index 9621abb2..d09d18e9 100644 --- a/src/main/java/club/ttg/dnd5/utills/Converter.java +++ b/src/main/java/club/ttg/dnd5/utills/Converter.java @@ -2,8 +2,8 @@ import club.ttg.dnd5.dto.base.BaseDTO; import club.ttg.dnd5.dto.base.DetailableDTO; -import club.ttg.dnd5.dto.base.HasSourceDTO; import club.ttg.dnd5.dto.base.NameBasedDTO; +import club.ttg.dnd5.dto.base.SourceResponse; import club.ttg.dnd5.dto.species.CreaturePropertiesDto; import club.ttg.dnd5.dto.species.MovementAttributes; import club.ttg.dnd5.model.base.CreatureProperties; @@ -73,8 +73,8 @@ public class Converter { }; // Function to map DTO Source to Entity Source - public static final BiFunction MAP_DTO_SOURCE_TO_ENTITY_SOURCE = (dto, entity) -> { - String sourceAcronym = dto.getSource(); + public static final BiFunction MAP_DTO_SOURCE_TO_ENTITY_SOURCE = (dto, entity) -> { + String sourceAcronym = dto.getName().getShortName(); Source source = entity.getSource(); if (source == null) { source = new Source(); @@ -90,10 +90,19 @@ public class Converter { }; // Function to map Entity Source to DTO Source - public static final BiFunction MAP_ENTITY_SOURCE_TO_DTO_SOURCE = (dto, entity) -> { - if (entity.getSource() != null) { - dto.setSource(entity.getSource().getSourceAcronym()); - dto.setPage(entity.getSource().getPage()); + public static final BiFunction MAP_ENTITY_SOURCE_TO_DTO_SOURCE = (dto, entity) -> { + Source source = entity.getSource(); + if (source != null) { + NameBasedDTO name = new NameBasedDTO(); + Book bookInfo = source.getBookInfo(); + if (bookInfo != null) { + name.setEnglish(bookInfo.getEnglishName()); + name.setName(bookInfo.getName()); + name.setShortName(bookInfo.getSourceAcronym()); + name.setAlternative(bookInfo.getAltName()); + } + dto.setName(name); + dto.setPage(source.getPage()); } return dto; }; diff --git a/src/main/java/club/ttg/dnd5/utills/species/SpeciesFeatureConverter.java b/src/main/java/club/ttg/dnd5/utills/species/SpeciesFeatureConverter.java index 35844dcb..3c4dea08 100644 --- a/src/main/java/club/ttg/dnd5/utills/species/SpeciesFeatureConverter.java +++ b/src/main/java/club/ttg/dnd5/utills/species/SpeciesFeatureConverter.java @@ -19,7 +19,7 @@ public class SpeciesFeatureConverter { private static final BiFunction DTO_TO_ENTITY_CONVERTER = (response, speciesFeature) -> { Converter.MAP_BASE_DTO_TO_ENTITY_NAME.apply(response, speciesFeature); - Converter.MAP_DTO_SOURCE_TO_ENTITY_SOURCE.apply(response, speciesFeature); + Converter.MAP_DTO_SOURCE_TO_ENTITY_SOURCE.apply(response.getSourceDTO(), speciesFeature); // Convert tags from TagDto to Map Map tags = response.getTags().stream() @@ -34,7 +34,7 @@ public class SpeciesFeatureConverter { private static final BiFunction ENTITY_TO_DTO_CONVERTER = (feature, dto) -> { Converter.MAP_ENTITY_TO_BASE_DTO.apply(dto, feature); - Converter.MAP_ENTITY_SOURCE_TO_DTO_SOURCE.apply(dto, feature); + Converter.MAP_ENTITY_SOURCE_TO_DTO_SOURCE.apply(dto.getSourceDTO(), feature); // Convert tags from Map to a collection of TagDto Collection tags = feature.getTags().entrySet().stream() diff --git a/src/main/resources/json/request/species/post/create_gnome_forest_child_request.json b/src/main/resources/json/request/species/post/create_gnome_forest_child_request.json index e8f30122..0f1d6844 100644 --- a/src/main/resources/json/request/species/post/create_gnome_forest_child_request.json +++ b/src/main/resources/json/request/species/post/create_gnome_forest_child_request.json @@ -1,54 +1,67 @@ { "url": "forest-gnome", - "imageUrl": "gnome/forest/picture", + "imageUrl": "gnome/forest/picture.webp", "description": "Лесные гномы живут в лесах и наделены магией иллюзий, чтобы защищаться и выживать.", - "name": { - "name": "Лесной Гном", - "english": "Forest Gnome", - "alternative": "Woodland Trickster" - }, - "sourceDTO": { - "source": "PHB", - "page": 181 - }, "creatureProperties": { - "size": "SMALL", + "size": "MEDIUM", "type": "HUMANOID", - "speed": 30, - "fly": 0, - "climb": 0, - "swim": 0, "darkVision": 60, - "sourceResponse": { - "source": "PHB", - "page": 181 + "speed": { + "base": 30, + "fly": 0, + "climb": 0, + "swim": 0 } }, - "parentUrl": "gnome", - "subSpeciesUrls": [], "features": [ { "url": "forest-gnome/natural-illusionist", - "imageUrl": null, + "imageUrl": "gnome/forest/natural-illusionist.webp", "description": "Лесные гномы умеют использовать Малую Иллюзию для маскировки и защиты. Вы знаете заговор Малая Иллюзия.", "name": { - "name": "Природный Иллюзионист", - "english": "Natural Illusionist", - "alternative": null + "rus": "Природный Иллюзионист", + "eng": "Natural Illusionist", + "alt": "Woodland Trickster", + "short": "PHB" }, - "sourceDTO": { - "source": "PHB", - "page": 181 + "source": { + "name": { + "rus": "Книга игрока", + "eng": "Player's Handbook", + "alt": "PHB", + "short": "PHB" + }, + "page": 181, + "homebrew": true, + "thirdParty": true }, - "tags": { - "magic": "illusion", - "gnome": "racial feature" - }, - "source": "PHB", - "page": 181 + "tags": [ + { + "name": "magic", + "value": "resistance" + }, + { + "name": "gnome", + "value": "racial feature" + } + ] } ], - "source": "PHB", - "detail": true, - "page": 181 -} + "name": { + "rus": "Лесной Гном", + "eng": "Forest Gnome", + "alt": "Woodland Trickster", + "short": "PHB" + }, + "source": { + "name": { + "rus": "Книга игрока", + "eng": "Player's Handbook", + "alt": "PHB", + "short": "PHB" + }, + "page": 181, + "homebrew": true, + "thirdParty": true + } +} \ No newline at end of file diff --git a/src/main/tests/club/ttg/dnd5/utills/ConverterTest.java b/src/main/tests/club/ttg/dnd5/utills/ConverterTest.java index 3db9b8de..746a7063 100644 --- a/src/main/tests/club/ttg/dnd5/utills/ConverterTest.java +++ b/src/main/tests/club/ttg/dnd5/utills/ConverterTest.java @@ -3,7 +3,6 @@ import club.ttg.dnd5.dictionary.Size; import club.ttg.dnd5.dictionary.beastiary.CreatureType; import club.ttg.dnd5.dto.base.BaseDTO; -import club.ttg.dnd5.dto.base.HasSourceDTO; import club.ttg.dnd5.dto.base.NameBasedDTO; import club.ttg.dnd5.dto.base.SourceResponse; import club.ttg.dnd5.dto.species.CreateSpeciesDto; @@ -75,9 +74,11 @@ public void setUp() { creatureProperties.setDarkVision(60); SourceResponse sourceResponse = new SourceResponse(); - sourceResponse.setSource("PHB"); + NameBasedDTO nameBasedDTO1 = new NameBasedDTO("Книга игрока", "Player HandBook", "", "PHB"); + sourceResponse.setName(nameBasedDTO1); sourceResponse.setPage((short) 155); speciesDTO = new SpeciesDto(); + sourceResponse.setName(nameBasedDTO1); speciesDTO.setSourceDTO(sourceResponse); source = new Source(); @@ -143,20 +144,20 @@ public void testMapEntityToCreaturePropertiesDTO() { @Test public void testMapDtoSourceToEntitySource() { Species species = new Species(); - Converter.MAP_DTO_SOURCE_TO_ENTITY_SOURCE.apply(speciesDTO, species); + Converter.MAP_DTO_SOURCE_TO_ENTITY_SOURCE.apply(speciesDTO.getSourceDTO(), species); assertEquals((Short) species.getSource().getPage(), speciesDTO.getSourceDTO().getPage()); - assertEquals(species.getSource().getBookInfo().getSourceAcronym(), speciesDTO.getSourceDTO().getSource()); + assertEquals(species.getSource().getBookInfo().getSourceAcronym(), speciesDTO.getSourceDTO().getName().getShortName()); } @Test public void testMapEntitySourceToDtoSource() { Species species = new Species(); species.setSource(source); - HasSourceDTO apply = Converter.MAP_ENTITY_SOURCE_TO_DTO_SOURCE.apply(speciesDTO, species); + SourceResponse apply = Converter.MAP_ENTITY_SOURCE_TO_DTO_SOURCE.apply(speciesDTO.getSourceDTO(), species); assertEquals((Short) species.getSource().getPage(), apply.getPage()); - assertEquals(species.getSource().getBookInfo().getSourceAcronym(), apply.getSource()); + assertEquals(species.getSource().getBookInfo().getSourceAcronym(), apply.getName().getShortName()); } @Test