Items endpoint tests and updates to the item endpoint (#13) (#16)

* Creation of base template (#1)

* Sample template created

* added findByName functionality for item

* Solve Cors errors and inhibit DefaultExposure

* changed project structure

* Added frontend

* changed base path of REST api and updated frontend api quering

* Items enpoint tests and updates to the item endpoint (#13)

* Config setup

* add tests for items

Co-authored-by: Bruno <brunoj.philipp@gmail.com>
This commit is contained in:
cato
2022-06-05 17:35:37 +02:00
committed by GitHub
parent f6e1373a46
commit a1b0e7d838
4 changed files with 157 additions and 7 deletions

View File

@@ -32,13 +32,13 @@ public class ItemController {
@PostMapping("/items")
public Item createItem(@RequestBody Item item) {
itemService.save(item);
return item;
return itemService.save(item);
}
@PutMapping("/items/{itemId}")
public String updateItem(@PathVariable(value = "itemId") Long itemId, @RequestBody Item item) {
return itemService.findById(itemId).map(i -> {
public void updateItem(@PathVariable(value = "itemId") Long itemId, @RequestBody Item item) {
itemService.findById(itemId).map(i -> {
i.setName(item.getName());
i.setQuantity(item.getQuantity());
i.setUnit(item.getUnit());
@@ -48,8 +48,8 @@ public class ItemController {
}
@DeleteMapping("/items/{itemId}")
public String deleteItem(@PathVariable(value = "itemId") Long itemId) {
return itemService.findById(itemId).map(p -> {
public void deleteItem(@PathVariable(value = "itemId") Long itemId) {
itemService.findById(itemId).map(p -> {
itemService.deleteById(itemId);
return "Item deleted";
}).orElseThrow(() -> new ItemNotFoundException("itemId " + itemId + " not found"));