diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java index 94a4bf58a8ff87f2765a36abf4c3510971ef566d..539e6349851f9dee0c3aee195e8e11f2e1ea6b59 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java @@ -12,7 +12,6 @@ import java.util.Optional; * * @author Stian Lyng and birk * @version 1.2 - * @since 21.04.2023 */ public interface AllergyRepository extends JpaRepository<Allergy, String> { /** diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java index d85894c2d48bb672c13cface578b18cdc3861d41..ace138c6f0374c10191072d2fee5d013e795e3dd 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java @@ -11,7 +11,7 @@ import org.springframework.data.repository.query.Param; * This interface defines the methods for the recipe repository * * @author Stian Lyng - * @version 1.0 + * @version 2.0 */ public interface RecipeRepository extends JpaRepository<Recipe, Long> { @@ -22,6 +22,11 @@ public interface RecipeRepository extends JpaRepository<Recipe, Long> { */ List<Recipe> findAllByName(String name); + /** + * Gets a weekly menu for a fridge + * @param fridgeId the id of the fridge + * @return a list of objects containing the name of the product and the id of the fridge + */ @Query( value = """ select p2.item_name, f.fridge_id from fridge f @@ -29,7 +34,11 @@ public interface RecipeRepository extends JpaRepository<Recipe, Long> { inner join product p2 on p2.ean = fp.ean """, nativeQuery = true) List<Object[]> findWeeklyMenu(long fridgeId); - + + /** + * Gets a list of recipes with their products + * @return a list of objects containing the recipe id, name, description, image url and product name + */ @Query( value = """ SELECT r.recipe_id, r.recipe_name, r.recipe_description, r.image_url, p.item_name FROM recipe r diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java index b4dfbe259e81c36e2a8bfbd9170f9b7945d6d9d6..f0dd168099ad926833f0f6a438c60d98614a632b 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java @@ -9,10 +9,8 @@ import org.springframework.data.jpa.repository.JpaRepository; /** * This interface defines the methods for the shopping list repository * - * @author Stian Lyng + * @author Stian Lyng, Birk * @version 1.2 - * @since 19.04.2023 - * */ public interface ShoppingListRepository extends JpaRepository<ShoppingList, Long> { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/UserGroupAssoRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/UserGroupAssoRepository.java index 07d3739543d9d39527e01eac24b404b0e3621d2e..9122768a25afb84e1692f9b5a86afb54279878d0 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/UserGroupAssoRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/UserGroupAssoRepository.java @@ -10,6 +10,12 @@ import org.springframework.data.jpa.repository.Query; import java.util.List; import java.util.Optional; +/** + * Repository interface for the UserGroupAsso association entity + * + * @author Pedro, Birk, Anders + * @version 1.3 + */ public interface UserGroupAssoRepository extends JpaRepository<UserGroupAsso, UserGroupId> { @@ -70,7 +76,7 @@ public interface UserGroupAssoRepository extends JpaRepository<UserGroupAsso, Us * Finds the authority level of a user in a group * @param username the username of the user * @param groupId the id of the group - * @return + * @return the authority level of the user in the group */ String findAuthorityByUser_UsernameAndGroup_GroupId(String username, long groupId); diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/WasteRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/WasteRepository.java index 02b4266434c4dcddd63c9a7fe411a058c6a4a182..aaa41eb7248df4b21f53cbb0298226ecf7d64fa3 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/WasteRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/group/WasteRepository.java @@ -9,6 +9,12 @@ import org.springframework.data.repository.query.Param; import java.util.Optional; +/** + * Repository for waste + * + * @author Anders, Pedro + * @version 1.1 + */ public interface WasteRepository extends JpaRepository<Waste, Long> { Optional<List<Waste>> findByGroupId( Group groupId); @@ -25,6 +31,10 @@ public interface WasteRepository extends JpaRepository<Waste, Long> { Optional<List<Waste>> findAllWasteOfOneCategoryFromGroup(@Param("groupId") long groupId, @Param("categoryName") String categoryName); + /** + * Gets the last added waste item + * @return the id of the last added waste item + */ @Query(value = "SELECT waste_id FROM wastes ORDER BY waste_id ASC",nativeQuery = true) long getLastWaste(); diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/CategoryRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/CategoryRepository.java index 6c7db2f19f4f3f155d02b4eefb92043d14c64d96..eb0f9642cf5d3e1239b88dfcfc8b0d9e1403816e 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/CategoryRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/CategoryRepository.java @@ -3,5 +3,11 @@ package ntnu.idatt2016.v233.SmartMat.repository.product; import ntnu.idatt2016.v233.SmartMat.entity.product.Category; import org.springframework.data.jpa.repository.JpaRepository; +/** + * Repository for categories + * + * @author Birk + * @version 1.0 + */ public interface CategoryRepository extends JpaRepository<Category, String> { } diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/FridgeProductAssoRepo.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/FridgeProductAssoRepo.java index 6cddba89479f9259f779d6c2604dc8d8c8debb28..f0e2d84a880d1aef1fd578eb1f5dbecf66e3b345 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/FridgeProductAssoRepo.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/FridgeProductAssoRepo.java @@ -5,6 +5,17 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; +/** + * Repository for fridge product associations + * + * @author Birk, Pedro + * @version 1.1 + */ public interface FridgeProductAssoRepo extends JpaRepository<FridgeProductAsso, Long> { + /** + * Finds all fridge product associations by id + * @param id the id of the fridge product association + * @return an optional holding the fridge product association with the given id if it exists + */ Optional<FridgeProductAsso> findAllById(long id); } diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/ProductRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/ProductRepository.java index ea88f235df4a6238b1f31ee7cc6d649859ac5630..ccf04933af2ed2946209fb486c3b18fc532d3a52 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/ProductRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/product/ProductRepository.java @@ -9,8 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository; /** * Repository for Products * @author Birk & Stian - * @version 1.0 - * @since 19.04.2023 + * @version 1.1 */ public interface ProductRepository extends JpaRepository<Product, Long> { @@ -20,4 +19,5 @@ public interface ProductRepository extends JpaRepository<Product, Long> { * @param name the name of the group * @return an optional containing the product if it exists */ - Optional<Product> getByName(String name);} + Optional<Product> getByName(String name); +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/AchievementRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/AchievementRepository.java index bcad340539d23afec160bcc4b0e9b2d7a429b24c..b702e3496b105cb93d8146b7d0dafb959944ea5d 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/AchievementRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/AchievementRepository.java @@ -10,7 +10,6 @@ import java.util.Optional; * * @author Anders * @version 1.0 - * @since 19.04.2023 */ public interface AchievementRepository extends JpaRepository<Achievement, String> { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/UserRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/UserRepository.java index 79aa716ab297b1116bfb4d217b3ce6df720a2fbf..20ef5b7ccbc83475a4ec5e4fd15cd503fa602626 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/UserRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/user/UserRepository.java @@ -7,11 +7,8 @@ import java.util.Optional; /** * repo for user entity - * uses mysql from server when ran - * uses h2 in memory database when testing * @author birk * @version 1.1 - * @since 20.04.2023 */ public interface UserRepository extends JpaRepository<User, Long>{ diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/AllergyService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/AllergyService.java index 168345c8a53d7e79a2bf83643a6bd88cc7557401..20fa670787178e384f2964f0a7c3c68b0e27d6c0 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/AllergyService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/AllergyService.java @@ -14,14 +14,10 @@ import ntnu.idatt2016.v233.SmartMat.repository.AllergyRepository; /** * Service for allergies * @author Stian Lyng - * @version 1.0 */ @Service public class AllergyService { - - /** - * Repository for allergies - */ + @Autowired private AllergyRepository allergyRepository; diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/RecipeService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/RecipeService.java index 4d894a1a1905a22fb8279885ca3c4d4d65ae953d..04a38cb5573a47d211777de2a5945a1861ebe391 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/RecipeService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/RecipeService.java @@ -24,15 +24,12 @@ import org.springframework.stereotype.Service; /** * This class defines the methods for the recipe service * - * @author Stian Lyng - * @version 1.0 + * @author Stian Lyng, Birk + * @version 1.1 */ @Service public class RecipeService { - - /** - * The recipe repository - */ + @Autowired private RecipeRepository recipeRepository; @@ -41,7 +38,7 @@ public class RecipeService { /** * Creates a new recipe service - * @param recipeRepository + * @param recipeRepository the recipe repository */ public RecipeService (RecipeRepository recipeRepository) { this.recipeRepository = recipeRepository; @@ -177,14 +174,11 @@ public class RecipeService { * @return A list of RecipeWithMatchCount objects representing the weekly menu */ public List<RecipeWithMatchCount> getWeeklyMenu(Integer fridgeId) { - // Get the results from both repository methods List<Object[]> weeklyMenu = recipeRepository.findWeeklyMenu(fridgeId); List<Object[]> recipeProducts = recipeRepository.findRecipeProductsWithName(); - // Prepare a map to store RecipeDetails with their match count Map<RecipeDetails, Integer> recipeMatchCountMap = new HashMap<>(); - // Compare the item_name on both lists for (Object[] menuRow : weeklyMenu) { String menuRowItemName = ((String) menuRow[0]).toLowerCase(); for (Object[] recipeProductRow : recipeProducts) { @@ -206,18 +200,15 @@ public class RecipeService { } } - // Get a list of unique RecipeDetails from recipeProducts List<RecipeDetails> uniqueRecipeDetails = recipeProducts.stream() .map(row -> new RecipeDetails(((Integer) row[0]).intValue(), (String) row[1], (String) row[2], (String) row[3])) .distinct() .collect(Collectors.toList()); - // Convert the map to a list of RecipeWithMatchCount List<RecipeWithMatchCount> commonRecipes = recipeMatchCountMap.entrySet().stream() .map(entry -> new RecipeWithMatchCount(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); - // Add additional recipes from uniqueRecipeDetails with a count of 0 if the list has less than 5 recipes List<RecipeWithMatchCount> zeroMatchRecipes = new ArrayList<>(); for (RecipeDetails recipeDetails : uniqueRecipeDetails) { if (commonRecipes.size() < 5 && !recipeMatchCountMap.containsKey(recipeDetails)) { @@ -225,10 +216,8 @@ public class RecipeService { } } - // Shuffle the zeroMatchRecipes list Collections.shuffle(zeroMatchRecipes); - // Combine the commonRecipes and zeroMatchRecipes lists for (RecipeWithMatchCount zeroMatchRecipe : zeroMatchRecipes) { if (commonRecipes.size() < 5) { commonRecipes.add(zeroMatchRecipe); diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java index c56b1c27c84caf834059a9eccb485e35b354354e..2d5701c93820fd18f97dc73b27b9776ba580c8b1 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java @@ -13,7 +13,7 @@ import ntnu.idatt2016.v233.SmartMat.repository.ShoppingListRepository; /** * Service for the shopping list * - * @author Stian Lyng + * @author Stian Lyng, Birk * @version 1.1 */ @Service diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/TokenService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/TokenService.java index e2caee18c54df6a6d0b923726aa2d925fe17b512..6f83285bf463003a8b8901b1089ad2ce5519ac80 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/TokenService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/TokenService.java @@ -15,7 +15,6 @@ import java.util.stream.Collectors; * This class is used to generate a JWT token. * @author Anders * @version 1.0 - * @since 22.03.2023 */ @Service public class TokenService { @@ -24,7 +23,6 @@ public class TokenService { /** * Creates a new TokenService object. - * The encoder object is injected by Spring. * * @param encoder the JwtEncoder object to use */ diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java index 8965be1d7bf2c390a0420fffd4f13a01b9593c33..2fedb932097f72b492e003266d59c5788f42a3ed 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java @@ -26,7 +26,7 @@ public class WeeklyMenuService { * Retrieves the top 5 recipes with products that have a match with items in the given fridge. * Returns a list of RecipeWithProductsDTO objects with recipe details and product information. * - * @param groupId the ID of the fridge to use for matching products + * @param fridgeId the ID of the fridge to use for matching products * @return a list of RecipeWithProductsDTO objects with recipe and product details */ public List<WeeklyMenuResponse> getWeeklyMenu(long fridgeId) { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java index 74295864fe25b35a3b7e1c2f5c32c0e17c7906a4..e7ae96f171e7aedb2624f7a5f8363f474e53c0ec 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/FridgeService.java @@ -28,7 +28,6 @@ import java.util.Optional; * * @author Anders Austlid & Birk * @version 2 - * @since 05.05.2023 */ @AllArgsConstructor @Service @@ -92,7 +91,12 @@ public class FridgeService { return product; } - + + /** + * Updates a product in the fridge of a group + * @param request the fridge product request + * @return the product that was added to the fridge + */ public Optional<FridgeProductAsso> updateProductInFridge(FridgeProductRequest request) { Optional<FridgeProductAsso> fridgeProductAsso = fridgeProductAssoRepo.findById(request.fridgeProductId()); if (fridgeProductAsso.isEmpty()) return Optional.empty(); diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/GroupService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/GroupService.java index e8b2b4d6797a8e2c219f4ae05cb245564bdb22fc..fb3e22f7e9958b0878bb09fe236237f896648002 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/GroupService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/GroupService.java @@ -20,9 +20,8 @@ import java.util.Optional; /** * Service for groups * - * @author Anders Austlid & Birk - * @version 1.2 - * @since 26.04.2023 + * @author Anders Austlid, Birk, Pedro + * @version 1.3 */ @AllArgsConstructor @Service @@ -166,6 +165,11 @@ public class GroupService { return Optional.of(groupRepository.save(group)); } + /** + * Gets a group by its link code + * @param linkCode the link code of the group + * @return an optional containing the group if it exists + */ public Optional<Group> getGroupByLinkCode(String linkCode) { return groupRepository.findByLinkCode(linkCode); } @@ -219,6 +223,12 @@ public class GroupService { return userGroupAssoRepository.findById(userGroupId); } + /** + * Gets the authority of a user group association + * @param username the username of the user + * @param groupId the id of the group + * @return the authority of the user group association + */ public String getUserGroupAssoAuthority(String username, long groupId) { Optional<UserGroupAsso> userGroupAsso = getUserGroupAsso(username, groupId); return userGroupAsso.map(UserGroupAsso::getGroupAuthority).orElseThrow(() -> new IllegalArgumentException("User is not associated with group")); @@ -236,8 +246,7 @@ public class GroupService { /** * removes user_group relatioon - * @param username the username of the user - * @param groupId the id of the group + * @param userGroup the user group association to remove * @return true if the user is the owner of the group, false otherwise */ @Transactional diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/WasteService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/WasteService.java index 3272f026f1921a22e53f2a727492346abe2a8713..20615c62e65ba9805211656fc5c924d57dca563c 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/WasteService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/group/WasteService.java @@ -20,9 +20,8 @@ import java.util.Optional; /** * Service for waste - * @author Pedro, Birk + * @author Anders, Pedro, Birk * @version 1.1 - * @since 04.05.2023 */ @Service @AllArgsConstructor diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/CategoryService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/CategoryService.java index 3e6698264d242fa99c11a51627d15e5b7a024ba2..48765c3578f908b1474a74fe444b26e38dc460f8 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/CategoryService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/CategoryService.java @@ -11,7 +11,6 @@ import java.util.Optional; * Service for Categories * @version 1.0 * @Author Birk - * @since 26.04.2020 */ @Service @AllArgsConstructor diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/ProductService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/ProductService.java index 9e55d02b86903873e82b2b3ebabf2d5629c0cb78..1d526e4924d78f85f2ae9320b50990a74225355e 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/ProductService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/product/ProductService.java @@ -13,7 +13,6 @@ import java.util.Optional; * uses both the ProductRepository and the ProductUtil * @author Birk * @version 1.1 - * @since 05.04.2023 */ @Service public class ProductService { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/AchievementService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/AchievementService.java index 83a781c445438cbb20148da93d8ee93519ce5762..7ef5c28bb2f00ca939d49679fdf75d6a54440c0e 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/AchievementService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/AchievementService.java @@ -13,7 +13,6 @@ import java.util.Optional; * * @author Anders * @version 1.0 - * @since 19.04.2023 */ @Service @@ -31,6 +30,10 @@ public class AchievementService { return achievementRepository.findByAchievementName(achievementName); } + /** + * Gets all achievements from the database + * @return a list of all achievements + */ public List<Achievement> getAchievements(){ return achievementRepository.findAll(); } diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/JpaUserDetailsService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/JpaUserDetailsService.java index d260ad8c01416997ec95480a761d2154a09a23ee..d256685ad22395e6ad97e1391a34f16f3c54cb0e 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/JpaUserDetailsService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/JpaUserDetailsService.java @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; * JpaUserDetailsService is a class that implements the UserDetailsService interface. * @author Birk * @version 1.0 - * @since 05.04.2023 */ @Service @AllArgsConstructor @@ -21,7 +20,7 @@ public class JpaUserDetailsService implements UserDetailsService { * gets user from username out of database * @param username username of user * @return user - * @throws UsernameNotFoundException + * @throws UsernameNotFoundException if user is not found */ @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/UserService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/UserService.java index 3c21d1971e071e2498c5432d7c982662ebd39799..7dc252ed2df343c200ede3430235873aae6bf2bf 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/UserService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/user/UserService.java @@ -21,9 +21,8 @@ import java.util.Optional; /** * UserService is a class that implements the UserDetailsService interface. - * @author Birk + * @author Birk, Stian * @version 1.1 - * @since 20.04.2023 */ @Service @AllArgsConstructor @@ -43,6 +42,10 @@ public class UserService { public Optional<User> getUserFromUsername(String username){ return userRepository.findByUsername(username); } + + /** + * Gets all users from the database + */ public List<User> getUsers(){ return userRepository.findAll(); } diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/CategoryUtil.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/CategoryUtil.java index 17b4771d51248c2e39d2e2f6733d83fb2c02f179..233458c218084c6b0b6a9d855c10d805cd9f5f3f 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/CategoryUtil.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/CategoryUtil.java @@ -6,7 +6,6 @@ import java.util.*; * Utility class for category * @author Pedro Pablo Cardona * @version 1.0 - * @since 21.04.2023 */ public class CategoryUtil { @@ -29,6 +28,11 @@ public class CategoryUtil { "grappa", "kirsebærbrannvin", "sherry", "sider", "mjød" ); + /** + * Static method that returns a list of keywords for a given category. + * @param category The category to get keywords for. + * @return A list of keywords. + */ private static List<String> getCategoryKeywords(String category) { return switch (category) { case "meat, fish and chicken" -> MEAT; diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/GroupUtil.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/GroupUtil.java index 7e586b6161198f4cb5b80587d372d37181f1c28e..013af0e5896692cb2226ccc8c33aa1c2c0a8b28c 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/GroupUtil.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/GroupUtil.java @@ -9,7 +9,6 @@ import java.util.UUID; * * @author Pedro Cardona * @version 1.0 - * @since 25.04.2023 */ public class GroupUtil { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/ProductUtil.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/ProductUtil.java index d83bf6cf2cc8533484f972294c7185f7b096fbd4..a9e9242ada9542d37bcffd1d66b3dd0078949387 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/ProductUtil.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/ProductUtil.java @@ -11,12 +11,16 @@ import java.util.regex.Pattern; /** * Utility class for products - * @author Birk - * @version 1.0 - * @since 04.04.2023 + * @author Birk, Pedro + * @version 1.1 */ public class ProductUtil { + /** + * Gets volume from a product + * @param product the product to get volume from + * @return an optional containing a list of the volume and unit if it exists + */ public static Optional<List<String>> getVolumeFromProduct(Product product) { String total = product.getName() + " " + product.getDescription(); double amount = parseAmount(total); @@ -32,6 +36,11 @@ public class ProductUtil { return Optional.of(List.of(amount + "", unit)); } + /** + * Parses unit from a string + * @param input the string to parse unit from + * @return the unit + */ private static String parseUnit(String input) { Pattern pattern = Pattern.compile("(\\d+(\\.\\d+)?)\\s*(g|kg|l|ml|dl|cl|Kg|L|STK)\\b", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(input); @@ -44,6 +53,11 @@ public class ProductUtil { return "STK"; } + /** + * Parses amount from a string + * @param input the string to parse amount from + * @return the amount + */ private static double parseAmount(String input) { Pattern pattern = Pattern.compile("(\\d+(\\.\\d+)?)\\s*(g|kg|l|ml|dl|cl|Kg|L|STK)\\b", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(input); diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/StatisticUtil.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/StatisticUtil.java index 10fc25577b40d6320557ec62c6ebb2bb3171999a..9ef7a57c7de6cc2845fc8c44bb3dbb0fc9ecb64a 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/StatisticUtil.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/StatisticUtil.java @@ -15,7 +15,6 @@ import java.util.List; * A utility class for calculating statistics related to waste and CO2 emissions. * @author Pedro Cardona * @version 1.0 - * @since 03.05.2023 */ public class StatisticUtil { diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/Jwks.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/Jwks.java index 59f309bc244e4e66943e3f5e8b8904c1b0b941e1..31f3bc73c0582816e371e230ad88cf9ae38b2edf 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/Jwks.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/Jwks.java @@ -9,15 +9,11 @@ import java.util.UUID; /** * Jwks is a utility class for generating RSA keys for JSON Web Key Set (JWKS) support. * It provides a method to generate an RSA key pair and create an RSAKey object. - * @author Anders (young buck) + * @author Anders * @version 1.0 - * @since 04.04.2023 */ public class Jwks { - /** - * Private constructor to prevent instantiation of this utility class. - */ private Jwks() {} /** diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/KeyGeneratorUtils.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/KeyGeneratorUtils.java index cd36005771fe2594fe470c536526c026d23b4b89..029f38e2eb397ce3396bbb1c3b2399f8628b5315 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/KeyGeneratorUtils.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/util/rsa/KeyGeneratorUtils.java @@ -8,16 +8,12 @@ import java.security.KeyPairGenerator; * KeyGeneratorUtils is a utility class for generating key pairs, specifically RSA key pairs. * This class is marked as a Spring component to allow its use in the Spring framework. * - * @author Anders (young buck) + * @author Anders * @version 1.0 - * @since 04.04.2023 */ @Component final class KeyGeneratorUtils { - /** - * Private constructor to prevent instantiation of this utility class. - */ private KeyGeneratorUtils() {} /**