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

Feature/item #55

Merged
merged 11 commits into from
Feb 21, 2025
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/
application-local.properties
/local.env

### STS ###
.apt_generated
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/club/ttg/dnd5/controller/item/ArmorController.java

This file was deleted.

98 changes: 93 additions & 5 deletions src/main/java/club/ttg/dnd5/controller/item/ItemController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,102 @@
package club.ttg.dnd5.controller.item;

import club.ttg.dnd5.dto.item.ItemDto;
import club.ttg.dnd5.service.item.ItemService;
import io.swagger.v3.oas.annotations.Operation;
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.NoArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Снаряжение", description = "REST API снаряжение и прочие предметы")
import java.util.Collection;

@RestController
@NoArgsConstructor
@RequiredArgsConstructor
@RequestMapping("/api/v2/item")
@Tag(name = "Снаряжение и предметы", description = "REST API снаряжение и прочие предметы")
public class ItemController {
private final ItemService itemService;
/**
* Проверка существования вида по URL.
*
* @param url URL вида.
* @return 204, если вида с таким URL не существует; 409, если вид существует.
*/
@Operation(
summary = "Проверка существования вида",
description = "Возвращает 204 (No Content), если предмет с указанным URL не существует, или 409 (Conflict), если существует."
)
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Предмет с указанным URL не найден."),
@ApiResponse(responseCode = "409", description = "Предмет с указанным URL уже существует.")
})
@RequestMapping(value = "/{url}", method = RequestMethod.HEAD)
public ResponseEntity<Void> handleOptions(@PathVariable("url") String url) {
boolean exists = itemService.existsByUrl(url);
if (exists) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
} else {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}

@Operation(summary = "Получение детального описания предмета")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Предмет успешно получена"),
@ApiResponse(responseCode = "404", description = "Предмет не найден")
})
@ResponseStatus(HttpStatus.OK)
@GetMapping("/{itemUtl}")
public ItemDto getItem(@PathVariable final String itemUtl) {
return itemService.getItem(itemUtl);
}

@Operation(summary = "Получение списка краткого описания предметов")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Предметы успешно получены")
})
@ResponseStatus(HttpStatus.OK)
@PostMapping("/search")
public Collection<ItemDto> getItems() {
return itemService.getItems();
}

@Operation(summary = "Добавление предмета")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Предмет успешно добавлен"),
@ApiResponse(responseCode = "400", description = "Предмет уже существует"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public ItemDto addItem(@RequestBody final ItemDto itemDto) {
return itemService.addItem(itemDto);
}

@Operation(summary = "Обновление предмета")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Предмет успешно обновлен"),
@ApiResponse(responseCode = "404", description = "Предмет не существует"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@ResponseStatus(HttpStatus.OK)
@PostMapping("{itemUrl}")
public ItemDto updateItem(@PathVariable final String itemUrl,
@RequestBody final ItemDto itemDto) {
return itemService.updateItem(itemUrl, itemDto);
}

@Operation(summary = "Скрывает предмет")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Предмет удалена из общего списка"),
@ApiResponse(responseCode = "403", description = "Доступ запрещен")
})
@ResponseStatus(HttpStatus.OK)
@DeleteMapping("{itemUrl}")
public ItemDto deleteItem(@PathVariable final String itemUrl) {
return itemService.delete(itemUrl);
}
}
14 changes: 0 additions & 14 deletions src/main/java/club/ttg/dnd5/controller/item/WeaponController.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package club.ttg.dnd5.controller.tools.dictionary;

import club.ttg.dnd5.dictionary.Alignment;
import club.ttg.dnd5.dictionary.DamageType;
import club.ttg.dnd5.dictionary.Dice;
import club.ttg.dnd5.dictionary.Size;
import club.ttg.dnd5.dictionary.beastiary.Condition;
import club.ttg.dnd5.dictionary.beastiary.CreatureType;
import club.ttg.dnd5.dictionary.beastiary.Environment;
import club.ttg.dnd5.dictionary.character.FeatCategory;
import club.ttg.dnd5.dictionary.character.SpellcasterType;
import club.ttg.dnd5.dictionary.item.ItemType;
import club.ttg.dnd5.dictionary.item.magic.Rarity;
import club.ttg.dnd5.dto.NameDto;
import club.ttg.dnd5.dto.base.NameBasedDTO;
import club.ttg.dnd5.dto.base.ValueDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;

/**
* Различные справочники
*/
@RequiredArgsConstructor
@Tag(name = "Справочники", description = "API для различных справочников")
@RequestMapping("/api/v2/directory/")
@RestController
public class DirectoryController {
@Operation(summary = "Дайсы")
@GetMapping("/dices")
public Collection<ValueDto> getDices() {
return Arrays.stream(Dice.values())
.map(type -> ValueDto.builder()
.name(NameBasedDTO.builder()
.name(type.getName())
.english(type.name())
.build())
.value(type.getMaxValue())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Типы существ")
@GetMapping("/beast/types")
public Collection<NameDto> getCreatureCategory() {
return Arrays.stream(CreatureType.values())
.map(type -> NameDto.builder()
.rus(type.getCyrillicName())
.eng(type.name())
.build()
)
.collect(Collectors.toList()
);
}

@Operation(summary = "Размеры существ")
@GetMapping("/sizes")
public Collection<NameDto> getCreatureSize() {
return Arrays.stream(Size.values())
.map(size -> NameDto.builder()
.rus(size.getName())
.eng(size.name())
.build()
)
.collect(Collectors.toList()
);
}

@Operation(summary = "Типы урона")
@GetMapping("/damage/types")
public Collection<NameDto> getDamageType() {
return Arrays.stream(DamageType.values())
.map(type -> NameDto.builder()
.rus(type.getCyrillicName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Состояния")
@GetMapping("/conditions")
public Collection<NameDto> getConditions() {
return Arrays.stream(Condition.values())
.map(type -> NameDto.builder()
.rus(type.getCyrillicName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Мировоззрение")
@GetMapping("/alignments")
public Collection<NameDto> getAlignments() {
return Arrays.stream(Alignment.values())
.map(type -> NameDto.builder()
.rus(type.getName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Места обитания существ")
@GetMapping("/environments")
public Collection<NameDto> getEnvironments() {
return Arrays.stream(Environment.values())
.map(type -> NameDto.builder()
.rus(type.getName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Типы черт")
@GetMapping("/type_feats")
public Collection<NameDto> getFeatTypes() {
return Arrays.stream(FeatCategory.values())
.map(type -> NameDto.builder()
.rus(type.getName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Типы заклинателей")
@GetMapping("/spellcaster_types")
public Collection<ValueDto> getSpellcasterTypes() {
return Arrays.stream(SpellcasterType.values())
.map(type -> ValueDto.builder()
.name(NameBasedDTO.builder()
.name(type.getName())
.english(type.name())
.build())
.value(type.getMaxSpellLevel())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Типы черт")
@GetMapping("/feat_types")
public Collection<NameDto> getFeatTypesSpellcasterTypes() {
return Arrays.stream(FeatCategory.values())
.map(type -> NameDto.builder()
.rus(type.getName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Типы предметов")
@GetMapping("/item_types")
public Collection<NameDto> getItemTypes() {
return Arrays.stream(ItemType.values())
.map(type -> NameDto.builder()
.rus(type.getName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}

@Operation(summary = "Редкость магических предметов")
@GetMapping("/rarities")
public Collection<NameDto> getRarities() {
return Arrays.stream(Rarity.values())
.map(type -> NameDto.builder()
.rus(type.getName())
.eng(type.name())
.build())
.collect(Collectors.toList()
);
}
}
50 changes: 50 additions & 0 deletions src/main/java/club/ttg/dnd5/dictionary/item/ItemType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package club.ttg.dnd5.dictionary.item;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum ItemType {
AMMUNITION("Боеприпасы"),

ADVENTURING_GEAR("Снаряжение приключенца"),
ARTISAN_S_TOOLS("Инструменты ремесленников"),
FOOD_AND_DRINK("Еда и питье"),
GAMING_SET("Игровой набор"),

WEAPON("Оружие"),
MARTIAL_WEAPON("Воинское оружие"),
SIMPLE_WEAPON("Простое оружие"),
MELEE_WEAPON("Рукопашное оружие"),
RANGED_WEAPON("Дальнобойное оружие"),
FIREARM("Огнестрельное оружие"),

ARMOR("Доспехи"),
LIGHT_ARMOR("Легкий доспех"),
MEDIUM_ARMOR("Средний доспех"),
HEAVY_ARMOR("Тяжелый доспех"),
SHIELD("щит"), // 10

TOOL("Инструменты"),
INSTRUMENT("Музыкальные инструменты"),
SPELLCASTING_FOCUS(""),
POISON("Яды"),
MOUNT("Верховое животное"),
TACK_AND_HARNESS("Упряжь и сбруя"),
VEHICLE("Транспорт"),
VEHICLE_AIR("Транспорт (воздушный)"),
VEHICLE_LAND("Транспорт (наземный)"),
VEHICLE_WATER("Транспорт (водный)"),

WAND("волшебная палочка"), // 2
ROD("жезл"), // 3
STAFF("посох"), //4
POTION("зелье"), //5
RING("кольцо"), //6
SCROLL("свиток"), // 7
SUBJECT("чудесный предмет"), // 8
;

private final String name;
}
Loading
Loading