From 21bc1ff11c8102e7a9d8c46b96f1dd65be78860b Mon Sep 17 00:00:00 2001 From: svifty7 Date: Fri, 15 Nov 2024 19:39:27 +0300 Subject: [PATCH] feat: update species controller --- .../controller/species/SpeciesController.java | 52 +++++++++---------- src/main/resources/scripts/setup.sql | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/club/ttg/dnd5/controller/species/SpeciesController.java b/src/main/java/club/ttg/dnd5/controller/species/SpeciesController.java index 84cc5db2..c1598f08 100644 --- a/src/main/java/club/ttg/dnd5/controller/species/SpeciesController.java +++ b/src/main/java/club/ttg/dnd5/controller/species/SpeciesController.java @@ -23,26 +23,37 @@ public class SpeciesController { private final SpeciesService speciesService; - @PostMapping("/all") + @PostMapping("/search") @Operation(summary = "Получение всех видов", description = "Виды будут не детальные, будет возвращать списков с указанным имени и урл") public ResponseEntity> getAllSpecies() { return ResponseEntity.ok(speciesService.getAllSpecies()); } - @GetMapping("/{parentUrl}/subspecies") + @Operation(summary = "Получить вид по URL", description = "Получение вида по его уникальному URL.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Вид успешно получен"), + @ApiResponse(responseCode = "404", description = "Вид не найден") + }) + @GetMapping("/{url}") + @ResponseStatus(HttpStatus.OK) + public SpeciesDto getSpeciesByUrl(@PathVariable String url) { + return speciesService.findById(url); + } + + @GetMapping("/subspecies") @Operation(summary = "Получить подвиды по URL родительского вида", description = "Возвращает список подвидов, связанных с указанным родительским видом по его URL.") public ResponseEntity> getSubSpeciesByParentUrl( - @Parameter(description = "URL родительского вида", required = true) @PathVariable String parentUrl) { + @Parameter(description = "URL родительского вида", required = true) @RequestParam String parentUrl) { List subSpeciesDto = speciesService.getSubSpeciesByParentUrl(parentUrl); return ResponseEntity.ok(subSpeciesDto); } - @GetMapping("/subspecies/{subSpeciesUrl}/related") + @GetMapping("/related") @Operation(summary = "Получить все связанные виды по URL подвида", description = "Возвращает список всех связанных видов, включая родительский вид и подвиды по указанному URL подвида.") public ResponseEntity> getAllRelatedSpeciesBySubSpeciesUrl( - @Parameter(description = "URL подвига", required = true) @PathVariable String subSpeciesUrl) { + @Parameter(description = "URL подвига", required = true) @RequestParam String subSpeciesUrl) { List relatedSpeciesRespons = speciesService.getAllRelatedSpeciesBySubSpeciesUrl(subSpeciesUrl); return ResponseEntity.ok(relatedSpeciesRespons); } @@ -59,10 +70,10 @@ public ResponseEntity> getAllRelatedSpeciesBySubSpeciesUrl( @ApiResponse(responseCode = "200", description = "Родитель успешно добавлен к виду"), @ApiResponse(responseCode = "404", description = "Вид или родитель не найден") }) - @PostMapping("/{speciesUrl}/parent") + @PostMapping("/parent") public ResponseEntity addParent( - @Parameter(description = "URL вида, к которому добавляется родитель") @PathVariable String speciesUrl, - @Parameter(description = "URL родителя, который будет добавлен") @RequestParam String speciesParentUrl) { + @Parameter(description = "URL вида, к которому добавляется родитель", required = true) @RequestParam String speciesUrl, + @Parameter(description = "URL родителя, который будет добавлен", required = true) @RequestParam String speciesParentUrl) { SpeciesDto response = speciesService.addParent(speciesUrl, speciesParentUrl); return ResponseEntity.ok(response); } @@ -79,31 +90,20 @@ public ResponseEntity addParent( @ApiResponse(responseCode = "200", description = "Подвиды успешно добавлены к виду"), @ApiResponse(responseCode = "404", description = "Вид не найден") }) - @PostMapping("/{speciesUrl}/subspecies") + @PostMapping("/subspecies") public ResponseEntity addSubSpecies( - @Parameter(description = "URL вида, к которому добавляются подвиды") @PathVariable String speciesUrl, - @Parameter(description = "Список URL подвидов, которые будут добавлены") @RequestBody List subSpeciesUrls) { + @Parameter(description = "URL вида, к которому добавляются подвиды", required = true) @RequestParam String speciesUrl, + @Parameter(description = "Список URL подвидов, которые будут добавлены", required = true) @RequestBody List subSpeciesUrls) { SpeciesDto response = speciesService.addSubSpecies(speciesUrl, subSpeciesUrls); return ResponseEntity.ok(response); } - @Operation(summary = "Получить вид по URL", description = "Получение вида по его уникальному URL.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Вид успешно получен"), - @ApiResponse(responseCode = "404", description = "Вид не найден") - }) - @GetMapping("/{url}") - @ResponseStatus(HttpStatus.OK) - public SpeciesDto getSpeciesByUrl(@PathVariable String url) { - return speciesService.findById(url); - } - @Operation(summary = "Создать новый вид", description = "Создание нового вида в системе.") @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "Вид успешно создан"), @ApiResponse(responseCode = "403", description = "Доступ запрещен") }) - @PostMapping + @PostMapping("/new") @Secured("ROLE_ADMIN") @ResponseStatus(HttpStatus.CREATED) public SpeciesDto createSpecies(@RequestBody CreateSpeciesDto createSpeciesDTO) { @@ -116,10 +116,10 @@ public SpeciesDto createSpecies(@RequestBody CreateSpeciesDto createSpeciesDTO) @ApiResponse(responseCode = "404", description = "Вид не найден"), @ApiResponse(responseCode = "403", description = "Доступ запрещен") }) - @PutMapping("/{oldUrl}") + @PutMapping("/{url}") @Secured("ROLE_ADMIN") @ResponseStatus(HttpStatus.OK) - public SpeciesDto updateSpecies(@PathVariable String oldUrl, @RequestBody SpeciesDto speciesDTO) { - return speciesService.update(oldUrl, speciesDTO); + public SpeciesDto updateSpecies(@PathVariable String url, @RequestBody SpeciesDto speciesDTO) { + return speciesService.update(url, speciesDTO); } } diff --git a/src/main/resources/scripts/setup.sql b/src/main/resources/scripts/setup.sql index 4d2368ff..73f69ecc 100644 --- a/src/main/resources/scripts/setup.sql +++ b/src/main/resources/scripts/setup.sql @@ -17,7 +17,7 @@ INSERT INTO ttg.species (climb, dark_vision, fly, is_hidden_entity, speed, swim, INSERT INTO ttg.species (climb, dark_vision, fly, is_hidden_entity, speed, swim, created_at, source, updated_at, alternative, description, english, image_url, name, parent_id, url, size, type) VALUES (0, 60, 0, false, 30, 0, '2024-11-11 22:22:20.776619', 7, '2024-11-11 22:22:40.628185', 'Tinker Gnome', 'Горные гномы – изобретательные создания, способные создавать крошечные механические устройства.', 'Rock Gnome', 'gnome/rock/picture', 'Горный Гном', 'gnome', 'rock-gnome', 'SMALL', 'HUMANOID'); INSERT INTO ttg.species_features (is_hidden_entity, created_at, source, updated_at, alternative, description, english, feature_description, image_url, name, species_url, url) VALUES (false, '2024-11-11 22:17:31.805949', 4, '2024-11-11 22:17:31.836948', null, 'Преимущество на спасброски Интеллекта, Мудрости и Харизмы.', 'Gnomish Cunning', 'Гномы обладают хитростью, позволяющей им противостоять ментальным эффектам.', null, 'Гномья Хитрость', 'gnome', 'gnome/gnomish-cunning'); -INSERT INTO ttg.species_features (is_hidden_entity, created_at, source, updated_at, alternative, description, english, feature_description, image_url, name, species_url, url) VALUES (false, '2024-11-11 22:22:20.771620', 8, '2024-11-11 22:22:20.777618', null, 'Вы получаете удвоенное мастерство при проверке Истории, касающейся магических, алхимических или технологических объектов.', 'Artificer\'s Lore', 'Горные гномы хорошо разбираются в магических и технологических предметах.', null, 'Артифициерские знания', 'rock-gnome', 'rock-gnome/artificer-lore'); +INSERT INTO ttg.species_features (is_hidden_entity, created_at, source, updated_at, alternative, description, english, feature_description, image_url, name, species_url, url) VALUES (false, '2024-11-11 22:22:20.771620', 8, '2024-11-11 22:22:20.777618', null, 'Вы получаете удвоенное мастерство при проверке Истории, касающейся магических, алхимических или технологических объектов.', 'Artificer''s Lore', 'Горные гномы хорошо разбираются в магических и технологических предметах.', null, 'Артифициерские знания', 'rock-gnome', 'rock-gnome/artificer-lore'); INSERT INTO ttg.species_features (is_hidden_entity, created_at, source, updated_at, alternative, description, english, feature_description, image_url, name, species_url, url) VALUES (false, '2024-11-07 20:10:00.820711', 2, '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', 'This feature allows the aasimar to use the Light cantrip at will.', 'assimar/picture', 'Light Bearer', 'assimar', 'assimar/light-bearer'); INSERT INTO ttg.species_features (is_hidden_entity, created_at, source, updated_at, alternative, description, english, feature_description, image_url, name, species_url, url) VALUES (false, '2024-11-11 22:17:41.468761', 6, '2024-11-11 22:17:41.471761', null, 'Вы знаете заговор Малая Иллюзия.', 'Natural Illusionist', 'Лесные гномы умеют использовать Малую Иллюзию для маскировки и защиты.', null, 'Природный Иллюзионист', 'forest-gnome', 'forest-gnome/natural-illusionist'); INSERT INTO ttg.species_features (is_hidden_entity, created_at, source, updated_at, alternative, description, english, feature_description, image_url, name, species_url, url) VALUES (false, '2024-11-11 22:22:20.773619', 9, '2024-11-11 22:22:20.777618', null, 'Вы можете создавать небольшие механические устройства, такие как игрушка или музыкальная шкатулка.', 'Tinker', 'Горные гномы могут создавать механические устройства для различных целей.', null, 'Изобретатель', 'rock-gnome', 'rock-gnome/tinker');