Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ implement ingredient registration #78

Merged
merged 18 commits into from
Jul 25, 2024
Merged

✨ implement ingredient registration #78

merged 18 commits into from
Jul 25, 2024

Conversation

tackyu
Copy link

@tackyu tackyu commented Jul 24, 2024

재료 등록

IngredientServiceregister 메서드를 통해 재료 등록을 진행합니다.

  1. Ingredient 등록
  2. IngredientRecipe 등록
  3. 재료가 '대체 가능'한 상태라면 IngredientSubstitution 등록

검증

재료 이름 공백/null, 중복
개별 재료에 대한 대체 재료 이름 공백/null, 중복

@tackyu tackyu requested review from HaiSeong and hyxrxn July 24, 2024 05:11
@tackyu tackyu added ✨ feature new feature BE Backend labels Jul 24, 2024
@tackyu tackyu self-assigned this Jul 24, 2024
Copy link

Overall Project 88.94% -0.99% 🍏
Files changed 95.05% 🍏

File Coverage
IngredientRecipeService.java 100% 🍏
IngredientSubstitutionService.java 100% 🍏
IngredientCreateRequest.java 100% 🍏
IngredientService.java 91.03% -8.97% 🍏
Ingredient.java 80% 🍏
IngredientSubstitution.java 71.43% 🍏
IngredientRecipe.java 66.67% 🍏

Copy link

@HaiSeong HaiSeong left a comment

Choose a reason for hiding this comment

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

폰드! 코드리뷰 남겼습니다!

@Entity
@NoArgsConstructor

Choose a reason for hiding this comment

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

옵션을 통해 접근 제어자를 private로 해보시

Choose a reason for hiding this comment

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

protected로 정정합니다


public Ingredient(String name) {
this.name = name;
}

Choose a reason for hiding this comment

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

@AllArgumentConstructor 사용후 this(0L, ...) 으로 초기화 해도 좋을것 같아요.
Category 도메인 참고 해보시죠

import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;

Choose a reason for hiding this comment

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

혹시 우테코 스타일 적용되어있나요??
* 로 임포트로 변환 되는걸 처음봐서 스타일 적용되었는지 확인해주세요

Copy link
Contributor

Choose a reason for hiding this comment

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

구글 자바 컨벤션

3.3.1 No wildcard imports

Wildcard imports, static or otherwise, are not used.


private void validateName(String name) {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("name cannot be null or empty");

Choose a reason for hiding this comment

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

이제 커스텀 예외가 생겼으니 IngredientException 를 상속받아서 새로운 예외를 반환해주세요!

}
}

private Ingredient registerIngredient(String ingredientName) {

Choose a reason for hiding this comment

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

있으면 조회해서 가져오는 분기도 있는데 메서드명을 보면 "재료를 저장한다." 라는 의미밖에 없네요.
registerOrGetIngredient 는 어떤가요?


boolean existsByName(String name);

Ingredient findByName(String name);

Choose a reason for hiding this comment

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

findByName 과 getByName 의 차이를 공부해보면 알아보면 좋을것 같아요.

저도 User 쪽 가서 수정해야겠네요.

find : 찾아본다. (있을 수도 있고 없을수도 있음. 없어도 예외 x, Optional로 반환이 일반적)

get : 가져온다. (있어야 한다. 없으면 예외)

return ingredientRepository.findByName(name);
}

return ingredientRepository.save(new Ingredient(name));

Choose a reason for hiding this comment

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

카테고리 코드쪽에 좋은 로직이 있어서 참고해보시면 좋을것 같아요

        Category category = categoryRepository.findByName(name)
                .orElseGet(() -> categoryRepository.save(new Category(name)));

private void registerSubstitution(IngredientCreateRequest request, IngredientRecipe ingredientRecipe) {
List<String> substitutionNames = request.substitutions();
validateDuplicateNames(substitutionNames);

Choose a reason for hiding this comment

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

registerSubstitution 메서드와 registerIngredientSubstitution 이 메서드를 private 보다 IngredientRecipeService와 IngredientSubstitutionService의 public 메서드로 해보는것은 어떨까요?

IngredientSubstitution을 저장하는것은 IngredientSubstitutionService의 책임인데 이걸 IngredientService가 대신 해주고 있는것 같아요.

또한 Private 메서드라 테스트가 어려워요.

@BeforeEach
void setUp() {
User author = userRepository.findById(1L).get();
Recipe recipe = new Recipe(

Choose a reason for hiding this comment

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

ingredient.sql에 레시피 정보를 저장하면 불필요한 레포지토리 의존을 줄일 수 있을것 같아요.

}

@Test
@DisplayName("재료 등록")

Choose a reason for hiding this comment

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

테스트 디스플레이 네임을 컨벤션에 맞춰주세요

Copy link

Overall Project 90.25% -0.6% 🍏
Files changed 97.14% 🍏

File Coverage
InvalidNameException.java 100% 🍏
IngredientRecipeService.java 100% 🍏
IngredientSubstitutionService.java 100% 🍏
IngredientCreateRequest.java 100% 🍏
IngredientService.java 94.23% -5.77% 🍏
Ingredient.java 86.96% 🍏
IngredientSubstitution.java 80% 🍏
IngredientRecipe.java 75.68% 🍏

@tackyu tackyu requested a review from HaiSeong July 25, 2024 02:06
Copy link

@HaiSeong HaiSeong left a comment

Choose a reason for hiding this comment

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

어제 고생 많았습니다!! 수고했습니다!

Copy link
Contributor

@hyxrxn hyxrxn left a comment

Choose a reason for hiding this comment

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

잘 읽었습니다~~~
대체재료 때문에 꽤나 힘드셨겠어요
고생하셨습니다

import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

구글 자바 컨벤션

3.3.1 No wildcard imports

Wildcard imports, static or otherwise, are not used.


import net.pengcook.ingredient.domain.IngredientRecipe;

@Repository
Copy link
Contributor

Choose a reason for hiding this comment

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

이거 어노테이션 없어도 된대요
JpaRepository면 Spring Data JPA가 알아서 구현체를 주입해준다고 하네요!

"''",
"' '",
})
@DisplayName("재료 이름에 공백 또는 null은 허용하지 않는다.")
Copy link
Contributor

Choose a reason for hiding this comment

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

✅ 테스트 코드 네이밍

  • DisplayName은 꼭 사용해요.
  • DisplayName
    • 성공
      • {행위}가 된다.
    • 실패
      • {상황}에 {행위}를 하면 예외가 발생한다.

재료 이름에 공백 또는 null이 입력되면 예외가 발생한다.
어떨지요

Comment on lines +69 to +71
private void registerIngredientSubstitution(IngredientRecipe ingredientRecipe, Ingredient substitution) {
ingredientSubstitutionService.save(ingredientRecipe, substitution);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

이 메서드가... 꼭 필요한가요....???
정말 몰라서 물어보는 겁니다!!!

Copy link
Author

Choose a reason for hiding this comment

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

가독성을 위해 생성하였습니다.
꼭 필요하진 않습니다!🥲

Copy link

Overall Project 90.25% -0.6% 🍏
Files changed 97.14% 🍏

File Coverage
InvalidNameException.java 100% 🍏
IngredientRecipeService.java 100% 🍏
IngredientSubstitutionService.java 100% 🍏
IngredientCreateRequest.java 100% 🍏
IngredientService.java 94.23% -5.77% 🍏
Ingredient.java 86.96% 🍏
IngredientSubstitution.java 80% 🍏
IngredientRecipe.java 75.68% 🍏

Copy link

Overall Project 89.63% -0.57% 🍏
Files changed 97.14% 🍏

File Coverage
InvalidNameException.java 100% 🍏
IngredientRecipeService.java 100% 🍏
IngredientSubstitutionService.java 100% 🍏
IngredientCreateRequest.java 100% 🍏
IngredientService.java 94.23% -5.77% 🍏
Ingredient.java 86.96% 🍏
IngredientSubstitution.java 80% 🍏
IngredientRecipe.java 75.68% 🍏

@tackyu tackyu merged commit cca2971 into be/dev Jul 25, 2024
1 check passed
@tackyu tackyu deleted the be/feat/24 branch July 25, 2024 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE Backend ✨ feature new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants