Skip to content
Snippets Groups Projects
Commit 397d8649 authored by Anders Austlid's avatar Anders Austlid
Browse files

Fridge controller delete fridgeproductid can now handle decimal numbers

parent 1553b7bf
No related branches found
No related tags found
No related merge requests found
......@@ -67,11 +67,22 @@ public class FridgeController {
@DeleteMapping("/group/delete/product/{fridgeProductId}/{amount}")
public ResponseEntity<?> deleteAmountFridgeProduct(@PathVariable("fridgeProductId") long fridgeProductId,
@PathVariable("amount") double amount){
return fridgeService.deleteAmountFromFridge(fridgeProductId,amount).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
@PathVariable("amount") String amountStr) {
try {
double amount = Double.parseDouble(amountStr);
if (amount < 0.0) {
return ResponseEntity.badRequest().body("Amount must be greater than or equal to 0.");
}
return fridgeService.deleteAmountFromFridge(fridgeProductId, amount).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().body("Invalid amount format. Please provide a valid number.");
}
}
/**
* Deletes a product from the fridge
* @param fridgeProductId the id of the fridge product association
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment