Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public CategoryDTO updateCategory(CategoryDTO categoryDTO, Long categoryId) {
.orElseThrow(() -> new ResourceNotFoundException("Category","categoryId",categoryId));

Category category = modelMapper.map(categoryDTO, Category.class);

//To implement unique categoryName before updating the record.
Category savedCategoryName = categoryRepository.findByCategoryName(category.getCategoryName());

if(savedCategoryName != null){
throw new APIException("Category with name " + category.getCategoryName() + " already exists!");
}

category.setCategoryId(categoryId);
savedCategory = categoryRepository.save(category);
return modelMapper.map(savedCategory, CategoryDTO.class);
Expand Down