Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106-v23-03
backend
Commits
397d8649
"...idatt-1002-2023-9.git" did not exist on "eb177b1b7ad13760dd528d52f70acf14c5e2ea1c"
Commit
397d8649
authored
2 years ago
by
Anders Austlid
Browse files
Options
Downloads
Patches
Plain Diff
Fridge controller delete fridgeproductid can now handle decimal numbers
parent
1553b7bf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/ntnu/idatt2016/v233/SmartMat/controller/group/FridgeController.java
+13
-2
13 additions, 2 deletions
...2016/v233/SmartMat/controller/group/FridgeController.java
with
13 additions
and
2 deletions
src/main/java/ntnu/idatt2016/v233/SmartMat/controller/group/FridgeController.java
+
13
−
2
View file @
397d8649
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment