Skip to content

Conversation

@LeeJaeYun7
Copy link
Collaborator

  • Answer 패키지를 리팩토링했습니다

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.

고생 많으셨어요~ 코멘트를 좀 남겨 두었는데, 확인 후 리뷰 재요청 부탁드려요 ~

}

@PostMapping("/api/v1/answer")
public ResultResponse<?> createAnswer(@RequestBody @Valid AnswerRequest answerRequest){
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Valid는 어떤 역할을 하고 있나요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

지금은 AnswerRequest에 Objects.requireNonNull을 추가해서 따로 필요하지 않을 것 같습니다.

@Valid는 DTO 필드들에 @NotNull, @Email 등이 쓰인다면, 해당 필드에 대해 검증해주는 역할을 맡습니다.

https://jyami.tistory.com/55

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("/{id}")
@GetMapping("/api/v1/answer/{id}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

엔드포인트는 메서드 별로 관리를 하기로 하신걸까요 ~? prefix는 컨트롤러를 나누는 기준이 되기도 해서 클래스 레벨에 붙여놔도 좋을 것 같아요 ~

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 int commentIncrease() { return ++this.commentCnt; }
public int commentIncrease() {
return ++this.commentCnt;
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.

반영 완료

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.

반영 완료


@Query("select a.question.id from Answer a where a.question.id in ?1 and a.member.id = ?2 ")
List<Long> findMyAnswer(List<Long> qList, Long memberId); //@Param("memberId")
List<Long> findMyAnswer(List<Long> questionIds, Long memberId); //@Param("memberId")
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

.createDate(customLocalDateTime(answer.getCreatedDate()))
.name(answer.getMember().getName())
.build();
return AnswerResponse.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

@LeeJaeYun7 LeeJaeYun7 Aug 21, 2023

Choose a reason for hiding this comment

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

반영 완료

Long memberId = JwtUtil.getMemberId();
Page<Answer> answers;

if(!(type.equals("my") || type.equals("others"))){
Copy link
Collaborator

Choose a reason for hiding this comment

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

타입은 enum을 이용해보면 어떨까요 ?

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.

반영 완료

Long memberId = JwtUtil.getMemberId();
if(memberId==0L) throw new CommonException(NOT_FOUND_ID);

if(memberId==0L) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

memberId 0은 언제 들어가는건가요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

멤버가 로그인되어 있지 않은 상황에서는 JwtUtil.getMemberId()가 0L을 반환하도록 설정되어 있습니다

Copy link
Collaborator

Choose a reason for hiding this comment

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

JwtUtil.getMemberId() 자체가 로그인 된 멤버의 아이디를 가져오겠다는 의미로 보이는데, 로그인되어있지 않은 경우 0을 반환 할 이유가 있을까요 ? 애초에 로그인되지 않은 경우 예외를 던지는게 어떨까 해서 의견 남겨봅니다 ~

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.

반영 완료

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.

고생 많으셨어요 ~
피드백 남겨 두었는데, 요건 머지 해 둘게요 ~

@PostMapping()
public ResponseEntity<Void> createAnswer(@RequestBody AnswerRequest answerRequest){
answerService.createAnswer(answerRequest);
return ResponseEntity.status(HttpStatus.CREATED).build();
Copy link
Collaborator

Choose a reason for hiding this comment

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

개인적으로 성공응답은 그냥 다 200으로 내려도 된다고 생각해요. 성공 상태에 따라서 뭐 분기할 일이 없어서 ..

this.version = version;
}

public static Answer createAnswerEntity(Member member, Question question, String content){
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 왜있는걸까요 ?

}

public int increase() {
public synchronized int increase() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

synchronized가 이런식으로 걸리면 성능에 어떤 영향이 있을까요 ? AtomicInteger에 대해서 찾아보시면 좋을 것 같아요 ~


private String content;

@Builder
Copy link
Collaborator

Choose a reason for hiding this comment

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

요거 저번에 유효성검사 위치를 잘못 봤는데, 이 생성자에 유효성검사가 들어있으면 실제 요청시에 유효성검사 되나요 ?

추가로, 유효성검사가 요청 객체에 있는게 맞을지, 서비스 메서드에 있는게 맞을지 고민도 한번 해보시면 좋을 것 같아요 ~

Page<Answer> answers;

if(!(type.equals("my") || type.equals("others"))){
Type inputType = Type.valueOf(type.toUpperCase());
Copy link
Collaborator

Choose a reason for hiding this comment

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

컨트롤러에서 처음부터 Type으로 받으면 치환 안해줘도 되지 않을까요 ~?

if(!(type.equals("my") || type.equals("others"))){
Type inputType = Type.valueOf(type.toUpperCase());

if(!(inputType.equals(Type.MY) || inputType.equals(Type.OTHERS))){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Type에 포함되지 않은 녀석들을 거르려고 하신 거 같아요 ~ 위와 마찬가지로 컨트롤러에서 enum 타입으로 받으면 이것도 없어도 될 것 같습니다 ~

@@ -0,0 +1,6 @@
package com.example.interviewPrep.quiz.utils;

public enum 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은 너무 범용적인 이름인데 좀 더 명확한 이름 없을까요 ?

@f-lab-moony f-lab-moony merged commit b18d888 into main Aug 24, 2023
LeeJaeYun7 added a commit that referenced this pull request Aug 28, 2023
#15 Question 패키지 버그 수정
LeeJaeYun7 added a commit that referenced this pull request Sep 4, 2023
#15 findByCompany 메소드 추가 with QueryDSL
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