From bcdbe3a393102de4a6e732d0877e87ddd2a53557 Mon Sep 17 00:00:00 2001 From: YoungJun Park Date: Tue, 26 Jul 2022 00:12:40 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=94=20=ED=9A=8C=EC=9B=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=B3=80=EA=B2=BD(Adapter=20&=20Service)(#14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../in/web/request/UpdateMemberReq.java | 3 --- .../persistence/MemberPersistenceAdapter.java | 4 ++-- .../service/UpdateMemberService.java | 19 +++++++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/hexagonal/api/member/adapter/in/web/request/UpdateMemberReq.java b/api/src/main/java/hexagonal/api/member/adapter/in/web/request/UpdateMemberReq.java index 224d8c8..7713bef 100644 --- a/api/src/main/java/hexagonal/api/member/adapter/in/web/request/UpdateMemberReq.java +++ b/api/src/main/java/hexagonal/api/member/adapter/in/web/request/UpdateMemberReq.java @@ -4,9 +4,6 @@ @Getter public class UpdateMemberReq { - - Long id; String name; - String email; String type; } diff --git a/api/src/main/java/hexagonal/api/member/adapter/out/persistence/MemberPersistenceAdapter.java b/api/src/main/java/hexagonal/api/member/adapter/out/persistence/MemberPersistenceAdapter.java index a47b593..7bc5d88 100644 --- a/api/src/main/java/hexagonal/api/member/adapter/out/persistence/MemberPersistenceAdapter.java +++ b/api/src/main/java/hexagonal/api/member/adapter/out/persistence/MemberPersistenceAdapter.java @@ -42,7 +42,7 @@ public Long saveMember(MemberJpaEntity memberJpaEntity) { @Override public Long updateMember(MemberJpaEntity memberJpaEntity) { - memberRepository.save(memberJpaEntity); - return null; + MemberJpaEntity saveEntity = memberRepository.save(memberJpaEntity); + return saveEntity.getId(); } } diff --git a/api/src/main/java/hexagonal/api/member/application/service/UpdateMemberService.java b/api/src/main/java/hexagonal/api/member/application/service/UpdateMemberService.java index 91ad768..4718a50 100644 --- a/api/src/main/java/hexagonal/api/member/application/service/UpdateMemberService.java +++ b/api/src/main/java/hexagonal/api/member/application/service/UpdateMemberService.java @@ -19,23 +19,22 @@ public class UpdateMemberService implements UpdateMemberUseCase { @Override public Long updateMember(UpdateMemberCommand command) { - // ID 존재 여부 검사 - if (checkMemberExistsById(command.getId())) { - MemberJpaEntity memberJpaEntity = command.toJpaEntity(); - return updateMemberPort.updateMember(memberJpaEntity); + MemberJpaEntity jpaEntity = checkMemberExistsById(command.getId()); + if (jpaEntity != null) { + jpaEntity.setName(command.getName()); + jpaEntity.setType(command.getMemberType()); + return updateMemberPort.updateMember(jpaEntity); } else { // FixMe Custom Exception 처리하기 - return null; + return 0L; } } - private boolean checkMemberExistsById(Long id) { + private MemberJpaEntity checkMemberExistsById(Long id) { try { - findMemberPort.findMemberById(id); + return findMemberPort.findMemberById(id); } catch (EntityNotFoundException e) { - return false; + return null; } - - return true; } }