From 942e1b8a140fd5198676fbfb9d9fa2df1a32bd47 Mon Sep 17 00:00:00 2001 From: HyeonjaeKwon Date: Wed, 16 Aug 2023 15:31:40 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EC=A4=91=EB=B3=B5=EB=90=9C=20?= =?UTF-8?q?=ED=99=9C=EB=8F=99=20id=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #377 --- .../emmsale/member/application/MemberActivityService.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java index 128457ade..0f2bb2f17 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java @@ -67,7 +67,7 @@ public List addActivity( ) { final List activityIds = memberActivityAddRequest.getActivityIds(); final List memberActivities = memberActivityRepository.findAllByMember(member); - if (hasDuplicateId(memberActivities, activityIds)) { + if (hasDuplicateId(activityIds)) { throw new MemberException(MemberExceptionType.DUPLICATE_ACTIVITY); } if (isAlreadyExistActivity(memberActivities, activityIds)) { @@ -87,9 +87,8 @@ private boolean isAlreadyExistActivity(final List memberActiviti ); } - private boolean hasDuplicateId(final List memberActivities, - final List activityIds) { - return new HashSet<>(activityIds).size() != memberActivities.size(); + private boolean hasDuplicateId(final List activityIds) { + return new HashSet<>(activityIds).size() != activityIds.size(); } public List deleteActivity( From cdb3fb035015d397410a232e39a40c5b6de36c11 Mon Sep 17 00:00:00 2001 From: HyeonjaeKwon Date: Wed, 16 Aug 2023 16:00:05 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EC=82=AD=EC=A0=9C=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=EC=8B=9C=20=ED=99=9C=EB=8F=99=20id=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=EC=9D=84=20body=EB=A1=9C=20=EB=B0=9B=EB=8A=94=20?= =?UTF-8?q?=EA=B2=83=EC=97=90=EC=84=9C=20param=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=9B=EB=8A=94=20=EA=B2=83=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #377 --- .../main/java/com/emmsale/member/api/MemberApi.java | 10 ++++------ .../member/application/MemberActivityService.java | 5 +---- .../java/com/emmsale/member/api/MemberApiTest.java | 12 ++++-------- .../application/MemberActivityServiceTest.java | 4 +--- 4 files changed, 10 insertions(+), 21 deletions(-) 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 9532674e9..63c640ea9 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 @@ -5,7 +5,6 @@ import com.emmsale.member.application.MemberUpdateService; import com.emmsale.member.application.dto.DescriptionRequest; import com.emmsale.member.application.dto.MemberActivityAddRequest; -import com.emmsale.member.application.dto.MemberActivityDeleteRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; import com.emmsale.member.application.dto.MemberActivityResponses; import com.emmsale.member.application.dto.MemberProfileResponse; @@ -22,6 +21,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -51,12 +51,10 @@ public ResponseEntity> addActivity( } @DeleteMapping("/members/activities") - public ResponseEntity> deleteActivity( - final Member member, - @RequestBody final MemberActivityDeleteRequest memberActivityDeleteRequest - ) { + public ResponseEntity> deleteActivity(final Member member, + @RequestParam("activity-ids") final List deleteActivityIds) { return ResponseEntity.ok( - memberActivityService.deleteActivity(member, memberActivityDeleteRequest)); + memberActivityService.deleteActivity(member, deleteActivityIds)); } @GetMapping("/members/{member-id}/activities") diff --git a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java index 0f2bb2f17..692ba147a 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/member/application/MemberActivityService.java @@ -4,7 +4,6 @@ import com.emmsale.activity.domain.ActivityRepository; import com.emmsale.member.application.dto.MemberActivityAddRequest; -import com.emmsale.member.application.dto.MemberActivityDeleteRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; import com.emmsale.member.application.dto.MemberActivityResponses; import com.emmsale.member.domain.Member; @@ -93,10 +92,8 @@ private boolean hasDuplicateId(final List activityIds) { public List deleteActivity( final Member member, - final MemberActivityDeleteRequest memberActivityDeleteRequest + final List deleteActivityIds ) { - final List deleteActivityIds = memberActivityDeleteRequest.getActivityIds(); - final List savedMemberActivityIds = memberActivityRepository.findAllByMemberAndActivityIds(member, deleteActivityIds) .stream() diff --git a/backend/emm-sale/src/test/java/com/emmsale/member/api/MemberApiTest.java b/backend/emm-sale/src/test/java/com/emmsale/member/api/MemberApiTest.java index bd3c08fb6..05d149836 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/member/api/MemberApiTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/member/api/MemberApiTest.java @@ -21,7 +21,6 @@ import com.emmsale.member.application.MemberUpdateService; import com.emmsale.member.application.dto.DescriptionRequest; import com.emmsale.member.application.dto.MemberActivityAddRequest; -import com.emmsale.member.application.dto.MemberActivityDeleteRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; import com.emmsale.member.application.dto.MemberActivityResponse; import com.emmsale.member.application.dto.MemberActivityResponses; @@ -140,8 +139,7 @@ void addActivity() throws Exception { @DisplayName("내 명함에서 활동이력들을 성공적으로 삭제하면, 200 OK를 반환해줄 수 있다.") void test_deleteActivity() throws Exception { //given - final List activityIds = List.of(1L, 2L); - final MemberActivityDeleteRequest request = new MemberActivityDeleteRequest(activityIds); + final String activityIds = "1,2"; final List memberActivityResponses = List.of( new MemberActivityResponses("동아리", @@ -154,13 +152,11 @@ void test_deleteActivity() throws Exception { .thenReturn(memberActivityResponses); //when & then - mockMvc.perform(delete("/members/activities") - .header(HttpHeaders.AUTHORIZATION, "Bearer AccessToken") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) + mockMvc.perform(delete("/members/activities?activity-ids={activityIds}", activityIds) + .header(HttpHeaders.AUTHORIZATION, "Bearer AccessToken")) .andExpect(status().isOk()) .andDo(print()) - .andDo(document("delete-activity", MEMBER_ACTIVITY_REQUEST_FIELDS, + .andDo(document("delete-activity", MEMBER_ACTIVITY_RESPONSE_FIELDS)); } diff --git a/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityServiceTest.java index c4a3d203a..2551fae99 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/member/application/MemberActivityServiceTest.java @@ -8,7 +8,6 @@ import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.member.application.dto.MemberActivityAddRequest; -import com.emmsale.member.application.dto.MemberActivityDeleteRequest; import com.emmsale.member.application.dto.MemberActivityInitialRequest; import com.emmsale.member.application.dto.MemberActivityResponse; import com.emmsale.member.application.dto.MemberActivityResponses; @@ -165,7 +164,6 @@ void test_deleteActivity() throws Exception { final long savedMemberId = 1L; final Member member = memberRepository.findById(savedMemberId).get(); - final MemberActivityDeleteRequest request = new MemberActivityDeleteRequest(deleteActivityIds); final List expected = List.of( new MemberActivityResponses("동아리", @@ -176,7 +174,7 @@ void test_deleteActivity() throws Exception { //when final List actual = memberActivityService.deleteActivity(member, - request); + deleteActivityIds); //then assertThat(expected)