Skip to content
Snippets Groups Projects

Add to fridge from shopping list

Merged Axel Ytterås requested to merge AddToFridgeFromShoppingList into main
3 files
+ 19
22
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -221,18 +221,18 @@ public class ShoppingListController {
@@ -221,18 +221,18 @@ public class ShoppingListController {
/**
/**
* Method to buy a list of ingredients from the shopping list, putting them in fridge
* Method to buy a list of ingredients from the shopping list, putting them in fridge
* @param ingredientIds a list of ingredient ids
* @param ingredients a list of ingredients
* @return the updated shopping list
* @return the updated shopping list
*/
*/
@ResponseStatus(code = HttpStatus.OK)
@ResponseStatus(code = HttpStatus.OK)
@DeleteMapping("/purchased")
@PutMapping("/purchased")
public @ResponseBody ShoppingList buyIngredients(@RequestBody List<Integer> ingredientIds) {
public @ResponseBody ShoppingList buyIngredients(@RequestBody List<Ingredient> ingredients) {
String authenticatedUsername = SecurityContextHolder.getContext().getAuthentication().getName();
String authenticatedUsername = SecurityContextHolder.getContext().getAuthentication().getName();
Account loggedInAccount = accountRepository.findByEmail(authenticatedUsername).orElseThrow();
Account loggedInAccount = accountRepository.findByEmail(authenticatedUsername).orElseThrow();
try {
try {
return shoppingListService.buyAll(ingredientIds, loggedInAccount);
return shoppingListService.buyAll(ingredients, loggedInAccount);
} catch ( IllegalArgumentException e) {
} catch ( IllegalArgumentException e) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
} catch (IllegalStateException e) {
} catch (IllegalStateException e) {
Loading