Skip to content

Commit

Permalink
Merge branch 'dev' into feature/TTG-62-spell-scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Magistrus authored Feb 25, 2025
2 parents 5da9f4d + 8214795 commit c7a332a
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package club.ttg.dnd5.controller.character;

import club.ttg.dnd5.dto.character.BackgroundDto;
import club.ttg.dnd5.exception.EntityExistException;
import club.ttg.dnd5.exception.EntityNotFoundException;
import club.ttg.dnd5.service.character.BackgroundService;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
Expand All @@ -23,32 +25,41 @@ public BackgroundDto findBackground(@PathVariable final String backgroundUrl) {
return backgroundService.getBackground(backgroundUrl);
}

@ResponseStatus(HttpStatus.OK)
@RequestMapping(path = "/{backgroundUrl}", method = RequestMethod.OPTIONS)
public ResponseEntity<Boolean> existByUrl(@PathVariable final String backgroundUrl) {
if (backgroundService.existByUrl(backgroundUrl)) {
throw new EntityExistException();
@RequestMapping(path = "/{backgroundUrl}", method = RequestMethod.HEAD)
public boolean existByUrl(@PathVariable final String backgroundUrl) {
var exist = backgroundService.exists(backgroundUrl);
if (!exist) {
throw new EntityNotFoundException("URL предыстории не найден");
}
return ResponseEntity.ok(false);
return true;
}

@PostMapping("/search")
public Collection<BackgroundDto> findBackgrounds() {
return backgroundService.getBackgrounds();
}

@PostMapping()
@Secured("ADMIN")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public BackgroundDto addBackgrounds(@RequestBody final BackgroundDto backgroundDto) {
return backgroundService.addBackground(backgroundDto);
}

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Предыстория успешно обновлена"),
@ApiResponse(responseCode = "404", description = "Предыстория не найден"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@Secured("ADMIN")
@PutMapping("{backgroundUrl}")
public BackgroundDto updateBackgrounds(
@PathVariable final String backgroundUrl,
@RequestBody final BackgroundDto backgroundDto) {
return backgroundService.updateBackgrounds(backgroundUrl, backgroundDto);
}

@Secured("ADMIN")
@DeleteMapping("{backgroundUrl}")
public BackgroundDto deleteBackgrounds(
@PathVariable final String backgroundUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import club.ttg.dnd5.dto.character.ClassDto;
import club.ttg.dnd5.dto.character.ClassFeatureDto;
import club.ttg.dnd5.dto.engine.SearchRequest;
import club.ttg.dnd5.exception.EntityNotFoundException;
import club.ttg.dnd5.service.character.ClassService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
Expand All @@ -24,10 +24,24 @@
public class ClassController {
private final ClassService classService;

@Operation(summary = "Проверить класс по URL", description = "Проверка класса по его уникальному URL.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Класс существует"),
@ApiResponse(responseCode = "404", description = "Класс не существует")
})
@RequestMapping(path = "/{url}", method = RequestMethod.HEAD)
public Boolean isSpecieExist(@PathVariable String url) {
var exist = classService.exist(url);
if(!exist) {
throw new EntityNotFoundException("URL вида не существует");
}
return true;
}

@Operation(summary = "Получение краткого списка классов")
@ResponseStatus(HttpStatus.OK)
@PostMapping("/all")
public Collection<ClassDto> getAllClasses(@ParameterObject final SearchRequest request) {
@PostMapping("/search")
public Collection<ClassDto> getAllClasses(final SearchRequest request) {
return classService.getClasses(request);
}

Expand All @@ -42,19 +56,18 @@ public Collection<ClassDto> getSubclasses(@PathVariable String parentUrl) {
@ApiResponse(responseCode = "200", description = "Класс успешно получен"),
@ApiResponse(responseCode = "404", description = "Класс не найден")
})
@ResponseStatus(HttpStatus.OK)
@GetMapping("/{url}")
public ClassDto getClass(@PathVariable String url) {
return classService.getClass(url);
}

@Secured("ADMIN")
@Operation(summary = "Добавление класса или подкласса")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Класс успешно создан"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@ResponseStatus(HttpStatus.CREATED)
@Secured("ADMIN")
@PostMapping
public ClassDto addClass(@RequestBody final ClassDto request) {
return classService.addClass(request);
Expand All @@ -67,12 +80,12 @@ public ClassDto addClass(@RequestBody final ClassDto request) {
* @param classParentUrl URL родителя, который будет добавлен.
* @return информацией о виде.
*/
@Secured("ADMIN")
@Operation(summary = "Добавить родителя к классу", description = "Добавляет родителя к указанному классу по его URL.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Родитель успешно добавлен к классу"),
@ApiResponse(responseCode = "404", description = "Класс или родитель не найден")
})
@ResponseStatus(HttpStatus.OK)
@PostMapping("/{classUrl}/parent")
public ClassDto addParent(
@Parameter(description = "URL класса, к которому добавляется родитель") @PathVariable String classUrl,
Expand All @@ -87,26 +100,25 @@ public ClassDto addParent(
* @param featureDto умение, которое будет добавлено к классу.
* @return информацией о виде.
*/
@Secured("ADMIN")
@Operation(summary = "Добавить умение к классу", description = "Добавляет умение к указанному классу по его URL.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Умение успешно добавлен к классу"),
@ApiResponse(responseCode = "404", description = "Класс не найден")
})
@ResponseStatus(HttpStatus.OK)
@PostMapping("/{classUrl}/feature")
public ClassDto addFeature(
@Parameter(description = "URL класса, к которому добавляется умение") @PathVariable String classUrl,
@RequestBody ClassFeatureDto featureDto) {
return classService.addFeature(classUrl, featureDto);
}

@ResponseStatus(HttpStatus.OK)
@Secured("ADMIN")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Класс успешно обновлен"),
@ApiResponse(responseCode = "404", description = "Класс не найден"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@Secured("ADMIN")
@PutMapping("/{url}")
public ClassDto updateClass(
@PathVariable final String url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
Expand All @@ -21,6 +22,15 @@
public class FeatController {
private final FeatService featService;

@ResponseStatus(HttpStatus.OK)
@RequestMapping(path = "/{featUrl}", method = RequestMethod.HEAD)
public ResponseEntity<Boolean> existByUrl(@PathVariable final String featUrl) {
if (featService.exists(featUrl)) {
throw new EntityExistException();
}
return ResponseEntity.ok(false);
}

@Operation(summary = "Получение детального описания черты")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Черта успешно получена"),
Expand All @@ -33,15 +43,7 @@ public FeatDto getFeat(@PathVariable final String featUrl) {
return featService.getFeat(featUrl);
}

@ResponseStatus(HttpStatus.OK)
@RequestMapping(path = "/{featUrl}", method = RequestMethod.OPTIONS)
public ResponseEntity<Boolean> existByUrl(@PathVariable final String featUrl) {
if (featService.existByUrl(featUrl)) {
throw new EntityExistException();
}
return ResponseEntity.ok(false);
}

@Secured("ADMIN")
@Operation(summary = "Получение списка краткого описания черты")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Черты успешно получена")
Expand All @@ -52,6 +54,7 @@ public Collection<FeatDto> getFeats() {
return featService.getFeats();
}

@Secured("ADMIN")
@Operation(summary = "Добавление черты")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Черта успешно добавлена"),
Expand All @@ -64,6 +67,7 @@ public FeatDto addFeats(@RequestBody final FeatDto featDto) {
return featService.addFeat(featDto);
}

@Secured("ADMIN")
@Operation(summary = "Обновление черты")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Черта успешно обновлена"),
Expand All @@ -77,6 +81,7 @@ public FeatDto updateFeats(@PathVariable final String featUrl,
return featService.updateFeat(featUrl, featDto);
}

@Secured("ADMIN")
@Operation(summary = "Скрывает черту")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Черта удалена из общего списка"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import club.ttg.dnd5.dto.species.CreateSpeciesDto;
import club.ttg.dnd5.dto.species.SpeciesDto;
import club.ttg.dnd5.exception.EntityNotFoundException;
import club.ttg.dnd5.service.species.SpeciesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -10,7 +11,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

Expand All @@ -23,34 +23,26 @@
public class SpeciesController {
private final SpeciesService speciesService;

/**
* Проверка существования вида по URL.
*
* @param url URL вида.
* @return 204, если вида с таким URL не существует; 409, если вид существует.
*/
@Operation(
summary = "Проверка существования вида",
description = "Возвращает 204 (No Content), если вида с указанным URL не существует, или 409 (Conflict), если вид существует."
)
@Operation(summary = "Проверить вид по URL", description = "Проверка вида по его уникальному URL.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Вид с указанным URL не найден."),
@ApiResponse(responseCode = "409", description = "Вид с указанным URL уже существует.")
@ApiResponse(responseCode = "200", description = "Вид существует"),
@ApiResponse(responseCode = "404", description = "Вид не существует")
})
@RequestMapping(value = "/{url}", method = RequestMethod.OPTIONS)
public ResponseEntity<Void> handleOptions(@PathVariable("url") String url) {
boolean exists = speciesService.speciesExistsByUrl(url);
if (exists) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
} else {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
@RequestMapping(path = "/{url}", method = RequestMethod.HEAD)
public Boolean isSpecieExist(@PathVariable String url) {
var exist = speciesService.exists(url);
if(!exist) {
throw new EntityNotFoundException("URL вида не существует");
}
else {
return true;
}
}

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

@Operation(summary = "Получить вид по URL", description = "Получение вида по его уникальному URL.")
Expand All @@ -64,38 +56,20 @@ public SpeciesDto getSpeciesByUrl(@PathVariable String url) {
return speciesService.findById(url);
}

@Operation(summary = "Проверить вид по URL", description = "Проверка вида по его уникальному URL.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Вид успешно получен"),
@ApiResponse(responseCode = "409", description = "Вид не найден")
})
@RequestMapping(path = "/{url}", method = RequestMethod.HEAD)
public ResponseEntity<?> isSpecieExist(@PathVariable String url) {
Boolean exist = speciesService.isExist(url);

if (exist.equals(Boolean.TRUE)) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}

return ResponseEntity.noContent().build();
}

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

@GetMapping("/related")
@Operation(summary = "Получить все связанные виды по URL подвида",
description = "Возвращает список всех связанных видов, включая родительский вид и подвиды по указанному URL подвида.")
public ResponseEntity<List<SpeciesDto>> getAllRelatedSpeciesBySubSpeciesUrl(
public List<SpeciesDto> getAllRelatedSpeciesBySubSpeciesUrl(
@Parameter(description = "URL подвига", required = true) @RequestParam String subSpeciesUrl) {
List<SpeciesDto> relatedSpeciesRespons = speciesService.getAllRelatedSpeciesBySubSpeciesUrl(subSpeciesUrl);
return ResponseEntity.ok(relatedSpeciesRespons);
return speciesService.getAllRelatedSpeciesBySubSpeciesUrl(subSpeciesUrl);
}

/**
Expand All @@ -111,11 +85,10 @@ public ResponseEntity<List<SpeciesDto>> getAllRelatedSpeciesBySubSpeciesUrl(
@ApiResponse(responseCode = "404", description = "Вид или родитель не найден")
})
@PostMapping("/parent")
public ResponseEntity<SpeciesDto> addParent(
public SpeciesDto addParent(
@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);
return speciesService.addParent(speciesUrl, speciesParentUrl);
}

/**
Expand All @@ -131,20 +104,19 @@ public ResponseEntity<SpeciesDto> addParent(
@ApiResponse(responseCode = "404", description = "Вид не найден")
})
@PostMapping("/subspecies")
public ResponseEntity<SpeciesDto> addSubSpecies(
public SpeciesDto addSubSpecies(
@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);
return speciesService.addSubSpecies(speciesUrl, subSpeciesUrls);
}

@Secured("ADMIN")
@Operation(summary = "Создать новый вид", description = "Создание нового вида в системе.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Вид успешно создан"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@PostMapping("/new")
@Secured("ADMIN")
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public SpeciesDto createSpecies(@RequestBody CreateSpeciesDto createSpeciesDTO) {
return speciesService.save(createSpeciesDTO);
Expand Down
Loading

0 comments on commit c7a332a

Please sign in to comment.