[EDIT] 名前で検索できる機能を追加しました。
This commit is contained in:
@@ -9,4 +9,6 @@ public interface CategoryService {
|
||||
public List<CategoryModel> findAll();
|
||||
|
||||
public CategoryModel findOne(Long categoryId);
|
||||
|
||||
public CategoryModel findOneByCategoryName(String categoryName);
|
||||
}
|
||||
|
||||
@@ -14,26 +14,38 @@ import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CategoryServiceImpl implements CategoryService{
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
private final CategoryRepository categoryRepository;
|
||||
|
||||
|
||||
public List<CategoryModel> findAll() {
|
||||
|
||||
|
||||
return CategoryModel.convertFrom(categoryRepository.findAll());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public CategoryModel findOne(Long categoryId) {
|
||||
|
||||
|
||||
Optional<CategoryEntity> optionalCategoryModel = categoryRepository.findById(categoryId);
|
||||
|
||||
|
||||
if (optionalCategoryModel.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return CategoryModel.convertFrom(optionalCategoryModel.get());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public CategoryModel findOneByCategoryName(String categoryName) {
|
||||
|
||||
CategoryEntity categoryModel = categoryRepository.findByCategoryName(categoryName);
|
||||
|
||||
if (categoryModel == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return CategoryModel.convertFrom(categoryModel);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user