Skip to content

[#1]; refact : 4계층 적용#2

Open
Shin-Yun-Cheol wants to merge 5 commits into
masterfrom
refact/1
Open

[#1]; refact : 4계층 적용#2
Shin-Yun-Cheol wants to merge 5 commits into
masterfrom
refact/1

Conversation

@Shin-Yun-Cheol

Copy link
Copy Markdown
Owner

[#1]; refact

application, business, implement, repository로 이루어진 4계층 적용.

  • controller, service를 각각 application, business디렉토리로 이동
  • 각 계층별로 참조 단계를 하위로 가게 수정 (dto, command분리)

하고 있는 일
단위 테스트 작성중

- application, business, implement, repository로 크게 4계층을 적용
- business 의 service를 굳이 impl과 나누지 않아도 될 것 같아서 다시 변경
- service에서 Repository바로 접근 보다 implement에서 repository를 접근해서 service에서는 흐름을 볼 수 있게 수정
- dto는 controller에서, command와 result는 service에서 사용할 수 있도록 하여 각자 다른 걸 참조할 수 있도록 수정
@Shin-Yun-Cheol
Shin-Yun-Cheol requested a review from seulnan October 1, 2025 15:45

@seulnan seulnan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

고생하셨습니다 아직 4계층에 대한 적용이 조금 서툰모습들이 보이네요 점차 나아질거라 믿습니다 파이팅입니다

String content
) {
public UpdatePostCommand{
if(id==null) throw new IllegalArgumentException("id is null");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

이런 간단한 validation은 어노테이션으로도 가능해요 @Valid, @notblank, @NotNull 같은거 공부해보시고 커스텀어노테이션으로도 도메인규칙이 적용된 검증이 가능해요


Post saved = postWriter.save(
Post.builder()
.title(createPostCommand.title())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

엥 제가 빌더패턴말고 정적팩토리메소드를 한번 써보라고했었는데.........왜 써야할까요?


@PostMapping("/signup")
public SignUpResponse signup(@RequestBody SignUpRequest req) {
var cmd = new SignUpCommand(req.email(), req.password(), req.username());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

command를 controller에서 생성하는게 책임분리면에서 옳을까요? new로 생성하는게 왜 권장되지않을까요? 그럼 new를 사용하지않으면 어떻게 해야할까요??

Comment on lines +9 to +12
if(email==null || email.isBlank()) throw new IllegalArgumentException("email is null or empty");
if(password==null || password.isBlank()) throw new IllegalArgumentException("password is null or empty");
if(username==null || username.isBlank()) throw new IllegalArgumentException("username is null or empty");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

여기도 위에서 얘기한대로 어노테이션으로 충분해요

Comment on lines 25 to 29
User.builder()
.email(signUpRequest.email())
.email(signUpCommand.email())
.passwordHash(hashedPassword)
.username(signUpRequest.username())
.username(signUpCommand.username())
.build()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

이거도 builder말고 정적팩토리메소드를 알아보시면 좋을듯해요

Comment on lines +19 to 21
if(userRepository.existsByEmail(signUpCommand.email())){
throw new IllegalArgumentException("email already in use");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

큰 흐름을 보여주는 business layer에서 예외를 던지는게 맞을까요?? 그리고 이메일중복검증은 어느계층에 두는게 맞을까요?

Comment on lines +14 to +15
return userRepository.findByEmail(email)
.orElseThrow(()->new IllegalArgumentException("email not found"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

린트적용해서 코드 스타일 통일시켜주세요


@PostMapping
public PostCreateResponse create(@RequestBody @Valid CreatePostRequest req) {
var cmd = new CreatePostCommand(req.email(), req.password(), req.title(), req.content());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

new로 command를 생성하는 이유가 있을까요?

Shin-Yun-Cheol added a commit that referenced this pull request Oct 2, 2025
- business계층에서 builder 패턴을 이용하던걸 정적팩토리 메소드를 이용해서 각 엔티티에서 생성할 수 있도록 수정
Shin-Yun-Cheol added a commit that referenced this pull request Nov 4, 2025
- business계층에서 builder 패턴을 이용하던걸 정적팩토리 메소드를 이용해서 각 엔티티에서 생성할 수 있도록 수정
Shin-Yun-Cheol added a commit that referenced this pull request Nov 4, 2025
- Controller에서 command생성하던걸 dto에서 command로 변환하고 정적팩토리로 변환해서 service에 이용
Shin-Yun-Cheol added a commit that referenced this pull request Nov 4, 2025
Shin-Yun-Cheol added a commit that referenced this pull request Nov 4, 2025
- BusinessException이라는 클래스를 둬서 에러처리할 수 있게 하고 각 도메인별 커스텀 예외를 만듦.
ErrorResponse객체와 GlobalExceptionHandler로 예외를 관리
Shin-Yun-Cheol added a commit that referenced this pull request Nov 4, 2025
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.

2 participants