Skip to content

Commit e810e52

Browse files
committed
feat(ItemController): add endpoints to update enchantments, flags, and lore of an item
1 parent 926c3fd commit e810e52

File tree

3 files changed

+147
-3
lines changed

3 files changed

+147
-3
lines changed

src/main/java/net/onelitefeather/vulpes/backend/controller/ItemController.java

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,41 @@ public HttpResponse<ItemModelResponseDTO> remove(@PathVariable UUID id) {
160160
)
161161
)
162162
)
163-
@Get("/enchantments/{id}")
163+
@Get(uris = {
164+
"/enchantments/{id}",
165+
"/{id}/enchantments"
166+
})
164167
@Produces(MediaType.APPLICATION_JSON)
165168
public HttpResponse<Page<ItemModelEnchantmentResponseDTO>> getEnchantmentsById(@PathVariable UUID id, Pageable pageable) {
166169
Map<String, Short> enchantments = itemService.findEnchantmentsById(id, pageable);
167170
return HttpResponse.ok(Page.of(enchantments.entrySet().stream().map(ItemModelResponseDTO.ItemModelEnchantmentResponseDTO::createDTO).toList(), pageable, (long) enchantments.size()));
168171
}
169172

173+
@Operation(
174+
summary = "Update enchantments of an item",
175+
description = "Updates the enchantments of an item by its ID.",
176+
tags = {"Item"}
177+
)
178+
@ApiResponse(
179+
responseCode = "200",
180+
description = "The enchantments of the item were successfully updated.",
181+
content = @Content(
182+
mediaType = MediaType.APPLICATION_JSON,
183+
array = @ArraySchema(
184+
schema = @Schema(implementation = ItemModelEnchantmentResponseDTO.class),
185+
arraySchema = @Schema(implementation = List.class)
186+
)
187+
)
188+
)
189+
@Post(uris = {
190+
"/enchantments/{id}",
191+
"/{id}/enchantments"
192+
})
193+
public HttpResponse<List<ItemModelEnchantmentResponseDTO>> updateEnchantments(@PathVariable UUID id, @Body Map<String, Short> enchantments) {
194+
var enchantmentResult = itemService.updateEnchantmentsById(id, enchantments);
195+
return HttpResponse.ok(enchantmentResult.entrySet().stream().map(ItemModelResponseDTO.ItemModelEnchantmentResponseDTO::createDTO).toList());
196+
}
197+
170198
@Operation(
171199
summary = "Get all flags of an item",
172200
description = "Retrieves all flags of an item by its ID.",
@@ -183,13 +211,41 @@ public HttpResponse<Page<ItemModelEnchantmentResponseDTO>> getEnchantmentsById(@
183211
)
184212
)
185213
)
186-
@Get("/flags/{id}")
214+
@Get(uris = {
215+
"/flags/{id}",
216+
"/{id}/flags"
217+
})
187218
@Produces(MediaType.APPLICATION_JSON)
188219
public HttpResponse<Page<String>> getFlagsById(@PathVariable UUID id, Pageable pageable) {
189220
List<String> flags = itemService.findFlagsById(id, pageable);
190221
return HttpResponse.ok(Page.of(flags, pageable, (long) flags.size()));
191222
}
192223

224+
@Operation(
225+
summary = "Update flags of an item",
226+
description = "Updates the flags of an item by its ID.",
227+
tags = {"Item"}
228+
)
229+
@ApiResponse(
230+
responseCode = "200",
231+
description = "The flags of the item were successfully updated.",
232+
content = @Content(
233+
mediaType = MediaType.APPLICATION_JSON,
234+
array = @ArraySchema(
235+
schema = @Schema(implementation = String.class),
236+
arraySchema = @Schema(implementation = List.class)
237+
)
238+
)
239+
)
240+
@Post(uris = {
241+
"/flags/{id}",
242+
"/{id}/flags"
243+
})
244+
public HttpResponse<List<String>> updateFlags(@PathVariable UUID id,@Body List<String> flags) {
245+
List<String> result = itemService.updateFlagsById(id, flags);
246+
return HttpResponse.ok(result);
247+
}
248+
193249
@Operation(
194250
summary = "Get all lore of an item",
195251
description = "Retrieves all lore of an item by its ID.",
@@ -206,13 +262,41 @@ public HttpResponse<Page<String>> getFlagsById(@PathVariable UUID id, Pageable p
206262
)
207263
)
208264
)
209-
@Get("/lore/{id}")
265+
@Get(uris = {
266+
"/lore/{id}",
267+
"/{id}/lore"
268+
})
210269
@Produces(MediaType.APPLICATION_JSON)
211270
public HttpResponse<Page<String>> getLoreById(@PathVariable UUID id, Pageable pageable) {
212271
List<String> lore = itemService.findLoreById(id, pageable);
213272
return HttpResponse.ok(Page.of(lore, pageable, (long) lore.size()));
214273
}
215274

275+
@Operation(
276+
summary = "Update lore of an item",
277+
description = "Updates the lore of an item by its ID.",
278+
tags = {"Item"}
279+
)
280+
@ApiResponse(
281+
responseCode = "200",
282+
description = "The lore of the item was successfully updated.",
283+
content = @Content(
284+
mediaType = MediaType.APPLICATION_JSON,
285+
array = @ArraySchema(
286+
schema = @Schema(implementation = String.class),
287+
arraySchema = @Schema(implementation = List.class)
288+
)
289+
)
290+
)
291+
@Post(uris = {
292+
"/lore/{id}",
293+
"/{id}/lore"
294+
})
295+
public HttpResponse<List<String>> updateLore(@PathVariable UUID id,@Body List<String> lore) {
296+
List<String> result = itemService.updateLoreById(id, lore);
297+
return HttpResponse.ok(result);
298+
}
299+
216300

217301
@Operation(
218302
summary = "Get all items",

src/main/java/net/onelitefeather/vulpes/backend/service/ItemService.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,28 @@ public interface ItemService {
8989
* @return a list of lore lines
9090
*/
9191
List<String> findLoreById(UUID id, Pageable pageable);
92+
93+
/**
94+
* Updates the flags of an item by its ID.
95+
* @param id the ID of the item to update the flags of
96+
* @param flags the new flags to set
97+
* @return the updated flags
98+
*/
99+
List<String> updateFlagsById(UUID id, List<String> flags);
100+
101+
/**
102+
* Updates the enchantments of an item by its ID.
103+
* @param id the ID of the item to update the enchantments of
104+
* @param enchantments the new enchantments to set
105+
* @return the updated enchantments
106+
*/
107+
Map<String, Short> updateEnchantmentsById(UUID id, Map<String, Short> enchantments);
108+
109+
/**
110+
* Updates the lore of an item by its ID.
111+
* @param id the ID of the item to update the lore of
112+
* @param lore the new lore to set
113+
* @return the updated lore
114+
*/
115+
List<String> updateLoreById(UUID id, List<String> lore);
92116
}

src/main/java/net/onelitefeather/vulpes/backend/service/impl/ItemServiceImpl.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,40 @@ public List<String> findFlagsById(UUID id, Pageable pageable) {
8686
public List<String> findLoreById(UUID id, Pageable pageable) {
8787
return itemRepository.findLoreById(id, pageable);
8888
}
89+
90+
@Override
91+
public List<String> updateLoreById(UUID id, List<String> lore) {
92+
var byId = this.itemRepository.findById(id);
93+
if (byId.isEmpty()) {
94+
return List.of();
95+
}
96+
var item = byId.get();
97+
item.setLore(lore);
98+
var updated = this.itemRepository.update(item);
99+
return updated.getLore();
100+
}
101+
102+
@Override
103+
public Map<String, Short> updateEnchantmentsById(UUID id, Map<String, Short> enchantments) {
104+
var byId = this.itemRepository.findById(id);
105+
if (byId.isEmpty()) {
106+
return Map.of();
107+
}
108+
var item = byId.get();
109+
item.setEnchantments(enchantments);
110+
var updated = this.itemRepository.update(item);
111+
return updated.getEnchantments();
112+
}
113+
114+
@Override
115+
public List<String> updateFlagsById(UUID id, List<String> flags) {
116+
var byId = this.itemRepository.findById(id);
117+
if (byId.isEmpty()) {
118+
return List.of();
119+
}
120+
var item = byId.get();
121+
item.setFlags(flags);
122+
var updated = this.itemRepository.update(item);
123+
return updated.getFlags();
124+
}
89125
}

0 commit comments

Comments
 (0)