doc: CategoryService javadocs
This commit is contained in:
parent
95b0508cab
commit
9f77593498
1 changed files with 41 additions and 1 deletions
|
@ -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<Category> 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<Category> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<Category> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue