-
Notifications
You must be signed in to change notification settings - Fork 75
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
[team-03][BackEnd] todo-list 2주차 두번째 #228
base: team-03
Are you sure you want to change the base?
Conversation
- CarsResponse 생성로직 생성자로 분리 - Enum 생성해서 기존 Location 하드코딩 개선
- insert, update, delete, findAll, updateLocation 테스트코드 작성
…to dev/backend
- Delete와 Move를 CardService에서 담당. - 추후 AOP를 통한 구현도 고려해볼만함.
…to dev/backend
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.
안녕하세요. 짱민 & 노리, 리뷰어 dion입니다.
첫번째 협업 프로젝트를 진행하느라 정말 수고 많으셨습니다~
CardRepository
테스트 열심히 진행해주셨네요. 몇가지 조언할 것이 있어 남겨두었으니 참고해주세요!
그리고 주석을 잘 작성해주는 것도 중요하긴 한데, 쓸모없는 주석을 남기지 않는 것이 더 중요합니다. 참고해주세요!
몇 가지 아쉬운 부분이 있어 변경요청을 드리니 확인하고 수정해주세요~ 고생하셨습니다.
cardRepository.delete(cardId); | ||
|
||
historyService.add(new History("remove", card.getTitle(), Optional.ofNullable(pastLocation), card.getCurrentLocation(), |
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.
왜 Optional을 인자로 넣어서 생성해주셨나요??
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.
"remove"라는 문자열은 상수로 관리하거나 Enum을 쓰는게 낫지 않을까요?
public void update(Long cardId, CardUpdateFormRequest request) { | ||
Card card = cardRepository.findById(cardId) | ||
.orElseThrow(() -> new IllegalArgumentException("카드를 찾을 수 없습니다.")); | ||
.orElseThrow(() -> new NoSuchElementException("카드를 찾을 수 없습니다.")); | ||
|
||
card.update(request.getTitle(), request.getContent()); | ||
cardRepository.update(card); | ||
} | ||
|
||
public Card findOne(Long cardId) { | ||
Card card = cardRepository.findById(cardId) | ||
.orElseThrow(() -> new IllegalArgumentException("카드를 찾을 수 없습니다.")); | ||
.orElseThrow(() -> new NoSuchElementException("카드를 찾을 수 없습니다.")); | ||
return card; | ||
} | ||
|
||
public CardsResponse findAll() { | ||
List<Card> cards = cardRepository.findAll(); | ||
|
||
return createCardsResponse(cards); | ||
} | ||
|
||
private CardsResponse createCardsResponse(List<Card> cards) { | ||
CardsResponse cardsResponse = new CardsResponse(); | ||
|
||
List<CardResponse> todos = new ArrayList<>(); | ||
List<CardResponse> ings = new ArrayList<>(); | ||
List<CardResponse> dones = new ArrayList<>(); | ||
|
||
for (Card card : cards) { | ||
if (card.getCurrentLocation().equals("todo")) { | ||
todos.add(new CardResponse(card)); | ||
} else if (card.getCurrentLocation().equals("ing")) { | ||
ings.add(new CardResponse(card)); | ||
} else if (card.getCurrentLocation().equals("done")) { | ||
dones.add(new CardResponse(card)); | ||
} | ||
} | ||
|
||
cardsResponse.putCards("todo", todos); | ||
cardsResponse.putCards("ing", ings); | ||
cardsResponse.putCards("done", dones); | ||
|
||
return cardsResponse; | ||
return new CardsResponse(cardRepository.findAll()); |
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.
여기에는 @Transactional
이 필요없나요?
public void add(History history) { | ||
|
||
historyRepository.insert(history); | ||
} |
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.
여기서는 @Transactional
필요가 없나요~~?
@@ -17,7 +17,7 @@ public void addInterceptors(InterceptorRegistry registry) { | |||
registry.addInterceptor(historyMakerInterCeptor) | |||
.order(1) | |||
.addPathPatterns("/card") | |||
.addPathPatterns("/card/{cardId}") | |||
//.addPathPatterns("/card/{cardId}"); // 서비스단으로 옮김 |
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.
사용하지 않는 코드는 제거해주세요.
public void removeCard(@PathVariable("cardId") Long cardId) { | ||
// putHistoryDataToRequest(request, "remove", null, cardService.findOne(cardId)); | ||
|
||
cardService.remove(cardId); | ||
} | ||
|
||
@PatchMapping("/card/move/{cardId}") | ||
public void moveCard(@Validated @RequestBody CardMoveFormRequest cardMoveFormRequest, | ||
BindingResult bindingResult, HttpServletResponse httpServletResponse, | ||
@PathVariable("cardId") Long cardId, HttpServletRequest request) { | ||
if (bindingResult.hasErrors()) { | ||
log.error("bindingResult: {}", bindingResult); | ||
httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); | ||
return; | ||
} | ||
String pastLocation = cardService.findOne(cardId).getCurrentLocation(); | ||
BindingResult bindingResult, @PathVariable("cardId") Long cardId) { | ||
|
||
//CardLocation pastLocation = cardService.findOne(cardId).getCurrentLocation(); | ||
//putHistoryDataToRequest(request, "move", pastLocation, cardService.findOne(cardId)); |
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.
주석 처리한 코드가 너무 많이 등장하는 것 같아요. 필요 없으면 지워주세요.
아니면 주석의 사유를 적어주세요.
//then | ||
assertThat(savedCardId).isEqualTo(foundCard.getId()); | ||
assertThat(card.getTitle()).isEqualTo("제목입니다"); | ||
assertThat(card.getContent()).isEqualTo("내용입니다"); | ||
assertThat(card.getWriter()).isEqualTo("sam"); | ||
assertThat(card.getCurrentLocation()).isEqualTo(CardLocation.done); |
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.
💯
Card foundCard = cardRepository.findById(savedCardId).get(); | ||
|
||
//then | ||
assertThat(savedCardId).isEqualTo(foundCard.getId()); |
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.
저장된 카드 ID로 직접 검증은 안되나요?
@DisplayName("카드 조회 시 저장 된 카드가 없다면 비어있는 리스트를 반환한다.") | ||
void finalAllErrorTest() { |
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.
왜 ErrorTest
인가요?
DisplayName과 맞지 않는 것 같습니다.
assertThat(card.getContent()).isEqualTo(foundCard.get().getContent()); | ||
assertThat(card.getWriter()).isEqualTo(foundCard.get().getWriter()); | ||
assertThat(card.getCurrentLocation()).isEqualTo(foundCard.get().getCurrentLocation()); | ||
assertThat(cards).hasSize(3); |
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.
이 검증만으로도 충분할까요?
card = cardAddFormRequest.toEntity(); | ||
} | ||
|
||
void createCards() { |
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.
createCards
라는 이름은 기대되는 결과가 혼동될 수도 있을 것 같아보여요.
createAndSaveCards
가 더 명확하지 않을까요?
안녕하세요 3조의 짱민과 노리입니다.
벌써 마지막 PR이라니 아쉽습니다 ㅠㅠ 😭
2주 동안 부족한 코드 리뷰해주셔서 감사합니다!!
수요일 이후 리뷰내용 수정 하느라 추가 기능이 별로없네요!!
이번 진행상황은 아래와 같습니다.
2주차 1차 리뷰내용 반영
CardResponse
로직을 생성자로 이동하였습니다.2주차 2차 개발 사항
리뷰 감사합니다! 2주동안 고생 많으셨어요!!🙇