Skip to content

Commit

Permalink
feat: 행사의 전체 참여자 중 특정 참여자의 멤버 액션을 모두 삭제하는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
kunsanglee committed Aug 3, 2024
1 parent 0739181 commit 2c33bb2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ private Event findEvent(String token) {
return eventRepository.findByToken(token)
.orElseThrow(() -> new HaengdongException(HaengdongErrorCode.NOT_FOUND_EVENT));
}

public void deleteMember(String token, String memberName) {
eventRepository.findByToken(token)
.orElseThrow(() -> new HaengdongException(HaengdongErrorCode.NOT_FOUND_EVENT));
memberActionRepository.deleteAllByMemberName(memberName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
Expand All @@ -12,4 +13,12 @@ public interface MemberActionRepository extends JpaRepository<MemberAction, Long

@Query("select m from MemberAction m join fetch m.action where m.action.event = :event")
List<MemberAction> findAllByEvent(@Param("event") Event event);

@Modifying
@Query("""
delete
from MemberAction m
where m.memberName = :memberName
""")
void deleteAllByMemberName(String memberName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -36,4 +37,12 @@ public ResponseEntity<CurrentMembersResponse> getCurrentMembers(@PathVariable("e
return ResponseEntity.ok()
.body(CurrentMembersResponse.of(currentMembers));
}

@DeleteMapping("/api/events/{eventId}/members/{memberName}")
public ResponseEntity<Void> deleteMember(@PathVariable("eventId") String token,
@PathVariable("memberName") String memberName) {
memberActionService.deleteMember(token, memberName);

return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package server.haengdong.application;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
import static server.haengdong.domain.action.MemberActionStatus.IN;
import static server.haengdong.domain.action.MemberActionStatus.OUT;

Expand Down Expand Up @@ -89,4 +91,33 @@ void getCurrentMembers() {
assertThatThrownBy(() -> memberActionService.getCurrentMembers("token"))
.isInstanceOf(HaengdongException.class);
}

@DisplayName("행사의 전체 참여자 중에서 특정 참여자의 맴버 액션을 전부 삭제한다.")
@Test
void deleteMember() {
String token = "TOKEN";
Event event = new Event("행동대장 회식", token);
eventRepository.save(event);
Action action = Action.createFirst(event);
MemberAction memberAction1 = new MemberAction(action, "참여자", IN, 1L);
MemberAction memberAction2 = new MemberAction(action.next(), "토다리", IN, 1L);
MemberAction memberAction3 = new MemberAction(action.next(), "쿠키", IN, 1L);
MemberAction memberAction4 = new MemberAction(action.next(), "소하", IN, 1L);
MemberAction memberAction5 = new MemberAction(action.next(), "웨디", IN, 1L);
MemberAction memberAction6 = new MemberAction(action.next(), "참여자", OUT, 1L);
memberActionRepository.saveAll(
List.of(memberAction1, memberAction2, memberAction3, memberAction4, memberAction5, memberAction6));

memberActionService.deleteMember(token, "참여자");

List<MemberAction> memberActions = memberActionRepository.findAll();
assertThat(memberActions).hasSize(4)
.extracting("memberName", "status")
.containsExactly(
tuple("토다리", IN),
tuple("쿠키", IN),
tuple("소하", IN),
tuple("웨디", IN)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand Down Expand Up @@ -64,4 +65,15 @@ void getCurrentMembers() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$.members[0].name").value(equalTo("소하")))
.andExpect(MockMvcResultMatchers.jsonPath("$.members[1].name").value(equalTo("토다리")));
}

@DisplayName("행사의 전체 참여자 중에서 특정 참여자의 맴버 액션을 전부 삭제한다.")
@Test
void deleteMember() throws Exception {
Long eventId = 1L;
String memberName = "행동대장";

mockMvc.perform(delete("/api/events/{eventId}/members/{memberName}", eventId, memberName))
.andDo(print())
.andExpect(status().isOk());
}
}

0 comments on commit 2c33bb2

Please sign in to comment.