Skip to content

Commit

Permalink
Merge branch 'refs/heads/be-dev' into feature/#193
Browse files Browse the repository at this point in the history
# Conflicts:
#	server/src/main/java/server/haengdong/application/EventService.java
#	server/src/main/java/server/haengdong/presentation/EventController.java
#	server/src/test/java/server/haengdong/application/EventServiceTest.java
#	server/src/test/java/server/haengdong/presentation/EventControllerTest.java
  • Loading branch information
Arachneee committed Aug 5, 2024
2 parents dfab28a + a7c942e commit 33e9746
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: [ self-hosted, backend-dev ]

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backend-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: [ self-hosted, backend-dev ]

defaults:
run:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import server.haengdong.application.response.ActionAppResponse;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.application.response.EventDetailAppResponse;
import server.haengdong.application.response.MembersAppResponse;
import server.haengdong.domain.action.BillAction;
import server.haengdong.domain.action.BillActionRepository;
import server.haengdong.domain.action.MemberAction;
Expand Down Expand Up @@ -90,6 +91,15 @@ private List<ActionAppResponse> getActionAppResponses(
return actionAppResponses;
}

public MembersAppResponse findAllMembers(String token) {
Event event = eventRepository.findByToken(token)
.orElseThrow(() -> new HaengdongException(HaengdongErrorCode.NOT_FOUND_EVENT));

List<String> memberNames = memberActionRepository.findAllUniqueMemberByEvent(event);

return new MembersAppResponse(memberNames);
}

@Transactional
public void updateMember(String token, String memberName, MemberUpdateAppRequest request) {
Event event = eventRepository.findByToken(token)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package server.haengdong.application.response;

import java.util.List;

public record MembersAppResponse(
List<String> memberNames
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ 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);

@Query("""
select distinct m.memberName
from MemberAction m
where m.action.event = :event
""")
List<String> findAllUniqueMemberByEvent(Event event);

@Modifying
@Query("""
delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import server.haengdong.presentation.request.MemberUpdateRequest;
import server.haengdong.presentation.response.EventDetailResponse;
import server.haengdong.presentation.response.EventResponse;
import server.haengdong.presentation.response.MembersResponse;
import server.haengdong.presentation.response.StepsResponse;

@RequiredArgsConstructor
Expand Down Expand Up @@ -43,6 +44,13 @@ public ResponseEntity<StepsResponse> findActions(@PathVariable("eventId") String
return ResponseEntity.ok(stepsResponse);
}

@GetMapping("/api/events/{eventId}/members")
public ResponseEntity<MembersResponse> findAllMembers(@PathVariable("eventId") String token) {
MembersResponse response = MembersResponse.of(eventService.findAllMembers(token));

return ResponseEntity.ok(response);
}

@PutMapping("/api/events/{eventId}/members/{memberName}")
public ResponseEntity<Void> updateMember(
@PathVariable("eventId") String token,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package server.haengdong.presentation.response;

import java.util.List;
import server.haengdong.application.response.MembersAppResponse;

public record MembersResponse(
List<String> memberNames
) {

public static MembersResponse of(MembersAppResponse response) {
return new MembersResponse(response.memberNames());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import server.haengdong.application.response.ActionAppResponse;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.application.response.EventDetailAppResponse;
import server.haengdong.application.response.MembersAppResponse;
import server.haengdong.domain.action.Action;
import server.haengdong.domain.action.ActionRepository;
import server.haengdong.domain.action.BillAction;
Expand Down Expand Up @@ -112,6 +113,28 @@ void findActionsTest() {
);
}

@DisplayName("행사에 μ°Έμ—¬ν•œ 전체 인원을 쀑볡 없이 μ‘°νšŒν•œλ‹€.")
@Test
void findAllMembersTest() {
String token = "웨디_토큰";
Event event = new Event("ν–‰λ™λŒ€μž₯ νšŒμ‹", token);
Action action1 = new Action(event, 1L);
Action action2 = new Action(event, 2L);
Action action3 = new Action(event, 3L);
Action action4 = new Action(event, 4L);
BillAction billAction = new BillAction(action3, "λ½•λ‚˜λ¬΄μŸμ΄μ‘±λ°œ", 30000L);
MemberAction memberAction1 = new MemberAction(action1, "토닀리", IN, 1L);
MemberAction memberAction2 = new MemberAction(action2, "μΏ ν‚€", IN, 1L);
MemberAction memberAction3 = new MemberAction(action4, "μΏ ν‚€", OUT, 1L);
eventRepository.save(event);
billActionRepository.save(billAction);
memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3));

MembersAppResponse membersAppResponse = eventService.findAllMembers(token);

assertThat(membersAppResponse.memberNames()).containsExactlyInAnyOrder("토닀리", "μΏ ν‚€");
}

@DisplayName("행사 μ°Έμ—¬ μΈμ›μ˜ 이름을 λ³€κ²½ν•œλ‹€.")
@Test
void updateMember() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server.haengdong.presentation;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand All @@ -10,6 +11,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -21,6 +23,7 @@
import server.haengdong.application.request.EventAppRequest;
import server.haengdong.application.response.EventAppResponse;
import server.haengdong.application.response.EventDetailAppResponse;
import server.haengdong.application.response.MembersAppResponse;
import server.haengdong.presentation.request.EventSaveRequest;
import server.haengdong.presentation.request.MemberUpdateRequest;

Expand Down Expand Up @@ -66,6 +69,20 @@ void findEventTest() throws Exception {
.andExpect(jsonPath("$.eventName").value("ν–‰λ™λŒ€μž₯ νšŒμ‹"));
}

@DisplayName("행사에 μ°Έμ—¬ν•œ 전체 인원을 쀑볡 없이 μ‘°νšŒν•œλ‹€.")
@Test
void findAllMembersTest() throws Exception {
MembersAppResponse memberAppResponse = new MembersAppResponse(List.of("토닀리", "μΏ ν‚€"));
given(eventService.findAllMembers(anyString())).willReturn(memberAppResponse);

mockMvc.perform(get("/api/events/{eventId}/members", "TOKEN"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.memberNames").isArray())
.andExpect(jsonPath("$.memberNames[0]").value("토닀리"))
.andExpect(jsonPath("$.memberNames[1]").value("μΏ ν‚€"));
}

@DisplayName("행사 μ°Έμ—¬ μΈμ›μ˜ 이름을 μˆ˜μ •ν•œλ‹€.")
@Test
void updateMember() throws Exception {
Expand Down

0 comments on commit 33e9746

Please sign in to comment.