Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/main/java/side/onetime/controller/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,6 @@ public ResponseEntity<ApiResponse<List<GetMostPossibleTime>>> getFilteredMostPos
return ApiResponse.onSuccess(SuccessStatus._GET_FILTERED_MOST_POSSIBLE_TIME, getFilteredMostPossibleTimes);
}

/**
* 유저 참여 이벤트 목록 조회 API.
*
* 이 API는 인증된 유저가 참여한 모든 이벤트 목록을 조회합니다. 유저의 참여 상태, 이벤트 정보 등이 포함됩니다.
*
* @return 유저가 참여한 이벤트 목록
*/
@GetMapping("/user/all")
public ResponseEntity<ApiResponse<List<GetUserParticipatedEventsResponse>>> getUserParticipatedEvents() {

List<GetUserParticipatedEventsResponse> getUserParticipatedEventsResponses = eventService.getUserParticipatedEvents();
return ApiResponse.onSuccess(SuccessStatus._GET_USER_PARTICIPATED_EVENTS, getUserParticipatedEventsResponses);
}

/**
* 유저 참여 이벤트 목록 조회 API.
*
Expand All @@ -144,7 +130,7 @@ public ResponseEntity<ApiResponse<List<GetUserParticipatedEventsResponse>>> getU
* @param createdDate 마지막으로 조회한 이벤트 생성일
* @return 유저가 참여한 이벤트 목록 및 페이지(커서) 정보가 포함된 응답 DTO
*/
@GetMapping("/user/all/v2")
@GetMapping("/user/all")
public ResponseEntity<ApiResponse<GetParticipatedEventsResponse>> getParticipatedEventsByCursor(
@RequestParam(value = "size", defaultValue = "2") @Min(1) int size,
@RequestParam(value = "cursor", required = false) LocalDateTime createdDate
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public enum SuccessStatus implements BaseCode {
_GET_PARTICIPANTS(HttpStatus.OK, "200", "참여자 조회에 성공했습니다."),
_GET_MOST_POSSIBLE_TIME(HttpStatus.OK, "200", "가장 많이 되는 시간 조회에 성공했습니다."),
_GET_FILTERED_MOST_POSSIBLE_TIME(HttpStatus.OK, "200", "필터링한 참여자의 시간 조회에 성공했습니다."),
_GET_USER_PARTICIPATED_EVENTS(HttpStatus.OK, "200", "유저 참여 이벤트 목록 조회에 성공했습니다."),
_GET_PARTICIPATED_EVENTS(HttpStatus.OK, "200", "유저 참여 이벤트 목록 조회에 성공했습니다."),
_REMOVE_USER_CREATED_EVENT(HttpStatus.OK, "200", "유저가 생성한 이벤트 삭제에 성공했습니다."),
_MODIFY_EVENT(HttpStatus.OK, "200", "이벤트 수정에 성공했습니다."),
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/side/onetime/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,45 +518,6 @@ private boolean isDateFormat(String range) {
return Character.isDigit(range.charAt(0));
}

/**
* 유저 참여 이벤트 반환 메서드.
* 인증된 유저가 참여한 모든 이벤트 목록을 조회하며, 각 이벤트에 대한 세부 정보를 반환합니다.
*
* @return 유저가 참여한 이벤트 목록
*/
@Transactional(readOnly = true)
public List<GetUserParticipatedEventsResponse> getUserParticipatedEvents() {
User user = userRepository.findById(UserAuthorizationUtil.getLoginUserId())
.orElseThrow(() -> new CustomException(UserErrorStatus._NOT_FOUND_USER));

List<EventParticipation> participations = eventParticipationRepository.findAllByUserWithEvent(user);

// 캐시 맵 선언
Map<String, GetParticipantsResponse> participantsCache = new HashMap<>();
Map<String, List<GetMostPossibleTime>> mostPossibleCache = new HashMap<>();

return participations.stream()
.sorted(Comparator.comparing((EventParticipation ep) -> ep.getEvent().getCreatedDate()).reversed())
.map(ep -> {
Event event = ep.getEvent();
String eventId = event.getEventId().toString();

// 캐시 또는 메서드 실행
GetParticipantsResponse participants = participantsCache.computeIfAbsent(
eventId, this::getParticipants);
List<GetMostPossibleTime> mostPossibleTimes = mostPossibleCache.computeIfAbsent(
eventId, this::getMostPossibleTime);

return GetUserParticipatedEventsResponse.of(
event,
ep,
participants.users().size() + participants.members().size(),
mostPossibleTimes
);
})
.collect(Collectors.toList());
}

/**
* 유저 참여 이벤트 목록 조회 메서드.
*
Expand Down Expand Up @@ -598,7 +559,6 @@ public GetParticipatedEventsResponse getParticipatedEventsByCursor(int size, Loc
return GetParticipatedEventsResponse.of(userParticipatedEvents, pageCursorInfo);
}


/**
* 유저가 생성한 이벤트 삭제 메서드.
* 인증된 유저가 생성한 특정 이벤트를 삭제합니다.
Expand Down
69 changes: 1 addition & 68 deletions src/test/java/side/onetime/event/EventControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,73 +382,6 @@ public void getFilteredMostPossibleTimes() throws Exception {
));
}

@Test
@DisplayName("유저 참여 이벤트 목록을 조회한다.")
public void getUserParticipatedEvents() throws Exception {
// given
List<GetUserParticipatedEventsResponse> response = List.of(
new GetUserParticipatedEventsResponse(
UUID.randomUUID(),
Category.DATE,
"Sample Event",
"2024.11.13",
10,
EventStatus.CREATOR,
List.of(
new GetMostPossibleTime("2024.11.13", "10:00", "10:30", 5, List.of("User1", "User2"), List.of("User3"))
)
)
);

Mockito.when(eventService.getUserParticipatedEvents()).thenReturn(response);

// when
ResultActions resultActions = this.mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/events/user/all")
.header(HttpHeaders.AUTHORIZATION, "Bearer sampleToken")
.accept(MediaType.APPLICATION_JSON));

// then
resultActions
.andExpect(status().isOk())
.andExpect(jsonPath("$.is_success").value(true))
.andExpect(jsonPath("$.code").value("200"))
.andExpect(jsonPath("$.message").value("유저 참여 이벤트 목록 조회에 성공했습니다."))
.andExpect(jsonPath("$.payload[0].event_id").exists())
.andExpect(jsonPath("$.payload[0].title").value("Sample Event"))

// docs
.andDo(MockMvcRestDocumentationWrapper.document("event/get-user-participated-events",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
resource(
ResourceSnippetParameters.builder()
.tag("Event API")
.description("유저가 참여한 이벤트 목록을 조회한다.")
.responseFields(
fieldWithPath("is_success").type(JsonFieldType.BOOLEAN).description("성공 여부"),
fieldWithPath("code").type(JsonFieldType.STRING).description("응답 코드"),
fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지"),
fieldWithPath("payload").type(JsonFieldType.ARRAY).description("참여 이벤트 목록"),
fieldWithPath("payload[].event_id").type(JsonFieldType.STRING).description("이벤트 ID"),
fieldWithPath("payload[].category").type(JsonFieldType.STRING).description("이벤트 카테고리"),
fieldWithPath("payload[].title").type(JsonFieldType.STRING).description("이벤트 제목"),
fieldWithPath("payload[].created_date").type(JsonFieldType.STRING).description("이벤트 생성일"),
fieldWithPath("payload[].participant_count").type(JsonFieldType.NUMBER).description("참여자 수"),
fieldWithPath("payload[].event_status").type(JsonFieldType.STRING).description("이벤트 참여 상태"),
fieldWithPath("payload[].most_possible_times").type(JsonFieldType.ARRAY).description("가장 많이 가능한 시간대"),
fieldWithPath("payload[].most_possible_times[].time_point").type(JsonFieldType.STRING).description("날짜 또는 요일"),
fieldWithPath("payload[].most_possible_times[].start_time").type(JsonFieldType.STRING).description("시작 시간"),
fieldWithPath("payload[].most_possible_times[].end_time").type(JsonFieldType.STRING).description("종료 시간"),
fieldWithPath("payload[].most_possible_times[].possible_count").type(JsonFieldType.NUMBER).description("가능한 참여자 수"),
fieldWithPath("payload[].most_possible_times[].possible_names").type(JsonFieldType.ARRAY).description("참여 가능한 유저 이름 목록"),
fieldWithPath("payload[].most_possible_times[].impossible_names").type(JsonFieldType.ARRAY).description("참여 불가능한 유저 이름 목록")
)
.responseSchema(Schema.schema("GetUserParticipatedEventsResponseSchema"))
.build()
)
));
}

@Test
@DisplayName("유저 참여 이벤트 목록을 조회한다.")
public void getParticipatedEventsByCursor() throws Exception {
Expand All @@ -474,7 +407,7 @@ public void getParticipatedEventsByCursor() throws Exception {
Mockito.when(eventService.getParticipatedEventsByCursor(anyInt(), any(LocalDateTime.class))).thenReturn(response);

// when
ResultActions resultActions = this.mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/events/user/all/v2")
ResultActions resultActions = this.mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/events/user/all")
.header(HttpHeaders.AUTHORIZATION, "Bearer sampleToken")
.param("size", String.valueOf(size))
.param("cursor", createdDate)
Expand Down
Loading