Merge branch 'feature/17-restful-api', fixes #17
This commit is contained in:
commit
109a7a9610
6 files changed
+21
-21
No files matched your search
+3
-3
@@ -27,7 +27,7 @@ public class ShoppingCategoryController {
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
|
||||
@PostMapping("/api/category")
|
||||
@PostMapping("/api/categories")
|
||||
public ShoppingCategoryResponseDTO addCategory(@RequestBody ShoppingCategoryPostDTO newCategory){
|
||||
|
||||
String name = newCategory.categoryName();
|
||||
@@ -40,7 +40,7 @@ public class ShoppingCategoryController {
|
||||
return new ShoppingCategoryResponseDTO(name, category.getId());
|
||||
}
|
||||
|
||||
@PatchMapping("/api/category/{categoryID}")
|
||||
@PatchMapping("/api/categories/{categoryID}")
|
||||
public ResponseEntity<Void> editCategory(@PathVariable UUID categoryID,@RequestBody ShoppingCategoryPatchDTO toChange){
|
||||
ShoppingCategory category = shoppingCategoryRepository.findById(categoryID).orElseThrow();
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ShoppingCategoryController {
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/api/category/{categoryID}")
|
||||
@DeleteMapping("/api/categories/{categoryID}")
|
||||
public ResponseEntity<Void> deleteCategory(@PathVariable UUID categoryID, @RequestParam(required = false) Boolean deleteAllItems){
|
||||
|
||||
if(deleteAllItems == null){
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ShoppingItemController {
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
|
||||
@PostMapping("/api/item")
|
||||
@PostMapping("/api/items")
|
||||
public ShoppingItemResponseDTO addItem(@RequestBody ShoppingItemPostDTO newItem){
|
||||
String name = newItem.itemName();
|
||||
String amount = newItem.itemAmount();
|
||||
@@ -42,7 +42,7 @@ public class ShoppingItemController {
|
||||
return new ShoppingItemResponseDTO(name, amount, item.getId(), c != null? c.getId() : null);
|
||||
}
|
||||
|
||||
@PatchMapping("/api/item/{itemID}")
|
||||
@PatchMapping("/api/items/{itemID}")
|
||||
public ResponseEntity<Void> editItem(@PathVariable UUID itemID ,@RequestBody ShoppingItemPatchDTO toChange){
|
||||
ShoppingItem item = shoppingItemRepository.findById(itemID).orElseThrow();
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ShoppingItemController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/item/{itemID}")
|
||||
@DeleteMapping("/api/items/{itemID}")
|
||||
public ResponseEntity<Void> deleteItem(@PathVariable UUID itemID){
|
||||
if(!shoppingItemRepository.existsById(itemID)){
|
||||
return ResponseEntity.notFound().build();
|
||||
@@ -66,8 +66,8 @@ public class ShoppingItemController {
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/api/item")
|
||||
public ResponseEntity<Void> deleteAllDoneItems(@RequestParam UUID listID, @RequestParam boolean done){
|
||||
@DeleteMapping("/api/lists/{listID}/items")
|
||||
public ResponseEntity<Void> deleteAllDoneItems(@PathVariable UUID listID, @RequestParam boolean done){
|
||||
if(!done) return ResponseEntity.badRequest().build();
|
||||
|
||||
List<ShoppingItem> items = shoppingItemRepository.findByList_IdAndIsDoneIsTrue(listID);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ShoppingListController {
|
||||
@Autowired
|
||||
private ShoppingListService shoppingListService;
|
||||
|
||||
@PostMapping("/api/list")
|
||||
@PostMapping("/api/lists")
|
||||
public ShoppingListResponseDTO addList(@RequestBody ShoppingListPostDTO newList){
|
||||
ShoppingList list = new ShoppingList(newList.listName(), null, null, 0, 0);
|
||||
|
||||
@@ -36,13 +36,13 @@ public class ShoppingListController {
|
||||
|
||||
return new ShoppingListResponseDTO(list.getListName(), list.getId());
|
||||
}
|
||||
@DeleteMapping("/api/list/{listID}")
|
||||
@DeleteMapping("/api/lists/{listID}")
|
||||
public ResponseEntity<Void> deleteList(@PathVariable UUID listID){
|
||||
shoppingListService.deleteList(listID);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PatchMapping("/api/list/{listID}")
|
||||
@PatchMapping("/api/lists/{listID}")
|
||||
public ResponseEntity<Void> editList(@PathVariable UUID listID,@RequestBody ShoppingListPatchDTO toChange){
|
||||
ShoppingList list = shoppingListRepository.findById(listID).orElseThrow();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
export async function addList(listName) {
|
||||
const response = await fetch(`/api/list`,
|
||||
const response = await fetch(`/api/lists`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({ listName: listName }),
|
||||
@@ -14,7 +14,7 @@ export async function addList(listName) {
|
||||
}
|
||||
|
||||
export async function deleteList(id) {
|
||||
const response = await fetch(`/api/list/${id}`, { method: "DELETE" });
|
||||
const response = await fetch(`/api/lists/${id}`, { method: "DELETE" });
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export async function deleteList(id) {
|
||||
|
||||
|
||||
export async function editList(listID, toChange) {
|
||||
const response = await fetch(`/api/list/${listID}`,
|
||||
const response = await fetch(`/api/lists/${listID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export async function addCategory(listID, categoryName) {
|
||||
const newCategory = await fetch(`/api/category`,
|
||||
const newCategory = await fetch(`/api/categories`,
|
||||
{
|
||||
method: "POST"
|
||||
, body: JSON.stringify({ "categoryName": categoryName, "listID": listID })
|
||||
@@ -10,7 +10,7 @@ export async function addCategory(listID, categoryName) {
|
||||
|
||||
|
||||
export async function editCategory(categoryID, toChange) {
|
||||
const response = await fetch(`/api/category/${categoryID}`,
|
||||
const response = await fetch(`/api/categories/${categoryID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
@@ -21,7 +21,7 @@ export async function editCategory(categoryID, toChange) {
|
||||
}
|
||||
|
||||
export async function deleteCategory(deleteAllItems, categoryID) {
|
||||
const response = await fetch(`/api/category/${categoryID}?deleteAllItems=${deleteAllItems}`, { method: "DELETE" });
|
||||
const response = await fetch(`/api/categories/${categoryID}?deleteAllItems=${deleteAllItems}`, { method: "DELETE" });
|
||||
|
||||
if (response.status == 204) {
|
||||
console.log(`deleted item ${categoryID}`);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
export async function addItem(listID, itemName, itemAmount, categoryID) {
|
||||
const newItem = await fetch(`/api/item`,
|
||||
const newItem = await fetch(`/api/items`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
@@ -20,7 +20,7 @@ export async function addItem(listID, itemName, itemAmount, categoryID) {
|
||||
|
||||
export async function deleteItem(itemID) {
|
||||
|
||||
const response = await fetch(`/api/item/${itemID}`, { method: "DELETE" });
|
||||
const response = await fetch(`/api/items/${itemID}`, { method: "DELETE" });
|
||||
|
||||
if (response.status == 204) {
|
||||
console.log(`deleted item ${itemID}`);
|
||||
@@ -31,7 +31,7 @@ export async function deleteItem(itemID) {
|
||||
}
|
||||
|
||||
export async function editItem(itemID, toChange) {
|
||||
const response = await fetch(`/api/item/${itemID}`,
|
||||
const response = await fetch(`/api/items/${itemID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
@@ -43,7 +43,7 @@ export async function editItem(itemID, toChange) {
|
||||
|
||||
export async function deleteAllDoneItems(listID) {
|
||||
|
||||
const response = await fetch(`/api/item?listID=${listID}&done=true`, { method: "DELETE" });
|
||||
const response = await fetch(`/api/lists/${listID}/items?done=true`, { method: "DELETE" });
|
||||
|
||||
if (response.status == 204) {
|
||||
console.log(`items have been deleted`);
|
||||
|
||||
Reference in new issue
Block a user