Skip to content

Commit

Permalink
merge: fix: 중복된 활동 id 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjerry authored Aug 17, 2023
2 parents d510e3b + cdb3fb0 commit f326864
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 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 @@ -67,7 +66,7 @@ public List<MemberActivityResponses> addActivity(
) {
final List<Long> activityIds = memberActivityAddRequest.getActivityIds();
final List<MemberActivity> memberActivities = memberActivityRepository.findAllByMember(member);
if (hasDuplicateId(memberActivities, activityIds)) {
if (hasDuplicateId(activityIds)) {
throw new MemberException(MemberExceptionType.DUPLICATE_ACTIVITY);
}
if (isAlreadyExistActivity(memberActivities, activityIds)) {
Expand All @@ -87,17 +86,14 @@ private boolean isAlreadyExistActivity(final List<MemberActivity> memberActiviti
);
}

private boolean hasDuplicateId(final List<MemberActivity> memberActivities,
final List<Long> activityIds) {
return new HashSet<>(activityIds).size() != memberActivities.size();
private boolean hasDuplicateId(final List<Long> activityIds) {
return new HashSet<>(activityIds).size() != activityIds.size();
}

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 f326864

Please sign in to comment.