diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/group/FridgeController.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/group/FridgeController.java index 9053405f2ca4b5722ddfeb6e36885138023aac7f..1a02f49d9a6f563e6311a47b3279f02aa37b73a9 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/group/FridgeController.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/group/FridgeController.java @@ -37,6 +37,19 @@ public class FridgeController { .orElseGet(() -> ResponseEntity.notFound().build()); } + /** + * Gets the fridge by its fridge id + * @param fridgeId the id of the fridge + * @return the fridge if it exists, or a 404 if it doesn't + */ + @GetMapping("/fridge/{fridgeId}") + public ResponseEntity<Fridge> getFridgeByFridgeId(@PathVariable("fridgeId") long fridgeId) { + return fridgeService.getFridgeByFridgeId(fridgeId) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + /** * Adds a product to the fridge of a group * diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java index 8650f11264f6dc6a51a2bc56bc82018ef823df51..d6a0d519e63af6a8728a6171f0d78342b68efe13 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java @@ -37,6 +37,17 @@ public class FridgeService { public Optional<Fridge> getFridgeByGroupId(long groupId) { return fridgeRepository.findByGroupId(groupId); } + + /** + * Gets the fridge by its fridge id + * + * @param fridgeId the id of the fridge + * @return the fridge if it exists + */ + public Optional<Fridge> getFridgeByFridgeId(long fridgeId) { + return fridgeRepository.findById(fridgeId); + } + /** * Add a product to the fridge of a group