Skip to content

Commit

Permalink
Merge pull request #32 from TTG-Club/feat/update-species
Browse files Browse the repository at this point in the history
  • Loading branch information
svifty7 authored Nov 16, 2024
2 parents 276c9e5 + 7aedab6 commit aade951
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,37 @@
public class SpeciesController {
private final SpeciesService speciesService;

@PostMapping("/all")
@PostMapping("/search")
@Operation(summary = "Получение всех видов", description = "Виды будут не детальные, будет возвращать списков с указанным имени и урл")
public ResponseEntity<List<SpeciesDto>> 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<List<SpeciesDto>> getSubSpeciesByParentUrl(
@Parameter(description = "URL родительского вида", required = true) @PathVariable String parentUrl) {
@Parameter(description = "URL родительского вида", required = true) @RequestParam String parentUrl) {
List<SpeciesDto> subSpeciesDto = speciesService.getSubSpeciesByParentUrl(parentUrl);
return ResponseEntity.ok(subSpeciesDto);
}

@GetMapping("/subspecies/{subSpeciesUrl}/related")
@GetMapping("/related")
@Operation(summary = "Получить все связанные виды по URL подвида",
description = "Возвращает список всех связанных видов, включая родительский вид и подвиды по указанному URL подвида.")
public ResponseEntity<List<SpeciesDto>> getAllRelatedSpeciesBySubSpeciesUrl(
@Parameter(description = "URL подвига", required = true) @PathVariable String subSpeciesUrl) {
@Parameter(description = "URL подвига", required = true) @RequestParam String subSpeciesUrl) {
List<SpeciesDto> relatedSpeciesRespons = speciesService.getAllRelatedSpeciesBySubSpeciesUrl(subSpeciesUrl);
return ResponseEntity.ok(relatedSpeciesRespons);
}
Expand All @@ -59,10 +70,10 @@ public ResponseEntity<List<SpeciesDto>> getAllRelatedSpeciesBySubSpeciesUrl(
@ApiResponse(responseCode = "200", description = "Родитель успешно добавлен к виду"),
@ApiResponse(responseCode = "404", description = "Вид или родитель не найден")
})
@PostMapping("/{speciesUrl}/parent")
@PostMapping("/parent")
public ResponseEntity<SpeciesDto> 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);
}
Expand All @@ -79,31 +90,20 @@ public ResponseEntity<SpeciesDto> addParent(
@ApiResponse(responseCode = "200", description = "Подвиды успешно добавлены к виду"),
@ApiResponse(responseCode = "404", description = "Вид не найден")
})
@PostMapping("/{speciesUrl}/subspecies")
@PostMapping("/subspecies")
public ResponseEntity<SpeciesDto> addSubSpecies(
@Parameter(description = "URL вида, к которому добавляются подвиды") @PathVariable String speciesUrl,
@Parameter(description = "Список URL подвидов, которые будут добавлены") @RequestBody List<String> subSpeciesUrls) {
@Parameter(description = "URL вида, к которому добавляются подвиды", required = true) @RequestParam String speciesUrl,
@Parameter(description = "Список URL подвидов, которые будут добавлены", required = true) @RequestBody List<String> 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) {
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/scripts/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit aade951

Please sign in to comment.