Skip to content

feat: 재료 조회 기능 구현#9

Merged
yunjaeeun merged 1 commit intodevelopfrom
hongbeom
Dec 12, 2024
Merged

feat: 재료 조회 기능 구현#9
yunjaeeun merged 1 commit intodevelopfrom
hongbeom

Conversation

@KIM9909
Copy link
Copy Markdown
Contributor

@KIM9909 KIM9909 commented Dec 11, 2024

  1. Controller에서 GetMapping 어노테이션으로 API 진입지점을 만들고 조회 메서드를 추가해주었습니다.
// 재료 조회
@GetMapping
public List<IngredientResponse> getIngredient() {
    return ingredientService.getIngredient();
}
  1. IngredientResponse 클래스를 만들어 Entity와 DB가 매핑되는 객체로 유지될 수 있도록 계층분리를 해주었습니다.

  2. IngredientService인터페이스에 조회 메서드를 만들어 주어서 함께 ServiceImpl에 상속될 수 있도록 하였습니다.

public interface IngredientService {
    void createIngredient(IngredientCreateRequest request); // 재료 등록 메서드
    List<IngredientResponse> getIngredient(); // 재료 조회 메서드
}
  1. IngredientServiceImpl에서는 ModelMapper를 활용해서 등록한 모든 재료들을 조회할 수 있도록 하였습니다.
@Override
@Transactional(readOnly = true)
public List<IngredientResponse> getIngredient() {
    List<IngredientManagement> ingredients = ingredientManagementRepository.findAll();

    return ingredients.stream()
            .map(ingredient -> mapper.map(ingredient, IngredientResponse.class))
            .collect(Collectors.toList());
}

image

Copy link
Copy Markdown
Contributor

@LeeGukgeon LeeGukgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapper를 활용한 재료 조회 메서드를 깔끔하게 구현한 것 같습니다

@MinFe4990 MinFe4990 self-requested a review December 11, 2024 08:28
Copy link
Copy Markdown
Contributor

@MinFe4990 MinFe4990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check!!

Copy link
Copy Markdown
Contributor

@kingkang85 kingkang85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dto와 service 계층이 잘 분리되어 있고, ModelMapper를 사용해 엔티티와 dto 간 변환을 잘 처리해준 것 같습니다!

@uni-zun
Copy link
Copy Markdown
Contributor

uni-zun commented Dec 12, 2024

흠 잡을게 없네요.

@yunjaeeun
Copy link
Copy Markdown
Contributor

재료 조회할 떄 카테고리도 같이 줘야될거같아요

@yunjaeeun yunjaeeun merged commit a30afd5 into develop Dec 12, 2024
@uni-zun uni-zun mentioned this pull request Dec 22, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants