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

Обновление справочников #46

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package club.ttg.dnd5.controller.tools.dictionary;

import club.ttg.dnd5.dto.base.ValueDto;
import club.ttg.dnd5.dto.select.DiceSelectOptionDto;
import club.ttg.dnd5.dto.select.SelectOptionDto;
import club.ttg.dnd5.dto.select.SpellcasterSelectOptionDto;
import club.ttg.dnd5.service.base.DirectoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
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.web.bind.annotation.GetMapping;
Expand All @@ -16,68 +22,294 @@
*/
@RequiredArgsConstructor
@Tag(name = "Справочники", description = "API для различных справочников")
@RequestMapping("/api/v2/directory/")
@RequestMapping("/api/v2/directory")
@RestController
public class DirectoryController {
private final DirectoryService directoryService;

@Operation(summary = "Дайсы")
@GetMapping("/dices")
public Collection<ValueDto> getDices() {
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "к4",
"value": "d4",
"maxValue": 4
},
{
"label": "к6",
"value": "d6",
"maxValue": 6
},
{
"label": "к8",
"value": "d8",
"maxValue": 8
}
]
""")
)
)
}
)
public Collection<DiceSelectOptionDto> getDices() {
return directoryService.getDices();
}

@Operation(summary = "Типы существ")
@GetMapping("/beast/types")
public Collection<ValueDto> getCreatureCategories() {
@GetMapping("/creature/types")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "Аберрация",
"value": "ABERRATION"
},
{
"label": "Зверь",
"value": "BEAST"
},
{
"label": "Небожитель",
"value": "CELESTIAL"
}
]
""")
)
)
}
)
public Collection<SelectOptionDto> getCreatureCategories() {
return directoryService.getCreatureCategories();
}


@Operation(summary = "Размеры существ")
@GetMapping("/sizes")
public Collection<ValueDto> getCreatureSizes() {
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "Маленький",
"value": "SMALL"
},
{
"label": "Средний",
"value": "MEDIUM"
},
{
"label": "Большой",
"value": "LARGE"
}
]
""")
)
)
}
)
public Collection<SelectOptionDto> getCreatureSizes() {
return directoryService.getCreatureSizes();
}

@Operation(summary = "Типы урона")
@GetMapping("/damage/types")
public Collection<ValueDto> getDamageTypes() {
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "огонь",
"value": "FAIR"
},
{
"label": "холод",
"value": "COLD"
},
{
"label": "электричество",
"value": "LIGHTNING"
}
]
""")
)
)
}
)
public Collection<SelectOptionDto> getDamageTypes() {
return directoryService.getDamageTypes();
}

@Operation(summary = "Состояния")
@GetMapping("/conditions")
public Collection<ValueDto> getConditions() {
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "ослепление",
"value": "BLINDED"
},
{
"label": "очарование",
"value": "CHARMED"
},
{
"label": "смерть",
"value": "DYING"
}
]
""")
)
)
}
)
public Collection<SelectOptionDto> getConditions() {
return directoryService.getConditions();
}

@Operation(summary = "Мировоззрение")
@GetMapping("/alignments")
public Collection<ValueDto> getAlignments() {
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "законно-добрый",
"value": "LAWFUL_GOOD"
},
{
"label": "законно-нейтральный",
"value": "LAWFUL_NEUTRAL"
},
{
"label": "законно-злой",
"value": "LAWFUL_EVIL"
}
]
""")
)
)
}
)
public Collection<SelectOptionDto> getAlignments() {
return directoryService.getAlignments();
}

@Operation(summary = "Места обитания существ")
@GetMapping("/environments")
public Collection<ValueDto> getEnvironments() {
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "полярная тундра",
"value": "ARCTIC"
},
{
"label": "побережье",
"value": "COAST"
},
{
"label": "под водой",
"value": "WATERS"
}
]
""")
)
)
}
)
public Collection<SelectOptionDto> getEnvironments() {
return directoryService.getEnvironments();
}

@Operation(summary = "Типы черт")
@GetMapping("/type/feats")
public Collection<ValueDto> getFeatTypes() {
@GetMapping("/feat/types")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "черты происхождения",
"value": "ORIGIN"
},
{
"label": "общие черты",
"value": "GENERAL"
},
{
"label": "эпические черты",
"value": "EPIC_BOON"
}
]
""")
)
)
}
)
public Collection<SelectOptionDto> getFeatTypes() {
return directoryService.getFeatTypes();
}

@Operation(summary = "Типы заклинателей")
@GetMapping("/spellcaster/types")
public Collection<ValueDto> getSpellcasterTypes() {
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = "application/json",
examples = @ExampleObject("""
[
{
"label": "полный заклинатель",
"value": "FULL",
"levels": 9
},
{
"label": "половинный заклинатель",
"value": "HALF",
"levels": 5
},
{
"label": "частичный заклинатель",
"value": "PARTLY",
"levels": 4
}
]
""")
)
)
}
)
public Collection<SpellcasterSelectOptionDto> getSpellcasterTypes() {
return directoryService.getSpellcasterTypes();
}

@Operation(summary = "Типы черт")
@GetMapping("/feat/types")
public Collection<ValueDto> getFeatTypesSpellcasterTypes() {
return directoryService.getFeatTypesSpellcasterTypes();
}
}
22 changes: 22 additions & 0 deletions src/main/java/club/ttg/dnd5/dto/select/DiceSelectOptionDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package club.ttg.dnd5.dto.select;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class DiceSelectOptionDto extends SelectOptionDto {
@Schema(
example = "9",
description = "Максимальное значение на кубе",
requiredMode = Schema.RequiredMode.REQUIRED
)
private int maxValue;
}
29 changes: 29 additions & 0 deletions src/main/java/club/ttg/dnd5/dto/select/SelectOptionDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package club.ttg.dnd5.dto.select;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;

/**
* Описывает один пункт в выпадающем списке.
*/
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class SelectOptionDto {
@Schema(
example = "Средний",
description = "Отображаемое имя. В выпадающих списках используется для человекочитаемого текста.",
requiredMode = Schema.RequiredMode.REQUIRED
)
private String label;

@Schema(
example = "MEDIUM",
description = "Используемое значение. Передается в запросах на API, например, при создании вида.",
requiredMode = Schema.RequiredMode.REQUIRED
)
private String value;
}
Loading
Loading