aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiederick de Vries <diederick@diederickdevries.net>2019-08-02 15:03:27 +0200
committerDiederick de Vries <diederick@diederickdevries.net>2019-08-02 15:03:27 +0200
commitaa460a248aa77eae57a35ebbe973c19d98cc5209 (patch)
treebfe726e37a95a5ad3b009d9f60fffec8cc0cc1c8
parent6c63d3d6e023246ebb52aa1276d6f3336e700951 (diff)
downloadboodschapi-aa460a248aa77eae57a35ebbe973c19d98cc5209.tar.gz
boodschapi-aa460a248aa77eae57a35ebbe973c19d98cc5209.tar.bz2
boodschapi-aa460a248aa77eae57a35ebbe973c19d98cc5209.zip
feature: when a bought item is re-added to the list, unbuy it and return a 200 ok with the existing item as payload
-rw-r--r--src/main/java/net/diederickdevries/boodschapi/controller/ItemController.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/net/diederickdevries/boodschapi/controller/ItemController.java b/src/main/java/net/diederickdevries/boodschapi/controller/ItemController.java
index 80c374d..a7f6201 100644
--- a/src/main/java/net/diederickdevries/boodschapi/controller/ItemController.java
+++ b/src/main/java/net/diederickdevries/boodschapi/controller/ItemController.java
@@ -59,8 +59,10 @@ public class ItemController
59 @Autowired private IngredientRepository ingredientRepository; 59 @Autowired private IngredientRepository ingredientRepository;
60 60
61 /** 61 /**
62 * Creates a new Item on the shopping list of a week. If the item represents 62 * Creates a new Item on the shopping list of a week. If the item represents an ingredient of a
63 * an ingredient of a meal, its showalways flag is set to true. 63 * meal, its showalways flag is set to true. If the item already exists in the list and is already
64 * bought, it is set to not bought. If the existing item was not bought, a 400 Illegal Request is
65 * returned.
64 * 66 *
65 * @param groceryid The id of the grocery that the item is. 67 * @param groceryid The id of the grocery that the item is.
66 * @param shopid The id of the shop to add the item to. 68 * @param shopid The id of the shop to add the item to.
@@ -96,9 +98,17 @@ public class ItemController
96 Item existing = itemRepository.findByWeekAndGrocery(weeknr, item.getGrocery()); 98 Item existing = itemRepository.findByWeekAndGrocery(weeknr, item.getGrocery());
97 if (null != existing) 99 if (null != existing)
98 { 100 {
101 if (existing.isBought())
102 {
103 unBuy(existing);
104 return ResponseEntity.ok(existing);
105 }
106 else
107 {
99 return ResponseEntity 108 return ResponseEntity
100 .badRequest() 109 .badRequest()
101 .body(MessageUtil.parse(MSG_400_EXISTS, item.getGrocery().getName())); 110 .body(MessageUtil.parse(MSG_400_EXISTS, item.getGrocery().getName()));
111 }
102 } 112 }
103 113
104 if (0 < ingredientRepository.findByGrocery(item.getGrocery()).size()) 114 if (0 < ingredientRepository.findByGrocery(item.getGrocery()).size())