Skip to content

Commit

Permalink
feat: 액션 이력 조회 v2 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachneee committed Aug 16, 2024
1 parent 92dd8ce commit 56b5809
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server.haengdong.presentation;

import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -15,10 +16,12 @@
import org.springframework.web.bind.annotation.RestController;
import server.haengdong.application.AuthService;
import server.haengdong.application.EventService;
import server.haengdong.application.response.ActionAppResponse;
import server.haengdong.infrastructure.auth.CookieProperties;
import server.haengdong.presentation.request.EventLoginRequest;
import server.haengdong.presentation.request.EventSaveRequest;
import server.haengdong.presentation.request.MemberNamesUpdateRequest;
import server.haengdong.presentation.response.ActionsResponse;
import server.haengdong.presentation.response.EventDetailResponse;
import server.haengdong.presentation.response.EventResponse;
import server.haengdong.presentation.response.MembersResponse;
Expand Down Expand Up @@ -60,6 +63,14 @@ public ResponseEntity<StepsResponse> findActions(@PathVariable("eventId") String
return ResponseEntity.ok(stepsResponse);
}

@GetMapping("/api/events/{eventId}/actions/v2")
public ResponseEntity<ActionsResponse> findActions2(@PathVariable("eventId") String token) {
List<ActionAppResponse> actions = eventService.findActions(token);
ActionsResponse actionsResponse = ActionsResponse.of(actions);

return ResponseEntity.ok(actionsResponse);
}

@GetMapping("/api/events/{eventId}/members")
public ResponseEntity<MembersResponse> findAllMembers(@PathVariable("eventId") String token) {
MembersResponse response = MembersResponse.of(eventService.findAllMembers(token));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package server.haengdong.presentation.response;

import server.haengdong.application.response.ActionAppResponse;

public record ActionResponse2(
Long actionId,
String name,
Long price,
Long sequence,
String type
) {

public static ActionResponse2 of(ActionAppResponse actionAppResponse) {
return new ActionResponse2(
actionAppResponse.actionId(),
actionAppResponse.name(),
actionAppResponse.price(),
actionAppResponse.sequence(),
actionAppResponse.actionType().name()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package server.haengdong.presentation.response;

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

public record ActionsResponse(
List<ActionResponse2> actions
) {
public static ActionsResponse of(List<ActionAppResponse> actions) {
return new ActionsResponse(actions.stream()
.map(ActionResponse2::of)
.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,69 @@ void findActions() throws Exception {
);
}

@DisplayName("행사 전체 액션 이력 조회 v2")
@Test
void findActions2() throws Exception {
String token = "TOKEN";
List<ActionAppResponse> actionAppResponses = List.of(
new ActionAppResponse(1L, "망쵸", null, 1L, ActionType.IN),
new ActionAppResponse(2L, "족발", 100L, 2L, ActionType.BILL),
new ActionAppResponse(3L, "인생네컷", 1000L, 3L, ActionType.BILL),
new ActionAppResponse(4L, "망쵸", null, 4L, ActionType.OUT)
);
given(eventService.findActions(token)).willReturn(actionAppResponses);

mockMvc.perform(get("/api/events/{eventId}/actions/v2", token)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.actions[0].actionId").value(equalTo(1)))
.andExpect(jsonPath("$.actions[0].name").value(equalTo("망쵸")))
.andExpect(jsonPath("$.actions[0].price").value(equalTo(null)))
.andExpect(jsonPath("$.actions[0].sequence").value(equalTo(1)))
.andExpect(jsonPath("$.actions[0].type").value(equalTo("IN")))

.andExpect(jsonPath("$.actions[1].actionId").value(equalTo(2)))
.andExpect(jsonPath("$.actions[1].name").value(equalTo("족발")))
.andExpect(jsonPath("$.actions[1].price").value(equalTo(100)))
.andExpect(jsonPath("$.actions[1].sequence").value(equalTo(2)))
.andExpect(jsonPath("$.actions[1].type").value(equalTo("BILL")))

.andExpect(jsonPath("$.actions[2].actionId").value(equalTo(3)))
.andExpect(jsonPath("$.actions[2].name").value(equalTo("인생네컷")))
.andExpect(jsonPath("$.actions[2].price").value(equalTo(1000)))
.andExpect(jsonPath("$.actions[2].sequence").value(equalTo(3)))
.andExpect(jsonPath("$.actions[2].type").value(equalTo("BILL")))

.andExpect(jsonPath("$.actions[3].actionId").value(equalTo(4)))
.andExpect(jsonPath("$.actions[3].name").value(equalTo("망쵸")))
.andExpect(jsonPath("$.actions[3].price").value(equalTo(null)))
.andExpect(jsonPath("$.actions[3].sequence").value(equalTo(4)))
.andExpect(jsonPath("$.actions[3].type").value(equalTo("OUT")))

.andDo(
document("findActions",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
pathParameters(
parameterWithName("eventId").description("행사 ID")
),
responseFields(
fieldWithPath("actions[].actionId").type(JsonFieldType.NUMBER)
.description("액션 ID"),
fieldWithPath("actions[].name").type(JsonFieldType.STRING)
.description("참여자 액션일 경우 참여자 이름, 지출 액션일 경우 지출 내역 이름"),
fieldWithPath("actions[].price").type(JsonFieldType.NUMBER).optional()
.description("참여자 액션일 경우 null, 지출 액션일 경우 지출 금액"),
fieldWithPath("actions[].sequence").type(JsonFieldType.NUMBER)
.description("액션 순서"),
fieldWithPath("actions[].type").type(JsonFieldType.STRING)
.description("액션 타입")
)
)
);
}

@DisplayName("행사 어드민 권한을 확인한다.")
@Test
void authenticateTest() throws Exception {
Expand Down

0 comments on commit 56b5809

Please sign in to comment.