Skip to content
Snippets Groups Projects
Commit 5d7be27b authored by Stian Lyng Stræte's avatar Stian Lyng Stræte
Browse files

Merge branch 'feature/45-implement-shoppinglist-service' into 'main'

Feature/45 implement shoppinglist service

See merge request idatt2106-v23-03/backend!21
parents 8dbd1a10 fe343c74
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ import ntnu.idatt2016.v233.SmartMat.model.ShoppingList;
* @version 1.0
*
*/
public interface ShoppingListReposity {
public interface ShoppingListRepository {
/**
* Saves a shopping list to the database
......
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.ShoppingListRepository;
/**
* Service for the shopping list
*
* @author Stian Lyng
* @version 1.0
*/
public class ShoppingListService {
ShoppingListRepository shoppingListRepository;
/**
* Creates a new ShoppingListService
*
* @param shoppingListRepository The repository to use
*/
public ShoppingListService(ShoppingListRepository 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);
}
}
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