-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
폰드! 코드리뷰 남겼습니다!
@Entity | ||
@NoArgsConstructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
옵션을 통해 접근 제어자를 private
로 해보시
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 우테코 스타일 적용되어있나요??
*
로 임포트로 변환 되는걸 처음봐서 스타일 적용되었는지 확인해주세요
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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); | ||
|
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ingredient.sql에 레시피 정보를 저장하면 불필요한 레포지토리 의존을 줄일 수 있을것 같아요.
} | ||
|
||
@Test | ||
@DisplayName("재료 등록") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 디스플레이 네임을 컨벤션에 맞춰주세요
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어제 고생 많았습니다!! 수고했습니다!
There was a problem hiding this 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.*; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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은 허용하지 않는다.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ 테스트 코드 네이밍
- DisplayName은 꼭 사용해요.
- DisplayName
- 성공
- {행위}가 된다.
- 실패
- {상황}에 {행위}를 하면 예외가 발생한다.
- 성공
재료 이름에 공백 또는 null이 입력되면 예외가 발생한다.
어떨지요
private void registerIngredientSubstitution(IngredientRecipe ingredientRecipe, Ingredient substitution) { | ||
ingredientSubstitutionService.save(ingredientRecipe, substitution); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 메서드가... 꼭 필요한가요....???
정말 몰라서 물어보는 겁니다!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
가독성을 위해 생성하였습니다.
꼭 필요하진 않습니다!🥲
|
|
재료 등록
IngredientService
의register
메서드를 통해 재료 등록을 진행합니다.검증
재료 이름 공백/null, 중복
개별 재료에 대한 대체 재료 이름 공백/null, 중복