Skip to content

Conversation

@LeeJaeYun7
Copy link
Collaborator

Question 패키지를 리팩터링하고, 테스트를 작성했습니다

Copy link
Collaborator

@f-lab-moony f-lab-moony left a comment

Choose a reason for hiding this comment

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

고생 많으셨어요 ~ 코멘트 좀 남겨 두었는데, 확인 후 리뷰 재요청 해주세요 ~

import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
Copy link
Collaborator

Choose a reason for hiding this comment

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

요거 메인 클래스에 선언해도 되지 않나요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

테스트 작성하는데 이걸 따로 선언해줘야 하더라고요
그래서 선언했습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

테스트 작성과 어떤 관계가 있는걸까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

테스트 할 때 깨지는 부분이 있었는데...
다시 해보니 InterviewPrepApplication 클래스에 @EnableJpaAuditing 하는 걸로 해결되서
수정해서 커밋했습니다

}

@GetMapping("/single/{id}")
@GetMapping("/api/v1/question/single/{id}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

중간에 single 굳이 안써도 되지 않을까요 ~?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 맞습니다. 그 부분은 수정해보겠습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

@GetMapping("/all")
public ResultResponse<?> getAllQuestionsSize(){
return ResultResponse.success(questionService.getAllQuestionsSize());
@GetMapping({"/api/v1/question/{type}", ""})
Copy link
Collaborator

Choose a reason for hiding this comment

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

type은 id의 성격이 아니라서 by-type 같이 추가 정보를 요구한다는걸 나타내주는게 좋을 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그럼 @GetMapping({"/api/v1/question/by/{type}", ""})
이렇게 나타내는걸 말씀하시는 걸까요?

Copy link
Collaborator

@f-lab-moony f-lab-moony Aug 20, 2023

Choose a reason for hiding this comment

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

@GetMapping("/api/v1/questions/by-type/{type}") 이런식으로 말씀드렸어요 ~ api를 쓰는 사람 입장에서 endpoint는 메서드같은 역할을 하기때문에 메서드 이름처럼 의미가 잘 드러나게 하는게 좋을 것 같아요

p.s @ 을 그냥 쓰시면 다른 사람이 멘션되니까 `` 요거로 감싸주시는게 좋아요 ~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

@GetMapping("/all")
public ResultResponse<?> getAllQuestionsSize(){
return ResultResponse.success(questionService.getAllQuestionsSize());
@GetMapping({"/api/v1/question/{type}", ""})
Copy link
Collaborator

Choose a reason for hiding this comment

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

뒤에 빈 문자열은 무슨 뜻일까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

type이 null일때를 의미하는 것 같은데... 굳이 필요하지 않을 것 같습니다

Copy link
Collaborator

Choose a reason for hiding this comment

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

type이 null일때라고 생각하신 이유가 있을까요 ? 연결되는 endpoint가 복수개라는 뜻으로 보이는데, 추가 path 없이 host만 입력된 요청도 얘가 받겠다 라는 뜻이 아닐까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

다시 생각해보니 말씀하신게 맞는 것 같습니다!

import java.util.Objects;

@Getter
@Builder
Copy link
Collaborator

Choose a reason for hiding this comment

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

빌더는 생성자에 달아주는걸 추천합니다 ~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

public List<Question> findQuestionsByType(String type){
return questionRepository.findByType(type);
public Question findQuestion(Long id){
return questionRepository.findById(id).orElseThrow(() -> new CommonException(NOT_FOUND_QUESTION));
Copy link
Collaborator

Choose a reason for hiding this comment

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

요청받은 id가 뭐였는지도 메세지에 드러나면 좋을 것 같아요 ~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

id는 Quesiton의 id인데 이 부분도 반영해보겠습니다

Copy link
Collaborator

Choose a reason for hiding this comment

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

뜻이 약간 잘못 전달된 것 같아서 .. 파라미터 명을 바꾸자는게 아니라 메세지에 드러났으면 좋겠다는 의견이었습니다 ~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

.type(q.getType())
.title(q.getTitle())
.status(myAnswer.contains(q.getId()))
.status(answers.contains(q.getId()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

contains 연산을 수행할때 List와 Set 중 뭐가 유리할까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ArrayList를 사용할 경우엔 O(N)이지만,
HashSet을 사용할 경우엔 O(1) 이므로, Set을 사용하는 편이 유리할 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

반영 완료

if(type==null) questions = questionRepository.findAllBy(pageable);
else questions = questionRepository.findByType(type, pageable); //문제 타입과 페이지 조건 값을 보내어 question 조회, 반환값 page
if(questions.getContent().isEmpty()) throw new CommonException(NOT_FOUND_QUESTION);
Page<Question> questions = findQuestionsByTypeAndPageable(type, pageable);
Copy link
Collaborator

Choose a reason for hiding this comment

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

사실 지금 수준에선 문제가 없겠지만, offset 방식의 페이징은 서비스가 커지면 반드시 문제가 생겨요. more 방식 페이징에 대해서 한번 찾아보시고 습관 들이시는걸 추천합니다~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://green-bin.tistory.com/m/23
넵 참고해보겠습니다

void setUp() throws Exception{

questionDTO = QuestionDTO.builder()
validQuestionRequest = QuestionRequest.builder()
Copy link
Collaborator

Choose a reason for hiding this comment

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

검증하려는 데이터는 그 테스트 내부에서 정의되는게 테스트 가독성을 더 높일 수 있다고 생각합니다 ~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 확인했습니다

when(questionService.deleteQuestion(1L)).thenReturn(question);
when(questionService.deleteQuestion(1000L)).thenThrow(new QuestionNotFoundException(1000L));
given(questionService.deleteQuestion(1L)).willReturn(question);
given(questionService.deleteQuestion(1000L)).willThrow(new QuestionNotFoundException(1000L));
Copy link
Collaborator

Choose a reason for hiding this comment

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

이거 이렇게 선언하면 아래 테스트들 잘 돌아가나요 ?

Copy link
Collaborator

@f-lab-moony f-lab-moony left a comment

Choose a reason for hiding this comment

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

고생 많으셨습니다 ~
코멘트를 좀 남겨 두었는데, 요거는 머지 해둘게요 ~ 확인 후 반영 부탁드립니다 ~

<td>
<div class="infoBox" id="failures">
<div class="counter">0</div>
<div class="counter">1</div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

gitignore에 build 하위 항목을 추가해주시는게 좋을 것 같아요 ~

Copy link
Collaborator

Choose a reason for hiding this comment

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

위에 .gradle 하위 항목도 추가해주시는게 좋을 것 같습니다 ~

import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableCaching
@EnableJpaAuditing
Copy link
Collaborator

Choose a reason for hiding this comment

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

오 근데 auditing 원래 있지 않았나요 ?

import java.util.List;

@RestController
@RequestMapping("/api/v1/questions")
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@PostMapping("/api/v1/question")
public ResultResponse<?> create(@RequestBody @Valid QuestionRequest questionRequest){
return ResultResponse.success(questionService.createQuestion(questionRequest));
@PostMapping()
Copy link
Collaborator

Choose a reason for hiding this comment

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

요럴땐 괄호 그냥 없애도 될거같아요 ~

public ResultResponse<?> create(@RequestBody @Valid QuestionRequest questionRequest){
return ResultResponse.success(questionService.createQuestion(questionRequest));
@PostMapping()
public ResponseEntity<Void> create(@RequestBody QuestionRequest questionRequest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

요전에 말씀 드리긴 했는데 ResponseEntity 꼭 써야할까요 ~?

@GetMapping("/api/v1/question/all")
public ResultResponse<?> getTotalQuestionsCount(){
return ResultResponse.success(questionService.getTotalQuestionsCount());
@GetMapping("/all")
Copy link
Collaborator

Choose a reason for hiding this comment

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

count가 질문의 갯수를 리턴한다면 /all 은 안어울리는 이름 같아요

@GetMapping("/api/v1/question/filter")
public ResultResponse<?> getFilterLanguage(){
return ResultResponse.success(questionService.findFilterLanguage());
@GetMapping("/filter")
Copy link
Collaborator

Choose a reason for hiding this comment

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

filter 라고 하면 어떤 기능인지 알 수 있을까요?

}

public void change(String title, String type){
public static Question createQuestionByQuestionRequest(QuestionRequest questionRequest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

의존성 방향을 바깥에서 안쪽으로만 허용해주시는 습관을 들이시는게 좋을 것 같아요. 클린 아키텍처에 대해서 한번 찾아보시는 걸 추천드립니다 ~

this.status = status;
}

public static QuestionResponse createQuestionResponse(Question question){
Copy link
Collaborator

Choose a reason for hiding this comment

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

요런건 보통 이름을 그냥 of나 from 으로 쓰는 편이에요!

.title(q.getTitle())
.status(answers.contains(q.getId()))
.build());
.id(q.getId())
Copy link
Collaborator

Choose a reason for hiding this comment

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

변수명을 줄여쓰지 않으시는게 좋아요 ~ oo씨 라고 지칭하는것과 거기! 라고 지칭하는 것 중 어떤게 더 명확한 표현일까 하는것과 같은 내용이라고 생각합니다 ~

@f-lab-moony f-lab-moony merged commit ea653cc into main Aug 24, 2023
f-lab-moony added a commit that referenced this pull request Aug 24, 2023
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.

3 participants