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

[4기 박상민] Springboot-jpa weekly 미션 1차 PR입니다. #312

Merged

Conversation

smartandhandsome
Copy link

📌 과제 설명

  • 단일 엔티티를 이용한 CRUD를 구현

Copy link

@seung-hun-h seung-hun-h left a comment

Choose a reason for hiding this comment

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

리뷰 남겼습니다~

Comment on lines 10 to 11
import org.programmers.jpaweeklymission.global.BaseEntity;
@Table(name = "customers")

Choose a reason for hiding this comment

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

Suggested change
import org.programmers.jpaweeklymission.global.BaseEntity;
@Table(name = "customers")
import org.programmers.jpaweeklymission.global.BaseEntity;
@Table(name = "customers")

private Long id;

@NotBlank
@Size(max = 20)

Choose a reason for hiding this comment

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

이렇게 되면 Empty String은 허용되는건가요?

Copy link
Author

Choose a reason for hiding this comment

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

Empty String 공백 허용하지 않는 걸로 정했습니다.

min 명시 해두었습니다.

Copy link
Author

Choose a reason for hiding this comment

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

Size가 있어서 NotBlank는 필요없는것 같아 제거했습니다.

d355a6b

}

@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.OK)

Choose a reason for hiding this comment

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

204 상태 코드에 대해서 알아보는 것도 좋겠네요~

Copy link
Author

Choose a reason for hiding this comment

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

같은 생각으로 해당 내용 작성했습니다.

prgrms-be-devcourse/springboot-board-jpa#225 (comment)

@ExceptionHandler({HttpMessageNotReadableException.class, MethodArgumentNotValidException.class})
public ResponseEntity<Map<String, String>> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
log.warn(e.getMessage(), e);
return ResponseEntity.badRequest().body(Collections.singletonMap(MESSAGE, e.getMessage()));

Choose a reason for hiding this comment

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

  • 예외 메시지를 그대로 클라이언트에 전댈해도 될까요?
  • Map을 사용하지말고 에러 응답 객체를 정의해도 좋을 것 같아요

Copy link
Author

Choose a reason for hiding this comment

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

변경했습니다.

cc9e51f

Copy link
Author

@smartandhandsome smartandhandsome Aug 3, 2023

Choose a reason for hiding this comment

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

혹시 저 핸들러에 어떤어떤 에러를 잡으시나요?

저는

  1. 제가 내부에서 발생시킨 에러
  2. 요청을 날렸을 때 발생할 만한 에러

이런 기준으로 작성했는데, 추가할 에러가 또 있을까요?

Comment on lines +63 to +64
tem.flush();
tem.clear();

Choose a reason for hiding this comment

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

필요한 이유가 있나요?

Copy link
Author

@smartandhandsome smartandhandsome Aug 3, 2023

Choose a reason for hiding this comment

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

Db에 대한 Test 라고 생각했고

1차 캐시를 이용하면 안된다고 생각했습니다.

또, 쿼리가 제대로 나가는지 확인하기 위해서 작성했습니다.

Comment on lines +36 to +39
public void changeEntity(Customer customer) {
changeFirstName(customer.firstName);
changeLastName(customer.lastName);
}
Copy link
Member

Choose a reason for hiding this comment

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

Customer를 새로 만들어서 update하는 형태가 적절한 지 잘 모르겠어요!
이렇게 생각하신 이유가 있을까요?

Copy link
Author

@smartandhandsome smartandhandsome Aug 3, 2023

Choose a reason for hiding this comment

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

일단 Update 요청으로 들어오는 Dto를 Domain Layer까지 끌고 오는 건 아니라고 생각했습니다.

Service Layer와 Domain Layer 사이에 Dto를 또 두는 건 이미 Service가 Domain을 알고 있고 사용하기 떄문에 굳이? 라고 생각했습니다. (작성하고 나니 Domain과 Entity를 분리하는 방법도 있구나라는 생각이 드는데 어떻게 생각하시나요?)

그리고 보통 사용자를 수정할 떄, 모든 항목의 내용을 다 받는 다는 걸 여러 사이트에서 참고 했습니다.

프론트에서 어떻게 처리되는지는 잘 모르겠지만 각각 한 요소 요소 마다 변경하는 것 보다는 보통 모든 요소를 다 변경하는구나 라고 파악해서 Customer를 넣는 방식으로 선택했습니다.

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
Member

Choose a reason for hiding this comment

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

요구사항에 따라서 다르겠지만 개인적으로는 업데이트 되는 필드와 업데이트 되지 않은(혹은 사용자가 업데이트할 수 없는) 필드가 있을 수 있다고 생각해요. 그래서 업데이트 되는 필드를 한번에 모두 요청을 받아서 업데이트를 한다면 저는 해당 데이터 관리용 DTO를 도메인까지 넣어줄 것 같아요. 해당 dto를 외부까지 쓸 수도 있고 아닐 수도 있지만 이 부분도 고민해볼 수 있겠네요.

정리하면

  • 변경 가능한 필드에 대해서 도메인에게 변경 요청을 하는 DTO를 만드는 것이 좋을 수 있다.
  • 이 도메인 DTO를 외부 레이어 어디까지 쓸 것인지는 고민이 필요하다

Copy link

@seung-hun-h seung-hun-h left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~


@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler { // TODO: 혹시 멘토님들은 여기서 어떤 어떤 에러를 잡으시나요?

Choose a reason for hiding this comment

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

GlobalExceptionHanlder이니 지금 작성하신 것 처럼 글로벌하게 처리할 예외들을 잡을 것 같습니다.

import jakarta.validation.constraints.Size;

public record CustomerCreationRequest(
@Size(min = 1, max = 20, message = "First name must be at least 1 character and no more than 20 characters.")

Choose a reason for hiding this comment

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

기본 메시지는 어떻게 출력되던가요?

Copy link
Member

@dojinyou dojinyou left a comment

Choose a reason for hiding this comment

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

수고하셨습니다

@smartandhandsome smartandhandsome merged commit 0cdc711 into prgrms-be-devcourse:smart-sangmin Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants