[EDIT] 特定のカテゴリレコードを取得するサービスメソッドを作成しました。
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.CategoryModel;
|
||||
import com.example.demo.app.domain.service.CategoryService;
|
||||
import com.example.demo.app.infra.entity.CategoryEntity;
|
||||
import com.example.demo.app.infra.repository.CategoryRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -22,4 +24,16 @@ public class CategoryServiceImpl implements CategoryService{
|
||||
|
||||
}
|
||||
|
||||
public CategoryModel findOne(Long categoryId) {
|
||||
|
||||
Optional<CategoryEntity> optionalCategoryModel = categoryRepository.findById(categoryId);
|
||||
|
||||
if (optionalCategoryModel.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return CategoryModel.convertFrom(optionalCategoryModel.get());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import com.example.demo.app.infra.entity.CategoryEntity;
|
||||
|
||||
public interface CategoryRepository extends JpaRepository<CategoryEntity, Long> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user