Skip to content

Commit

Permalink
๐Ÿ—ƒ๏ธ ์กฐํšŒ Adapter ์ˆ˜์ • ๋ฐ Update ์ถ”๊ฐ€(#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Jul 1, 2022
1 parent 90eaac1 commit 2fe47a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hexagonal.api.member.application.port.out.FindMemberPort;
import hexagonal.api.member.application.port.out.SaveMemberPort;
import hexagonal.api.member.application.port.out.UpdateMemberPort;
import hexagonal.core.domain.jpa.MemberJpaEntity;
import hexagonal.core.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -11,21 +12,31 @@

@RequiredArgsConstructor
@Component
class MemberPersistenceAdapter implements FindMemberPort, SaveMemberPort {
class MemberPersistenceAdapter implements FindMemberPort, SaveMemberPort, UpdateMemberPort {

private final MemberRepository memberRepository;

@Override
public MemberJpaEntity findMember(String email) {
MemberJpaEntity member = memberRepository.findByEmail(email)
public MemberJpaEntity findMemberById(Long id) {
return memberRepository.findById(id)
.orElseThrow(EntityNotFoundException::new);
return member;
}

@Override
public MemberJpaEntity findMemberByEmail(String email) {
return memberRepository.findByEmail(email)
.orElseThrow(EntityNotFoundException::new);
}

@Override
public Long saveMember(MemberJpaEntity memberJpaEntity) {
MemberJpaEntity saved = memberRepository.save(memberJpaEntity);
return saved.getId();
}

@Override
public Long updateMember(MemberJpaEntity memberJpaEntity) {
memberRepository.save(memberJpaEntity);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ public Long registerMember(RegisterMemberCommand command) {
}
MemberJpaEntity memberJpaEntity = command.toJpaEntity();
// ๋ชจ๋ธ ์ƒํƒœ ์กฐ์ž‘
Long memberId = saveMemberPort.saveMember(memberJpaEntity);
// ์ถœ๋ ฅ ๊ฐ’ ๋ฐ˜ํ™˜
return memberId;
return saveMemberPort.saveMember(memberJpaEntity);
}

private boolean checkMemberEmailExists(String email) {
try {
findMemberPort.findMember(email);
findMemberPort.findMemberByEmail(email);
} catch (EntityNotFoundException e) {
return true;
}
Expand Down

0 comments on commit 2fe47a3

Please sign in to comment.