Skip to content

Commit

Permalink
๐Ÿ‘” ํšŒ์›์ •๋ณด ๋ณ€๊ฒฝ ์š”์ฒญ UseCase-Service ์ถ”๊ฐ€(#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Jun 29, 2022
1 parent 8823eec commit 5886737
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package hexagonal.api.member.application.port.in;

public interface UpdateMemberUseCase {

Long updateMember(UpdateMemberCommand command);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package hexagonal.api.member.application.service;

import hexagonal.api.member.application.port.in.UpdateMemberCommand;
import hexagonal.api.member.application.port.in.UpdateMemberUseCase;
import hexagonal.api.member.application.port.out.FindMemberPort;
import hexagonal.api.member.application.port.out.UpdateMemberPort;
import hexagonal.core.domain.jpa.MemberJpaEntity;
import lombok.RequiredArgsConstructor;

import javax.persistence.EntityNotFoundException;

@RequiredArgsConstructor
public class UpdateMemberService implements UpdateMemberUseCase {

private final FindMemberPort findMemberPort;
private final UpdateMemberPort updateMemberPort;

@Override
public Long updateMember(UpdateMemberCommand command) {
// ID ์กด์žฌ ์—ฌ๋ถ€ ๊ฒ€์‚ฌ
if (checkMemberExistsById(command.getId())) {
MemberJpaEntity memberJpaEntity = command.toJpaEntity();
return updateMemberPort.updateMember(memberJpaEntity);
} else {
// FixMe Custom Exception ์ฒ˜๋ฆฌํ•˜๊ธฐ
return null;
}
}

private boolean checkMemberExistsById(Long id) {
try {
findMemberPort.findMemberById(id);
} catch (EntityNotFoundException e) {
return false;
}

return true;
}
}

0 comments on commit 5886737

Please sign in to comment.