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
e63dfddc
Commit
e63dfddc
authored
1 year ago
by
Anders Austlid
Browse files
Options
Downloads
Patches
Plain Diff
Synced to changes from main
parent
8cac6efc
No related branches found
Branches containing commit
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/service/group/FridgeService.java
+15
-9
15 additions, 9 deletions
.../idatt2016/v233/SmartMat/service/group/FridgeService.java
with
15 additions
and
9 deletions
src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java
+
15
−
9
View file @
e63dfddc
...
...
@@ -69,7 +69,7 @@ public class FridgeService {
* @param fridgeProductRequest the fridge product request
* @return the product that was added to the fridge
*/
public
Optional
<
Obje
ct
>
addProductToFridge
(
FridgeProductRequest
fridgeProductRequest
)
{
public
Optional
<
Produ
ct
>
addProductToFridge
(
FridgeProductRequest
fridgeProductRequest
)
{
Optional
<
Product
>
product
=
productService
.
getProductById
(
fridgeProductRequest
.
ean
());
Optional
<
Fridge
>
fridge
=
fridgeRepository
.
findByGroupGroupId
(
fridgeProductRequest
.
groupId
());
double
price
=
100.0
;
...
...
@@ -89,11 +89,11 @@ public class FridgeService {
.
build
());
fridgeRepository
.
save
(
fridge
.
get
());
return
Optional
.
of
(
product
)
;
return
product
;
}
public
Optional
<
Object
>
updateProductInFridge
(
FridgeProductRequest
request
)
{
public
Optional
<
FridgeProductAsso
>
updateProductInFridge
(
FridgeProductRequest
request
)
{
Optional
<
FridgeProductAsso
>
fridgeProductAsso
=
fridgeProductAssoRepo
.
findById
(
request
.
fridgeProductId
());
if
(
fridgeProductAsso
.
isEmpty
())
return
Optional
.
empty
();
...
...
@@ -108,7 +108,7 @@ public class FridgeService {
fridgeProductAssoRepo
.
save
(
fridgeProductAsso
.
get
());
return
Optional
.
of
(
fridgeProductAsso
)
;
return
fridgeProductAsso
;
}
...
...
@@ -164,12 +164,12 @@ public class FridgeService {
* @param amount the amount to delete
* @return an optional containing the fridge product if it exists
*/
public
Optional
<
Object
>
deleteAmountFromFridge
(
long
fridgeProductId
,
double
amount
)
{
public
Optional
<
FridgeProductAsso
>
deleteAmountFromFridge
(
long
fridgeProductId
,
double
amount
)
{
Optional
<
FridgeProductAsso
>
fridgeProductAsso
=
fridgeProductAssoRepo
.
findAllById
(
fridgeProductId
);
if
(
fridgeProductAsso
.
isEmpty
())
return
Optional
.
empty
();
FridgeProductAsso
fridgeProductAsso1
=
fridgeProductAsso
.
get
();
if
(
amount
<
fridgeProductAsso1
.
getAmount
()
){
fridgeProductAsso1
.
setAmount
(
fridgeProductAsso1
.
getAmount
()
-
amount
);
fridgeProductAsso1
.
setAmount
(
fridgeProductAsso1
.
getAmount
()
-
amount
);
return
Optional
.
of
(
fridgeProductAssoRepo
.
save
(
fridgeProductAsso1
));
}
else
{
Group
group
=
fridgeProductAsso1
.
getFridgeId
().
getGroup
();
...
...
@@ -177,7 +177,7 @@ public class FridgeService {
group
.
setLevel
(
GroupUtil
.
getLevel
(
group
.
getPoints
()));
groupRepository
.
save
(
group
);
fridgeProductAssoRepo
.
delete
(
fridgeProductAsso
.
get
());
return
Optional
.
of
(
true
);
return
Optional
.
empty
(
);
}
}
...
...
@@ -186,7 +186,7 @@ public class FridgeService {
* @param fridgeProductId the ID of the fridge product association to delete
* @return an Optional containing the saved waste object, or an empty Optional if the fridge product association with the given ID is not found
*/
public
Optional
<
Object
>
wasteProductFromFridge
(
long
fridgeProductId
){
public
Optional
<
Waste
>
wasteProductFromFridge
(
long
fridgeProductId
){
Optional
<
FridgeProductAsso
>
fridgeProductAsso
=
fridgeProductAssoRepo
.
findById
(
fridgeProductId
);
if
(
fridgeProductAsso
.
isEmpty
())
return
Optional
.
empty
();
FridgeProductAsso
fridgeProductAsso1
=
fridgeProductAsso
.
get
();
...
...
@@ -197,7 +197,13 @@ public class FridgeService {
group
.
setLevel
(
GroupUtil
.
getLevel
(
group
.
getPoints
()));
}
groupRepository
.
save
(
group
);
return
Optional
.
of
(
wasteRepository
.
save
(
Waste
.
builder
().
buyPrice
(
fridgeProductAsso1
.
getBuyPrice
()).
amount
(
fridgeProductAsso1
.
getAmount
()).
unit
(
fridgeProductAsso1
.
getEan
().
getUnit
()).
ean
(
fridgeProductAsso1
.
getEan
()).
groupId
(
fridgeProductAsso1
.
getFridgeId
().
getGroup
()).
timestamp
(
new
Timestamp
(
System
.
currentTimeMillis
())).
build
()));
return
Optional
.
of
(
wasteRepository
.
save
(
Waste
.
builder
()
.
amount
(
fridgeProductAsso1
.
getAmount
())
.
unit
(
fridgeProductAsso1
.
getEan
().
getUnit
())
.
ean
(
fridgeProductAsso1
.
getEan
())
.
groupId
(
fridgeProductAsso1
.
getFridgeId
().
getGroup
())
.
timestamp
(
new
Timestamp
(
System
.
currentTimeMillis
()))
.
build
()));
}
...
...
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