Skip to content
Snippets Groups Projects

Added add all items from recipe endpoint and tests

Merged Axel Ytterås requested to merge CheckFridgeBeforeAddingFromRecipe into main
4 files
+ 67
7
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -240,4 +240,21 @@ public class ShoppingListController {
@@ -240,4 +240,21 @@ public class ShoppingListController {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
}
}
}
}
 
 
@ResponseStatus(code = HttpStatus.OK)
 
@PutMapping("/recipe/{recipeId}")
 
public @ResponseBody ShoppingList addItemsFromRecipe(@PathVariable("recipeId") Integer recipeId) {
 
 
String authenticatedUsername = SecurityContextHolder.getContext().getAuthentication().getName();
 
Account loggedInAccount = accountRepository.findByEmail(authenticatedUsername).orElseThrow();
 
 
try {
 
return shoppingListService.addAllItemsFromRecipe(recipeId, loggedInAccount);
 
} catch ( IllegalArgumentException e) {
 
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
 
} catch (IllegalStateException e) {
 
logger.error(e.getMessage());
 
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage());
 
}
 
}
}
}
Loading