Class CategoryServiceImpl
java.lang.Object
com.glowmart.shop_management.service.implementation.CategoryServiceImpl
- All Implemented Interfaces:
CategoryService
Implementation of
CategoryService that provides business logic
for managing Category entities.
This service handles creation, updating, deletion, and retrieval of categories.
It performs validation on input data, ensures uniqueness of category names,
and throws appropriate custom exceptions such as NotValidException,
DuplicateException, and NotFoundException.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateCategory(CategoryDto categoryDto) Creates a new category after validating its name and ensuring uniqueness.Deletes a category by its ID.Retrieves all categories from the repository.Retrieves a category by its ID.getCategoryByName(String name) Retrieves a category by its name.updateCategoryById(String id, CategoryDto categoryDto) Updates an existing category by its ID.
-
Constructor Details
-
CategoryServiceImpl
public CategoryServiceImpl()
-
-
Method Details
-
createCategory
Creates a new category after validating its name and ensuring uniqueness.- Specified by:
createCategoryin interfaceCategoryService- Parameters:
categoryDto- the DTO containing category details- Returns:
- the created
CategoryDto - Throws:
NotValidException- if the category name is invalidDuplicateException- if a category with the same name already exists
-
updateCategoryById
Updates an existing category by its ID.- Specified by:
updateCategoryByIdin interfaceCategoryService- Parameters:
id- the ID of the category to updatecategoryDto- the DTO containing updated category details- Returns:
- the updated
CategoryDto - Throws:
NotValidException- if the ID or category name is invalidNotFoundException- if no category exists with the given IDDuplicateException- if the new category name already exists or matches the old one
-
deleteCategoryById
Deletes a category by its ID.- Specified by:
deleteCategoryByIdin interfaceCategoryService- Parameters:
id- the ID of the category to delete- Returns:
- the deleted
CategoryDto - Throws:
NotValidException- if the ID is invalidNotFoundException- if no category exists with the given ID
-
getAllCategory
Retrieves all categories from the repository.- Specified by:
getAllCategoryin interfaceCategoryService- Returns:
- a list of
CategoryDtorepresenting all categories
-
getCategoryById
Retrieves a category by its ID.- Specified by:
getCategoryByIdin interfaceCategoryService- Parameters:
id- the ID of the category to retrieve- Returns:
- the found
CategoryDto - Throws:
NotValidException- if the ID is invalidNotFoundException- if no category exists with the given ID
-
getCategoryByName
Retrieves a category by its name.- Specified by:
getCategoryByNamein interfaceCategoryService- Parameters:
name- the name of the category to retrieve- Returns:
- the found
CategoryDto - Throws:
NotValidException- if the name is invalidNotFoundException- if no category exists with the given name
-