diff --git a/src/main/java/com/application/munera/services/CategoryService.java b/src/main/java/com/application/munera/services/CategoryService.java index 5cf8c0b..e5944dc 100644 --- a/src/main/java/com/application/munera/services/CategoryService.java +++ b/src/main/java/com/application/munera/services/CategoryService.java @@ -18,31 +18,71 @@ public class CategoryService { this.categoryRepository = categoryRepository; } + /** + * Finds a category by its ID. + * + * @param id the ID of the category to find + * @return an {@code Optional} containing the found category, or {@code Optional.empty()} if no category with the given ID exists + */ public Optional findById(Long id) { return categoryRepository.findById(id); } + /** + * Finds all categories associated with a specific user ID. + * + * @param userId the ID of the user whose categories are to be retrieved + * @return a {@code List} of categories associated with the given user ID + */ public List findAllByUserId(Long userId) { return categoryRepository.findByUserId(userId); } + /** + * Updates the provided category and associates it with a specific user ID. + * + * @param category the category to update + * @param userId the ID of the user to associate with the category + */ public void update(Category category, Long userId) { category.setUserId(userId); - categoryRepository.save(category ); + categoryRepository.save(category); } + /** + * Deletes the given category. + * + * @param category the category to delete + */ public void delete(Category category) { categoryRepository.delete(category); } + /** + * Retrieves a paginated list of categories. + * + * @param pageable the pagination information + * @return a {@code Page} containing the categories for the requested page + */ public Page list(Pageable pageable){ return categoryRepository.findAll(pageable); } + /** + * Counts the total number of categories. + * + * @return the total number of categories + */ public Long count() { return this.categoryRepository.count(); } + /** + * Saves the given category to the repository. + * + * @param category the category to save + * @return the saved category + */ public Category save(Category category) { return this.categoryRepository.save(category); }