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
201c9803
Commit
201c9803
authored
2 years ago
by
Stian Lyng
Browse files
Options
Downloads
Patches
Plain Diff
add service
parent
520b01d0
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/ShoppingListService.java
+84
-0
84 additions, 0 deletions
.../idatt2016/v233/SmartMat/service/ShoppingListService.java
with
84 additions
and
0 deletions
src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java
0 → 100644
+
84
−
0
View file @
201c9803
package
ntnu.idatt2016.v233.SmartMat.service
;
import
java.util.List
;
import
java.util.Optional
;
import
ntnu.idatt2016.v233.SmartMat.model.ShoppingList
;
import
ntnu.idatt2016.v233.SmartMat.repository.ShoppingListReposity
;
/**
* Service for the shopping list
*
* @author Stian Lyng
* @version 1.0
*/
public
class
ShoppingListService
{
ShoppingListReposity
shoppingListRepository
;
/**
* Creates a new ShoppingListService
*
* @param shoppingListRepository The repository to use
*/
public
ShoppingListService
(
ShoppingListReposity
shoppingListRepository
)
{
this
.
shoppingListRepository
=
shoppingListRepository
;
}
/**
* Saves a shopping list to the database
* @param shoppingList the shopping list to save
* @return the saved shopping list
*/
public
ShoppingList
saveShoppingList
(
ShoppingList
shoppingList
)
{
return
shoppingListRepository
.
save
(
shoppingList
);
}
/**
* Gets a shopping list by its ID
*
* @param id the ID of the shopping list
* @return an optional containing the shopping list if it exists
*/
public
Optional
<
ShoppingList
>
getShoppingListById
(
int
id
)
{
return
shoppingListRepository
.
getById
(
id
);
}
/**
* Gets a shopping list by its group ID
*
* @param id the ID of the group
* @return an optional containing the shopping list if it exists
*/
public
Optional
<
ShoppingList
>
getShoppingListByGroupId
(
int
id
)
{
return
shoppingListRepository
.
getByGroupID
(
id
);
}
/**
* Gets all shopping lists
*
* @return an optional containing a list of all shopping lists if they exist
*/
public
Optional
<
List
<
ShoppingList
>>
getAllShoppingLists
()
{
return
shoppingListRepository
.
getAll
();
}
/**
* Gets all shopping lists by group ID
*
* @param id the ID of the group
* @return an optional containing a list of all shopping lists if they exist
*/
public
Optional
<
List
<
ShoppingList
>>
getAllShoppingListsByGroupId
(
int
id
)
{
return
shoppingListRepository
.
getAllByGroupID
(
id
);
}
/**
* Deletes a shopping list by its ID
*
* @param id the ID of the shopping list
*/
public
void
deleteShoppingListById
(
int
id
)
{
shoppingListRepository
.
deleteById
(
id
);
}
}
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