addCategory gibt statuscode + neue category als json zurück
This commit is contained in:
1 parent
16dfd340ec
commit
9fa60a8d6d
1 file changed
+8
-2
+8
-2
@@ -32,7 +32,7 @@ public class ShoppingCategoryController {
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
|
||||
@PostMapping("/api/categories")
|
||||
public ShoppingCategoryResponseDTO addCategory(@RequestBody ShoppingCategoryPostDTO newCategory){
|
||||
public ResponseEntity<ShoppingCategoryResponseDTO> addCategory(@RequestBody ShoppingCategoryPostDTO newCategory){
|
||||
|
||||
String name = newCategory.categoryName();
|
||||
ShoppingList list = shoppingListRepository.findById(newCategory.listID()).orElseThrow(() -> new ResourceNotFoundException("listID",newCategory.listID()));
|
||||
@@ -41,7 +41,13 @@ public class ShoppingCategoryController {
|
||||
|
||||
shoppingCategoryRepository.save(category);
|
||||
|
||||
return new ShoppingCategoryResponseDTO(name, category.getId());
|
||||
URI location = ServletUriComponentsBuilder
|
||||
.fromCurrentRequest()
|
||||
.path("/{id}")
|
||||
.buildAndExpand(category.getId())
|
||||
.toUri();
|
||||
|
||||
return ResponseEntity.created(location).body(new ShoppingCategoryResponseDTO(name, category.getId()));
|
||||
}
|
||||
|
||||
@PatchMapping("/api/categories/{categoryID}")
|
||||
|
||||
Reference in new issue
Block a user