diff --git a/src/main/java/side/onetime/controller/EventController.java b/src/main/java/side/onetime/controller/EventController.java index 3571a4b..2ee279c 100644 --- a/src/main/java/side/onetime/controller/EventController.java +++ b/src/main/java/side/onetime/controller/EventController.java @@ -118,20 +118,6 @@ public ResponseEntity>> getFilteredMostPos return ApiResponse.onSuccess(SuccessStatus._GET_FILTERED_MOST_POSSIBLE_TIME, getFilteredMostPossibleTimes); } - /** - * 유저 참여 이벤트 목록 조회 API. - * - * 이 API는 인증된 유저가 참여한 모든 이벤트 목록을 조회합니다. 유저의 참여 상태, 이벤트 정보 등이 포함됩니다. - * - * @return 유저가 참여한 이벤트 목록 - */ - @GetMapping("/user/all") - public ResponseEntity>> getUserParticipatedEvents() { - - List getUserParticipatedEventsResponses = eventService.getUserParticipatedEvents(); - return ApiResponse.onSuccess(SuccessStatus._GET_USER_PARTICIPATED_EVENTS, getUserParticipatedEventsResponses); - } - /** * 유저 참여 이벤트 목록 조회 API. * @@ -144,7 +130,7 @@ public ResponseEntity>> getU * @param createdDate 마지막으로 조회한 이벤트 생성일 * @return 유저가 참여한 이벤트 목록 및 페이지(커서) 정보가 포함된 응답 DTO */ - @GetMapping("/user/all/v2") + @GetMapping("/user/all") public ResponseEntity> getParticipatedEventsByCursor( @RequestParam(value = "size", defaultValue = "2") @Min(1) int size, @RequestParam(value = "cursor", required = false) LocalDateTime createdDate diff --git a/src/main/java/side/onetime/dto/event/response/GetUserParticipatedEventsResponse.java b/src/main/java/side/onetime/dto/event/response/GetUserParticipatedEventsResponse.java deleted file mode 100644 index affac00..0000000 --- a/src/main/java/side/onetime/dto/event/response/GetUserParticipatedEventsResponse.java +++ /dev/null @@ -1,36 +0,0 @@ -package side.onetime.dto.event.response; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import side.onetime.domain.Event; -import side.onetime.domain.EventParticipation; -import side.onetime.domain.enums.Category; -import side.onetime.domain.enums.EventStatus; - -import java.util.List; -import java.util.UUID; - -@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) -@JsonInclude(JsonInclude.Include.NON_NULL) -public record GetUserParticipatedEventsResponse( - UUID eventId, - Category category, - String title, - String createdDate, - int participantCount, - EventStatus eventStatus, - List mostPossibleTimes -) { - public static GetUserParticipatedEventsResponse of(Event event, EventParticipation eventParticipation, int participantCount, List mostPossibleTimes) { - return new GetUserParticipatedEventsResponse( - event.getEventId(), - event.getCategory(), - event.getTitle(), - String.valueOf(event.getCreatedDate()), - participantCount, - eventParticipation.getEventStatus(), - mostPossibleTimes - ); - } -} diff --git a/src/main/java/side/onetime/global/common/status/SuccessStatus.java b/src/main/java/side/onetime/global/common/status/SuccessStatus.java index 651bdfa..91957b8 100644 --- a/src/main/java/side/onetime/global/common/status/SuccessStatus.java +++ b/src/main/java/side/onetime/global/common/status/SuccessStatus.java @@ -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", "이벤트 수정에 성공했습니다."), diff --git a/src/main/java/side/onetime/service/EventService.java b/src/main/java/side/onetime/service/EventService.java index a057025..3acafd1 100644 --- a/src/main/java/side/onetime/service/EventService.java +++ b/src/main/java/side/onetime/service/EventService.java @@ -518,45 +518,6 @@ private boolean isDateFormat(String range) { return Character.isDigit(range.charAt(0)); } - /** - * 유저 참여 이벤트 반환 메서드. - * 인증된 유저가 참여한 모든 이벤트 목록을 조회하며, 각 이벤트에 대한 세부 정보를 반환합니다. - * - * @return 유저가 참여한 이벤트 목록 - */ - @Transactional(readOnly = true) - public List getUserParticipatedEvents() { - User user = userRepository.findById(UserAuthorizationUtil.getLoginUserId()) - .orElseThrow(() -> new CustomException(UserErrorStatus._NOT_FOUND_USER)); - - List participations = eventParticipationRepository.findAllByUserWithEvent(user); - - // 캐시 맵 선언 - Map participantsCache = new HashMap<>(); - Map> 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 mostPossibleTimes = mostPossibleCache.computeIfAbsent( - eventId, this::getMostPossibleTime); - - return GetUserParticipatedEventsResponse.of( - event, - ep, - participants.users().size() + participants.members().size(), - mostPossibleTimes - ); - }) - .collect(Collectors.toList()); - } - /** * 유저 참여 이벤트 목록 조회 메서드. * @@ -598,7 +559,6 @@ public GetParticipatedEventsResponse getParticipatedEventsByCursor(int size, Loc return GetParticipatedEventsResponse.of(userParticipatedEvents, pageCursorInfo); } - /** * 유저가 생성한 이벤트 삭제 메서드. * 인증된 유저가 생성한 특정 이벤트를 삭제합니다. diff --git a/src/test/java/side/onetime/event/EventControllerTest.java b/src/test/java/side/onetime/event/EventControllerTest.java index 62bdf49..d223317 100644 --- a/src/test/java/side/onetime/event/EventControllerTest.java +++ b/src/test/java/side/onetime/event/EventControllerTest.java @@ -382,73 +382,6 @@ public void getFilteredMostPossibleTimes() throws Exception { )); } - @Test - @DisplayName("유저 참여 이벤트 목록을 조회한다.") - public void getUserParticipatedEvents() throws Exception { - // given - List 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 { @@ -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)