Skip to content

Commit

Permalink
refactor: 삭제 요청시 활동 id 목록을 body로 받는 것에서 param으로 받는 것으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjerry committed Aug 16, 2023
1 parent 942e1b8 commit cdb3fb0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -51,12 +51,10 @@ public ResponseEntity<List<MemberActivityResponses>> addActivity(
}

@DeleteMapping("/members/activities")
public ResponseEntity<List<MemberActivityResponses>> deleteActivity(
final Member member,
@RequestBody final MemberActivityDeleteRequest memberActivityDeleteRequest
) {
public ResponseEntity<List<MemberActivityResponses>> deleteActivity(final Member member,
@RequestParam("activity-ids") final List<Long> deleteActivityIds) {
return ResponseEntity.ok(
memberActivityService.deleteActivity(member, memberActivityDeleteRequest));
memberActivityService.deleteActivity(member, deleteActivityIds));
}

@GetMapping("/members/{member-id}/activities")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,10 +92,8 @@ private boolean hasDuplicateId(final List<Long> activityIds) {

public List<MemberActivityResponses> deleteActivity(
final Member member,
final MemberActivityDeleteRequest memberActivityDeleteRequest
final List<Long> deleteActivityIds
) {
final List<Long> deleteActivityIds = memberActivityDeleteRequest.getActivityIds();

final List<Long> savedMemberActivityIds =
memberActivityRepository.findAllByMemberAndActivityIds(member, deleteActivityIds)
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,8 +139,7 @@ void addActivity() throws Exception {
@DisplayName("내 명함에서 활동이력들을 성공적으로 삭제하면, 200 OK를 반환해줄 수 있다.")
void test_deleteActivity() throws Exception {
//given
final List<Long> activityIds = List.of(1L, 2L);
final MemberActivityDeleteRequest request = new MemberActivityDeleteRequest(activityIds);
final String activityIds = "1,2";

final List<MemberActivityResponses> memberActivityResponses = List.of(
new MemberActivityResponses("동아리",
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MemberActivityResponses> expected = List.of(
new MemberActivityResponses("동아리",
Expand All @@ -176,7 +174,7 @@ void test_deleteActivity() throws Exception {

//when
final List<MemberActivityResponses> actual = memberActivityService.deleteActivity(member,
request);
deleteActivityIds);

//then
assertThat(expected)
Expand Down

0 comments on commit cdb3fb0

Please sign in to comment.