From 974a46d98d5f7f39097f88bbc1cb2c9035904092 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 22 May 2024 21:20:36 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[ADD]=20DollFinder=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/doll/adapter/DollFinder.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/com/soptie/server/doll/adapter/DollFinder.java diff --git a/src/main/java/com/soptie/server/doll/adapter/DollFinder.java b/src/main/java/com/soptie/server/doll/adapter/DollFinder.java new file mode 100644 index 00000000..132f35c6 --- /dev/null +++ b/src/main/java/com/soptie/server/doll/adapter/DollFinder.java @@ -0,0 +1,22 @@ +package com.soptie.server.doll.adapter; + +import com.soptie.server.common.support.RepositoryAdapter; +import com.soptie.server.doll.entity.Doll; +import com.soptie.server.doll.entity.DollType; +import com.soptie.server.doll.exception.DollException; +import com.soptie.server.doll.repository.DollRepository; +import lombok.RequiredArgsConstructor; + +import static com.soptie.server.doll.message.ErrorCode.INVALID_TYPE; + +@RepositoryAdapter +@RequiredArgsConstructor +public class DollFinder { + + private final DollRepository dollRepository; + + public Doll findByType(DollType type) { + return dollRepository.findByDollType(type) + .orElseThrow(() -> new DollException(INVALID_TYPE)); + } +} From 6863a8abea9845340203acba4cb03df551769587 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 22 May 2024 21:20:54 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[ADD]=20MemberDeleter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/member/adapter/MemberDeleter.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/soptie/server/member/adapter/MemberDeleter.java diff --git a/src/main/java/com/soptie/server/member/adapter/MemberDeleter.java b/src/main/java/com/soptie/server/member/adapter/MemberDeleter.java new file mode 100644 index 00000000..a6a8848a --- /dev/null +++ b/src/main/java/com/soptie/server/member/adapter/MemberDeleter.java @@ -0,0 +1,17 @@ +package com.soptie.server.member.adapter; + +import com.soptie.server.common.support.RepositoryAdapter; +import com.soptie.server.member.entity.Member; +import com.soptie.server.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; + +@RepositoryAdapter +@RequiredArgsConstructor +public class MemberDeleter { + + private final MemberRepository memberRepository; + + public void deleteMember(Member member) { + memberRepository.delete(member); + } +} From 95eecd02803a90c7913c63f45d53dff418058f52 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 22 May 2024 21:21:07 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[ADD]=20ConversationFinder=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/ConversationFinder.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/soptie/server/conversation/adapter/ConversationFinder.java diff --git a/src/main/java/com/soptie/server/conversation/adapter/ConversationFinder.java b/src/main/java/com/soptie/server/conversation/adapter/ConversationFinder.java new file mode 100644 index 00000000..eb43bb1b --- /dev/null +++ b/src/main/java/com/soptie/server/conversation/adapter/ConversationFinder.java @@ -0,0 +1,19 @@ +package com.soptie.server.conversation.adapter; + +import com.soptie.server.common.support.RepositoryAdapter; +import com.soptie.server.conversation.entity.Conversation; +import com.soptie.server.conversation.repository.ConversationRepository; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +@RepositoryAdapter +@RequiredArgsConstructor +public class ConversationFinder { + + private final ConversationRepository conversationRepository; + + public List findAll() { + return conversationRepository.findAll(); + } +} From 96540a740ff5ce7b4868ad7c68788a14b314899f Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 22 May 2024 21:21:17 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[ADD]=20MemberDollSaver=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memberDoll/adapter/MemberDollSaver.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/soptie/server/memberDoll/adapter/MemberDollSaver.java diff --git a/src/main/java/com/soptie/server/memberDoll/adapter/MemberDollSaver.java b/src/main/java/com/soptie/server/memberDoll/adapter/MemberDollSaver.java new file mode 100644 index 00000000..1c838f30 --- /dev/null +++ b/src/main/java/com/soptie/server/memberDoll/adapter/MemberDollSaver.java @@ -0,0 +1,17 @@ +package com.soptie.server.memberDoll.adapter; + +import com.soptie.server.common.support.RepositoryAdapter; +import com.soptie.server.memberDoll.entity.MemberDoll; +import com.soptie.server.memberDoll.repository.MemberDollRepository; +import lombok.RequiredArgsConstructor; + +@RepositoryAdapter +@RequiredArgsConstructor +public class MemberDollSaver { + + private final MemberDollRepository memberDollRepository; + + public void save(MemberDoll memberDoll) { + memberDollRepository.save(memberDoll); + } +} From d0aa4b04aa958d0262f9c877e5358bb47a98bd99 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 22 May 2024 21:21:40 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[REFACTOR]=20MemberService=20=EC=88=9C?= =?UTF-8?q?=ED=99=98=EC=B0=B8=EC=A1=B0=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/service/MemberServiceImpl.java | 45 +++++++++++++------ .../service/MemberRoutineCreateService.java | 4 -- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java b/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java index 89bd159d..d4596854 100644 --- a/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java +++ b/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java @@ -1,7 +1,12 @@ package com.soptie.server.member.service; +import com.soptie.server.conversation.adapter.ConversationFinder; import com.soptie.server.conversation.entity.Conversation; import com.soptie.server.conversation.repository.ConversationRepository; +import com.soptie.server.doll.adapter.DollFinder; +import com.soptie.server.doll.entity.DollType; +import com.soptie.server.member.adapter.MemberDeleter; +import com.soptie.server.member.adapter.MemberFinder; import com.soptie.server.member.service.dto.request.CottonGiveServiceRequest; import com.soptie.server.member.service.dto.request.MemberHomeInfoGetServiceRequest; import com.soptie.server.member.service.dto.response.MemberCottonCountGetServiceResponse; @@ -10,9 +15,13 @@ import com.soptie.server.member.entity.Member; import com.soptie.server.member.exception.MemberException; import com.soptie.server.member.repository.MemberRepository; +import com.soptie.server.memberDoll.adapter.MemberDollSaver; +import com.soptie.server.memberDoll.entity.MemberDoll; import com.soptie.server.memberDoll.service.MemberDollService; +import com.soptie.server.memberRoutine.adapter.MemberRoutineSaver; import com.soptie.server.memberRoutine.service.MemberRoutineCreateService; +import com.soptie.server.routine.adapter.RoutineFinder; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Service; @@ -27,31 +36,34 @@ @Transactional(readOnly = true) public class MemberServiceImpl implements MemberService { - private final MemberDollService memberDollService; - private final MemberRoutineCreateService memberRoutineCreateService; - private final MemberRepository memberRepository; - private final ConversationRepository conversationRepository; + private final ConversationFinder conversationFinder; + private final MemberFinder memberFinder; + private final MemberDeleter memberDeleter; + private final DollFinder dollFinder; + private final RoutineFinder routineFinder; + private final MemberDollSaver memberDollSaver; + private final MemberRoutineSaver memberRoutineSaver; @Override @Transactional public void createMemberProfile(MemberProfileCreateServiceRequest request) { - val member = findMember(request.memberId()); + val member = memberFinder.findById(request.memberId()); member.checkMemberDollNonExist(); - memberRoutineCreateService.createDailyRoutines(member, request.routines()); - memberDollService.createMemberDoll(member, request.dollType(), request.name()); + createDailyRoutines(member, request.routines()); + createMemberDoll(member, request.dollType(), request.name()); } @Override @Transactional public MemberCottonCountGetServiceResponse giveCotton(CottonGiveServiceRequest request) { - val member = findMember(request.memberId()); + val member = memberFinder.findById(request.memberId()); val cottonCount = member.subtractAndGetCotton(request.cottonType()); return MemberCottonCountGetServiceResponse.of(cottonCount); } @Override public MemberHomeInfoGetServiceResponse getMemberHomeInfo(MemberHomeInfoGetServiceRequest request) { - val member = findMember(request.memberId()); + val member = memberFinder.findById(request.memberId()); member.checkMemberDollExist(); val conversations = getConversations(); return MemberHomeInfoGetServiceResponse.of(member, conversations); @@ -59,16 +71,21 @@ public MemberHomeInfoGetServiceResponse getMemberHomeInfo(MemberHomeInfoGetServi @Override public void deleteMember(Member member) { - memberRepository.delete(member); + memberDeleter.deleteMember(member); } - private Member findMember(long id) { - return memberRepository.findById(id) - .orElseThrow(() -> new MemberException(INVALID_MEMBER)); + private void createDailyRoutines(Member member, List routineIds) { + routineIds.forEach(id -> memberRoutineSaver.checkHasDeletedAndSave(member, routineFinder.findById(id))); + } + + private void createMemberDoll(Member member, DollType dollType, String name) { + val doll = dollFinder.findByType(dollType); + val memberDoll = new MemberDoll(member, doll, name); + memberDollSaver.save(memberDoll); } private List getConversations() { - return conversationRepository.findAll().stream() + return conversationFinder.findAll().stream() .map(Conversation::getContent) .toList(); } diff --git a/src/main/java/com/soptie/server/memberRoutine/service/MemberRoutineCreateService.java b/src/main/java/com/soptie/server/memberRoutine/service/MemberRoutineCreateService.java index 2f135ae0..f82c179c 100644 --- a/src/main/java/com/soptie/server/memberRoutine/service/MemberRoutineCreateService.java +++ b/src/main/java/com/soptie/server/memberRoutine/service/MemberRoutineCreateService.java @@ -42,10 +42,6 @@ public MemberDailyRoutineCreateServiceResponse createDailyRoutine(MemberDailyRou return MemberDailyRoutineCreateServiceResponse.of(savedMemberRoutine); } - public void createDailyRoutines(Member member, List routineIds) { - routineIds.forEach(id -> memberRoutineSaver.checkHasDeletedAndSave(member, routineFinder.findById(id))); - } - public MemberHappinessRoutineCreateServiceResponse createHappinessRoutine( MemberHappinessRoutineCreateServiceRequest request ) { From 590600b780058085246286a7186b4c6ea7368929 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Wed, 22 May 2024 21:22:08 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[TEST]=20MemberService=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=84=EC=8B=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 멤버 프로필 생성 부분 통합 테스트에서 테스트 예정 --- .../member/service/MemberServiceImplTest.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/test/java/com/soptie/server/member/service/MemberServiceImplTest.java b/src/test/java/com/soptie/server/member/service/MemberServiceImplTest.java index 8bc580e7..6c9ec4b3 100644 --- a/src/test/java/com/soptie/server/member/service/MemberServiceImplTest.java +++ b/src/test/java/com/soptie/server/member/service/MemberServiceImplTest.java @@ -1,9 +1,12 @@ package com.soptie.server.member.service; +import com.soptie.server.conversation.adapter.ConversationFinder; import com.soptie.server.conversation.entity.Conversation; -import com.soptie.server.conversation.repository.ConversationRepository; +import com.soptie.server.doll.adapter.DollFinder; import com.soptie.server.doll.entity.Doll; import com.soptie.server.doll.entity.DollType; +import com.soptie.server.member.adapter.MemberDeleter; +import com.soptie.server.member.adapter.MemberFinder; import com.soptie.server.member.controller.dto.request.MemberProfileCreateRequest; import com.soptie.server.member.service.dto.request.CottonGiveServiceRequest; import com.soptie.server.member.service.dto.request.MemberHomeInfoGetServiceRequest; @@ -12,10 +15,10 @@ import com.soptie.server.member.entity.CottonType; import com.soptie.server.member.entity.Member; import com.soptie.server.member.exception.MemberException; -import com.soptie.server.member.repository.MemberRepository; +import com.soptie.server.memberDoll.adapter.MemberDollSaver; import com.soptie.server.memberDoll.entity.MemberDoll; -import com.soptie.server.memberDoll.service.MemberDollServiceImpl; -import com.soptie.server.memberRoutine.service.MemberRoutineCreateService; +import com.soptie.server.memberRoutine.adapter.MemberRoutineSaver; +import com.soptie.server.routine.adapter.RoutineFinder; import com.soptie.server.support.fixture.ConversationFixture; import com.soptie.server.support.fixture.DollFixture; import com.soptie.server.support.fixture.MemberDollFixture; @@ -28,7 +31,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; -import java.util.Optional; import static com.soptie.server.doll.entity.DollType.BROWN; import static com.soptie.server.member.message.ErrorCode.NOT_ENOUGH_COTTON; @@ -43,17 +45,11 @@ class MemberServiceImplTest { private MemberServiceImpl memberService; @Mock - private MemberRoutineCreateService memberRoutineCreateService; + private MemberFinder memberFinder; @Mock - private MemberDollServiceImpl memberDollService; - - @Mock - private MemberRepository memberRepository; - - @Mock - private ConversationRepository conversationRepository; - + private ConversationFinder conversationFinder; +/* @Test @DisplayName("멤버 프로필 생성 시, 멤버 데일리 루틴 생성과 멤버 인형 생성 메소드를 호출한다.") void 멤버_프로필을_생성하면서_멤버_데일리_루틴과_멤버_인형을_생성한다() { @@ -64,16 +60,16 @@ class MemberServiceImplTest { String name = "memberDoll"; List routines = List.of(2L, 3L, 4L); MemberProfileCreateRequest request = new MemberProfileCreateRequest(dollType, name, routines); - doNothing().when(memberRoutineCreateService).createDailyRoutines(member, List.of(2L, 3L, 4L)); - doNothing().when(memberDollService).createMemberDoll(member, dollType, name); + doNothing().when(memberRoutineSaver).checkHasDeletedAndSave(member, List.of(2L, 3L, 4L)); + doNothing().when(memberService).createMemberDoll(member, dollType, name); // when memberService.createMemberProfile(MemberProfileCreateServiceRequest.of(memberId, request)); // then - verify(memberRoutineCreateService).createDailyRoutines(member, routines); - verify(memberDollService).createMemberDoll(member, dollType, name); - } + verify(memberService).createDailyRoutines(member, routines); + verify(memberService).createMemberDoll(member, dollType, name); + }*/ @Test @DisplayName("솜뭉치 개수가 양수일 때 솜뭉치를 줄 수 있다.") @@ -128,19 +124,19 @@ void occurExceptionGiveCottonWhenCottonCountIsZero() { private Member member(long memberId) { Member member = MemberFixture.member().id(memberId).build(); - doReturn(Optional.of(member)).when(memberRepository).findById(memberId); + doReturn(member).when(memberFinder).findById(memberId); return member; } private Member member(long memberId, MemberDoll memberDoll) { Member member = MemberFixture.member().id(memberId).memberDoll(memberDoll).build(); - doReturn(Optional.of(member)).when(memberRepository).findById(memberId); + doReturn(member).when(memberFinder).findById(memberId); return member; } private Member member(long memberId, MemberDoll memberDoll, int dailyCottonCount) { Member member = MemberFixture.member().id(memberId).memberDoll(memberDoll).dailyCotton(dailyCottonCount).build(); - doReturn(Optional.of(member)).when(memberRepository).findById(memberId); + doReturn(member).when(memberFinder).findById(memberId); return member; } @@ -162,7 +158,7 @@ private List conversations(List conversationIds) { .content("conversation" + conversationId) .build() ).toList(); - doReturn(conversations).when(conversationRepository).findAll(); + doReturn(conversations).when(conversationFinder).findAll(); return conversations; } } From 906206f8b11d45e43f3335438e5087f3d5c21b2d Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 23 May 2024 19:34:28 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[CHORE]=20deleteMember=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/soptie/server/member/adapter/MemberDeleter.java | 2 +- .../com/soptie/server/member/service/MemberServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/soptie/server/member/adapter/MemberDeleter.java b/src/main/java/com/soptie/server/member/adapter/MemberDeleter.java index a6a8848a..1e94d10d 100644 --- a/src/main/java/com/soptie/server/member/adapter/MemberDeleter.java +++ b/src/main/java/com/soptie/server/member/adapter/MemberDeleter.java @@ -11,7 +11,7 @@ public class MemberDeleter { private final MemberRepository memberRepository; - public void deleteMember(Member member) { + public void delete(Member member) { memberRepository.delete(member); } } diff --git a/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java b/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java index d4596854..ee9f98c6 100644 --- a/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java +++ b/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java @@ -71,7 +71,7 @@ public MemberHomeInfoGetServiceResponse getMemberHomeInfo(MemberHomeInfoGetServi @Override public void deleteMember(Member member) { - memberDeleter.deleteMember(member); + memberDeleter.delete(member); } private void createDailyRoutines(Member member, List routineIds) { From 5e06b4272305acf2a28ba5286d38bc5b12e577b8 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Thu, 23 May 2024 19:44:39 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[CHORE]=20routine=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/soptie/server/member/service/MemberServiceImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java b/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java index ee9f98c6..84b96011 100644 --- a/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java +++ b/src/main/java/com/soptie/server/member/service/MemberServiceImpl.java @@ -75,7 +75,10 @@ public void deleteMember(Member member) { } private void createDailyRoutines(Member member, List routineIds) { - routineIds.forEach(id -> memberRoutineSaver.checkHasDeletedAndSave(member, routineFinder.findById(id))); + routineIds.forEach(id -> { + val routine = routineFinder.findById(id); + memberRoutineSaver.checkHasDeletedAndSave(member, routine); + }); } private void createMemberDoll(Member member, DollType dollType, String name) {