From 4471047b7b557fba908fc06b14cc06a9a3423994 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Tue, 21 Nov 2023 15:50:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=EB=B0=98=ED=99=98=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20MemberACtivityResponse=20->=20ActivityResponse?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #820 --- .../MemberActivityCommandService.java | 11 +++++---- .../MemberActivityCommandServiceTest.java | 24 +++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityCommandService.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityCommandService.java index 10d662412..58192eae9 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityCommandService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityCommandService.java @@ -2,6 +2,7 @@ import static java.util.stream.Collectors.toUnmodifiableList; +import com.emmsale.activity.application.dto.ActivityResponse; import com.emmsale.activity.domain.ActivityRepository; import com.emmsale.member.application.dto.MemberActivityAddRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; @@ -58,7 +59,7 @@ private void validateAllActivityIdsExist( } } - public List addActivity( + public List addActivity( final Member member, final MemberActivityAddRequest memberActivityAddRequest ) { @@ -74,7 +75,8 @@ public List addActivity( return memberActivityRepository.findAllByMember(member) .stream() - .map(MemberActivityResponse::from) + .map(MemberActivity::getActivity) + .map(ActivityResponse::from) .collect(toUnmodifiableList()); } @@ -91,7 +93,7 @@ private boolean hasDuplicateId(final List activityIds) { return new HashSet<>(activityIds).size() != activityIds.size(); } - public List deleteActivity( + public List deleteActivity( final Member member, final List deleteActivityIds ) { @@ -105,7 +107,8 @@ public List deleteActivity( return memberActivityRepository.findAllByMember(member) .stream() - .map(MemberActivityResponse::from) + .map(MemberActivity::getActivity) + .map(ActivityResponse::from) .collect(toUnmodifiableList()); } } diff --git a/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityCommandServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityCommandServiceTest.java index c78514045..625d2311b 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityCommandServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityCommandServiceTest.java @@ -6,10 +6,10 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import com.emmsale.activity.application.dto.ActivityResponse; import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.member.application.dto.MemberActivityAddRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; -import com.emmsale.member.application.dto.MemberActivityResponse; import com.emmsale.member.domain.Member; import com.emmsale.member.domain.MemberRepository; import com.emmsale.member.exception.MemberException; @@ -84,17 +84,17 @@ void addActivity() { final Member member = memberRepository.findById(savedMemberId).get(); final MemberActivityAddRequest request = new MemberActivityAddRequest(activityIds); - final List expected = List.of( - new MemberActivityResponse(1L, "YAPP", "동아리"), - new MemberActivityResponse(2L, "DND", "동아리"), - new MemberActivityResponse(3L, "nexters", "동아리"), - new MemberActivityResponse(5L, "인프콘", "컨퍼런스"), - new MemberActivityResponse(6L, "우아한테크코스", "교육"), - new MemberActivityResponse(7L, "Backend", "직무") + final List expected = List.of( + new ActivityResponse(1L, "동아리", "YAPP"), + new ActivityResponse(2L, "동아리", "DND"), + new ActivityResponse(3L, "동아리", "nexters"), + new ActivityResponse(4L, "컨퍼런스", "인프콘"), + new ActivityResponse(5L, "교육", "우아한테크코스"), + new ActivityResponse(6L, "직무", "Backend") ); //when - final List actual = memberActivityCommandService.addActivity(member, + final List actual = memberActivityCommandService.addActivity(member, request); //then assertThat(expected) @@ -154,12 +154,12 @@ void test_deleteActivity() throws Exception { final Member member = memberRepository.findById(savedMemberId).get(); - final List expected = List.of( - new MemberActivityResponse(3L, "nexters", "동아리") + final List expected = List.of( + new ActivityResponse(3L, "동아리", "nexters") ); //when - final List actual = memberActivityCommandService.deleteActivity(member, + final List actual = memberActivityCommandService.deleteActivity(member, deleteActivityIds); //then From 90b51389fd85aa38c0825924100126ed20c2a118 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Tue, 21 Nov 2023 17:19:02 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=EB=B0=98=ED=99=98=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20MemberACtivityResponse=20->=20ActivityResponse?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #840 --- .../MemberActivityQueryService.java | 8 ++-- .../MemberActivityQueryServiceTest.java | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityQueryServiceTest.java diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityQueryService.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityQueryService.java index b7ae5fe67..906983dd6 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityQueryService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityQueryService.java @@ -2,8 +2,9 @@ import static java.util.stream.Collectors.toUnmodifiableList; -import com.emmsale.member.application.dto.MemberActivityResponse; +import com.emmsale.activity.application.dto.ActivityResponse; import com.emmsale.member.domain.Member; +import com.emmsale.member.domain.MemberActivity; import com.emmsale.member.domain.MemberActivityRepository; import com.emmsale.member.domain.MemberRepository; import java.util.List; @@ -19,12 +20,13 @@ public class MemberActivityQueryService { private final MemberRepository memberRepository; private final MemberActivityRepository memberActivityRepository; - public List findActivities(final Long memberId) { + public List findActivities(final Long memberId) { final Member member = memberRepository.getByIdOrElseThrow(memberId); return memberActivityRepository.findAllByMember(member) .stream() - .map(MemberActivityResponse::from) + .map(MemberActivity::getActivity) + .map(ActivityResponse::from) .collect(toUnmodifiableList()); } } diff --git a/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityQueryServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityQueryServiceTest.java new file mode 100644 index 000000000..41d09729c --- /dev/null +++ b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityQueryServiceTest.java @@ -0,0 +1,40 @@ +package com.emmsale.member.application; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.emmsale.activity.application.dto.ActivityResponse; +import com.emmsale.helper.ServiceIntegrationTestHelper; +import com.emmsale.member.domain.MemberRepository; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +class MemberActivityQueryServiceTest extends ServiceIntegrationTestHelper { + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private MemberActivityQueryService memberActivityQueryService; + + @Test + @DisplayName("findActivities(): 유저의 Activity들을 조회한다.") + void findActivities() { + final Long memberId = 1L; + + final List actual + = memberActivityQueryService.findActivities(memberId); + + final List expected = List.of( + new ActivityResponse(1L, "동아리", "YAPP"), + new ActivityResponse(2L, "동아리", "DND"), + new ActivityResponse(3L, "동아리", "nexters") + ); + + assertThat(actual) + .usingRecursiveComparison() + .ignoringCollectionOrder() + .isEqualTo(expected); + } +} From e288371991100a332367f948f1168002b5ecf474 Mon Sep 17 00:00:00 2001 From: hong-sile Date: Tue, 21 Nov 2023 17:45:19 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20API=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #840 --- .../java/com/emmsale/MemberApiTest.java | 30 +++++++++---------- .../application/dto/ActivityResponse.java | 22 +++++--------- .../com/emmsale/member/api/MemberApi.java | 7 +++-- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java b/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java index 74ee8554c..2e14caf91 100644 --- a/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java +++ b/backend/emm-sale/src/documentTest/java/com/emmsale/MemberApiTest.java @@ -16,6 +16,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.emmsale.activity.application.dto.ActivityResponse; import com.emmsale.member.api.MemberApi; import com.emmsale.member.application.dto.DescriptionRequest; import com.emmsale.member.application.dto.MemberActivityAddRequest; @@ -95,10 +96,10 @@ void addActivity() throws Exception { final List activityIds = List.of(4L, 5L, 6L); final MemberActivityAddRequest request = new MemberActivityAddRequest(activityIds); - final List memberActivityResponses = createMemberActivityResponses(); + final List activityResponses = createActivityResponses(); when(memberActivityCommandService.addActivity(any(), any())) - .thenReturn(memberActivityResponses); + .thenReturn(activityResponses); //when & then mockMvc.perform(post("/members/activities") @@ -111,14 +112,14 @@ void addActivity() throws Exception { MEMBER_ACTIVITY_RESPONSE_FIELDS)); } - private List createMemberActivityResponses() { + private List createActivityResponses() { return List.of( - new MemberActivityResponse(1L, "YAPP", "동아리"), - new MemberActivityResponse(2L, "DND", "동아리"), - new MemberActivityResponse(3L, "nexters", "동아리"), - new MemberActivityResponse(4L, "인프콘", "컨퍼런스"), - new MemberActivityResponse(5L, "우아한테크코스", "교육"), - new MemberActivityResponse(6L, "Backend", "직무") + new ActivityResponse(1L, "YAPP", "동아리"), + new ActivityResponse(2L, "DND", "동아리"), + new ActivityResponse(3L, "nexters", "동아리"), + new ActivityResponse(4L, "인프콘", "컨퍼런스"), + new ActivityResponse(5L, "우아한테크코스", "교육"), + new ActivityResponse(6L, "Backend", "직무") ); } @@ -128,12 +129,12 @@ void test_deleteActivity() throws Exception { //given final String activityIds = "1,2"; - final List memberActivityResponses = List.of( - new MemberActivityResponse(3L, "nexters", "동아리") + final List activityResponses = List.of( + new ActivityResponse(3L, "nexters", "동아리") ); when(memberActivityCommandService.deleteActivity(any(), any())) - .thenReturn(memberActivityResponses); + .thenReturn(activityResponses); //when & then mockMvc.perform( @@ -149,11 +150,10 @@ void test_deleteActivity() throws Exception { @DisplayName("내 활동들을 조회할 수 있다.") void test_findActivity() throws Exception { //given - final List memberActivityResponse = createMemberActivityResponses(); + final List memberActivityResponse = createActivityResponses(); //when - when(memberActivityQueryService.findActivities(any())) - .thenReturn(memberActivityResponse); + when(memberActivityQueryService.findActivities(any())).thenReturn(memberActivityResponse); //then mockMvc.perform(get("/members/1/activities") diff --git a/backend/emm-sale/src/main/java/com/emmsale/activity/application/dto/ActivityResponse.java b/backend/emm-sale/src/main/java/com/emmsale/activity/application/dto/ActivityResponse.java index e101a9421..e7c6488dc 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/activity/application/dto/ActivityResponse.java +++ b/backend/emm-sale/src/main/java/com/emmsale/activity/application/dto/ActivityResponse.java @@ -1,9 +1,13 @@ package com.emmsale.activity.application.dto; import com.emmsale.activity.domain.Activity; +import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; @RequiredArgsConstructor +@ToString +@Getter public class ActivityResponse { private final Long id; @@ -12,21 +16,9 @@ public class ActivityResponse { public static ActivityResponse from(final Activity activity) { return new ActivityResponse( - activity.getId(), - activity.getActivityType().getValue(), - activity.getName() + activity.getId(), + activity.getActivityType().getValue(), + activity.getName() ); } - - public Long getId() { - return id; - } - - public String getActivityType() { - return activityType; - } - - public String getName() { - return name; - } } diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java b/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java index 6bf9b1958..406216ce4 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/api/MemberApi.java @@ -1,5 +1,6 @@ package com.emmsale.member.api; +import com.emmsale.activity.application.dto.ActivityResponse; import com.emmsale.member.application.MemberActivityCommandService; import com.emmsale.member.application.MemberActivityQueryService; import com.emmsale.member.application.MemberCommandService; @@ -46,7 +47,7 @@ public ResponseEntity register( } @PostMapping("/members/activities") - public ResponseEntity> addActivity( + public ResponseEntity> addActivity( final Member member, @RequestBody final MemberActivityAddRequest memberActivityAddRequest ) { @@ -55,14 +56,14 @@ public ResponseEntity> addActivity( } @DeleteMapping("/members/activities") - public ResponseEntity> deleteActivity(final Member member, + public ResponseEntity> deleteActivity(final Member member, @RequestParam("activity-ids") final List deleteActivityIds) { return ResponseEntity.ok( memberActivityCommandService.deleteActivity(member, deleteActivityIds)); } @GetMapping("/members/{member-id}/activities") - public ResponseEntity> findActivity( + public ResponseEntity> findActivity( @PathVariable("member-id") final Long memberId) { return ResponseEntity.ok(memberActivityQueryService.findActivities(memberId)); }