Skip to content

Commit

Permalink
Merge branch 'Feature/#650-행사_상태_리팩터링' of https://github.com/woowacou…
Browse files Browse the repository at this point in the history
…rse-teams/2023-emmsale into Feature/#664-행사_다단건_조회_시_S3의_이미지를_반환하도록_수정
  • Loading branch information
amaran-th committed Sep 27, 2023
2 parents 6920902 + 8ba3577 commit 67616b9
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,46 +131,60 @@ void findEvents() throws Exception {
);

final ResponseFieldsSnippet responseFields = PayloadDocumentation.responseFields(
fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("행사 id"),
fieldWithPath("[].name").type(JsonFieldType.STRING).description("행사명"),
fieldWithPath("[].startDate").type(JsonFieldType.STRING)
PayloadDocumentation.fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("행사 id"),
PayloadDocumentation.fieldWithPath("[].name").type(JsonFieldType.STRING).description("행사명"),
PayloadDocumentation.fieldWithPath("[].eventStartDate").type(JsonFieldType.STRING)
.description("행사 시작일(yyyy:MM:dd:HH:mm:ss)"),
fieldWithPath("[].endDate").type(JsonFieldType.STRING)
PayloadDocumentation.fieldWithPath("[].eventEndDate").type(JsonFieldType.STRING)
.description("행사 마감일(yyyy:MM:dd:HH:mm:ss)"),
fieldWithPath("[].tags[]").type(JsonFieldType.ARRAY)
PayloadDocumentation.fieldWithPath("[].applyStartDate").type(JsonFieldType.STRING)
.description("행사 시작일(yyyy:MM:dd:HH:mm:ss)"),
PayloadDocumentation.fieldWithPath("[].applyEndDate").type(JsonFieldType.STRING)
.description("행사 마감일(yyyy:MM:dd:HH:mm:ss)"),
PayloadDocumentation.fieldWithPath("[].tags[]").type(JsonFieldType.ARRAY)
.description("행사 태그 목록"),
fieldWithPath("[].status").type(JsonFieldType.STRING)
.description("행사 진행 상황(IN_PROGRESS, UPCOMING, ENDED)"),
fieldWithPath("[].applyStatus").type(JsonFieldType.STRING)
.description("행사 신청 기간의 진행 상황(IN_PROGRESS, UPCOMING, ENDED)"),
fieldWithPath("[].remainingDays").type(JsonFieldType.NUMBER)
.description("행사 시작일까지 남은 일 수"),
fieldWithPath("[].applyRemainingDays").type(JsonFieldType.NUMBER)
.description("행사 신청 시작일까지 남은 일 수"),
fieldWithPath("[].imageUrl").type(JsonFieldType.STRING)
PayloadDocumentation.fieldWithPath("[].imageUrl").type(JsonFieldType.STRING)
.description("행사 이미지 URL"),
fieldWithPath("[].eventMode").type(JsonFieldType.STRING)
PayloadDocumentation.fieldWithPath("[].eventMode").type(JsonFieldType.STRING)
.description("행사 온라인 여부(온라인, 오프라인, 온오프라인)"),
fieldWithPath("[].paymentType").type(JsonFieldType.STRING)
PayloadDocumentation.fieldWithPath("[].paymentType").type(JsonFieldType.STRING)
.description("행사 유료 여부(유료, 무료, 유무료)")
);

final List<EventResponse> eventResponses = List.of(
new EventResponse(1L, "인프콘 2023", LocalDateTime.parse("2023-06-03T12:00:00"),
new EventResponse(
1L,
"인프콘 2023",
LocalDateTime.parse("2023-06-03T12:00:00"),
LocalDateTime.parse("2023-09-03T12:00:00"),
List.of("백엔드", "프론트엔드", "안드로이드", "IOS", "AI"), "IN_PROGRESS", "ENDED",
LocalDateTime.parse("2023-09-01T00:00:00"),
LocalDateTime.parse("2023-09-02T23:59:59"),
List.of("백엔드", "프론트엔드", "안드로이드", "IOS", "AI"),
"https://biz.pusan.ac.kr/dext5editordata/2022/08/20220810_160546511_10103.jpg",
3, -30, EventMode.ONLINE.getValue(), PaymentType.PAID.getValue()),
new EventResponse(5L, "웹 컨퍼런스", LocalDateTime.parse("2023-07-03T12:00:00"),
LocalDateTime.parse("2023-08-03T12:00:00"), List.of("백엔드", "프론트엔드"),
"IN_PROGRESS", "IN_PROGRESS",
EventMode.ONLINE.getValue(),
PaymentType.PAID.getValue()
),
new EventResponse(
5L,
"웹 컨퍼런스",
LocalDateTime.parse("2023-07-03T12:00:00"),
LocalDateTime.parse("2023-08-03T12:00:00"),
LocalDateTime.parse("2023-06-23T10:00:00"),
LocalDateTime.parse("2023-07-03T12:00:00"),
List.of("백엔드", "프론트엔드"),
"https://biz.pusan.ac.kr/dext5editordata/2022/08/20220810_160546511_10103.jpg",
3, 3, EventMode.ONLINE.getValue(), PaymentType.PAID.getValue()),
new EventResponse(2L, "AI 컨퍼런스", LocalDateTime.parse("2023-07-22T12:00:00"),
LocalDateTime.parse("2023-07-30T12:00:00"), List.of("AI"), "UPCOMING",
"IN_PROGRESS",
EventMode.ONLINE.getValue(),
PaymentType.PAID.getValue()),
new EventResponse(2L,
"AI 컨퍼런스",
LocalDateTime.parse("2023-07-22T12:00:00"),
LocalDateTime.parse("2023-07-30T12:00:00"),
LocalDateTime.parse("2023-07-01T00:00:00"),
LocalDateTime.parse("2023-07-21T23:59:59"),
List.of("AI"),
"https://biz.pusan.ac.kr/dext5editordata/2022/08/20220810_160546511_10103.jpg",
3, -18, EventMode.ONLINE.getValue(), PaymentType.PAID.getValue())
EventMode.ONLINE.getValue(),
PaymentType.PAID.getValue())
);

Mockito.when(eventService.findEvents(any(EventType.class),
Expand Down Expand Up @@ -230,7 +244,7 @@ void updateEventTest() throws Exception {
Mockito.when(eventService.updateEvent(eq(eventId), any(EventDetailRequest.class), any(), any()))
.thenReturn(response);

String contents = objectMapper.writeValueAsString(request);
final String contents = objectMapper.writeValueAsString(request);

final RequestPartsSnippet requestPartsSnippet = requestParts(
partWithName("images").description("이미지들").optional(),
Expand All @@ -253,7 +267,8 @@ void updateEventTest() throws Exception {
);

//when
MockMultipartHttpServletRequestBuilder builder = multipart(HttpMethod.PUT, "/events/" + eventId)
final MockMultipartHttpServletRequestBuilder builder = multipart(HttpMethod.PUT,
"/events/" + eventId)
.file("images", image1.getBytes())
.file("images", image2.getBytes())
.file(new MockMultipartFile("request", "", "application/json", contents.getBytes(
Expand Down Expand Up @@ -331,7 +346,7 @@ void addEventTest() throws Exception {
Mockito.when(eventService.addEvent(any(EventDetailRequest.class), any(), any()))
.thenReturn(response);

String contents = objectMapper.writeValueAsString(request);
final String contents = objectMapper.writeValueAsString(request);

final RequestPartsSnippet requestPartsSnippet = requestParts(
partWithName("images").description("이미지들").optional(),
Expand All @@ -354,7 +369,7 @@ void addEventTest() throws Exception {
);

//when
MockMultipartHttpServletRequestBuilder builder = multipart("/events")
final MockMultipartHttpServletRequestBuilder builder = multipart("/events")
.file("images", image1.getBytes())
.file("images", image2.getBytes())
.file(new MockMultipartFile("request", "", "application/json", contents.getBytes(
Expand Down Expand Up @@ -399,7 +414,7 @@ void addEventWithEmptyNameTest(final String eventName) throws Exception {
event.getEventPeriod().getApplyStartDate(), event.getEventPeriod().getApplyEndDate(),
tags, event.getImageUrl(), event.getType(), event.getEventMode(),
event.getPaymentType(), event.getOrganization());
String contents = objectMapper.writeValueAsString(request);
final String contents = objectMapper.writeValueAsString(request);
//when & then
mockMvc.perform(multipart("/events")
.file("images", image1.getBytes())
Expand Down Expand Up @@ -440,7 +455,7 @@ void addEventWithEmptyLocationTest(final String eventLocation) throws Exception
event.getEventPeriod().getApplyStartDate(), event.getEventPeriod().getApplyEndDate(),
tags, event.getImageUrl(), event.getType(), event.getEventMode(),
event.getPaymentType(), event.getOrganization());
String contents = objectMapper.writeValueAsString(request);
final String contents = objectMapper.writeValueAsString(request);
//when & then
mockMvc.perform(multipart("/events")
.file("images", image1.getBytes())
Expand Down Expand Up @@ -482,7 +497,7 @@ void addEventWithInvalidInformationUrlTest(final String informationUrl) throws E
event.getEventPeriod().getApplyStartDate(), event.getEventPeriod().getApplyEndDate(),
tags, event.getImageUrl(), event.getType(), event.getEventMode(),
event.getPaymentType(), event.getOrganization());
String contents = objectMapper.writeValueAsString(request);
final String contents = objectMapper.writeValueAsString(request);
//when & then
mockMvc.perform(multipart("/events")
.file("images", image1.getBytes())
Expand Down Expand Up @@ -517,7 +532,7 @@ void addEventWithUnformattedStartDateTimeTest(final String startDateTime)

final Event event = EventFixture.인프콘_2023();

Map<String, String> request = new HashMap<>();
final Map<String, String> request = new HashMap<>();
request.put("name", event.getName());
request.put("location", event.getLocation());
request.put("informationUrl", event.getInformationUrl());
Expand All @@ -531,7 +546,7 @@ void addEventWithUnformattedStartDateTimeTest(final String startDateTime)
request.put("paymentType", event.getPaymentType().name());
request.put("organization", event.getOrganization());

String contents = objectMapper.writeValueAsString(request);
final String contents = objectMapper.writeValueAsString(request);
//when & then
mockMvc.perform(multipart("/events")
.file("images", image1.getBytes())
Expand Down Expand Up @@ -565,7 +580,7 @@ void addEventWithUnformattedEndDateTimeTest(final String endDateTime) throws Exc

final Event event = EventFixture.인프콘_2023();

Map<String, String> request = new HashMap<>();
final Map<String, String> request = new HashMap<>();
request.put("name", event.getName());
request.put("location", event.getLocation());
request.put("informationUrl", event.getInformationUrl());
Expand All @@ -579,7 +594,7 @@ void addEventWithUnformattedEndDateTimeTest(final String endDateTime) throws Exc
request.put("paymentType", event.getPaymentType().name());
request.put("organization", event.getOrganization());

String contents = objectMapper.writeValueAsString(request);
final String contents = objectMapper.writeValueAsString(request);
//when & then
mockMvc.perform(multipart("/events")
.file("images", image1.getBytes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,54 @@ class ScrapApiTest extends MockMvcTestHelper {
void findAllScraps() throws Exception {
//given
final List<EventResponse> expectedScrapResponse = List.of(
new EventResponse(1L, "인프콘 2023", LocalDateTime.parse("2023-06-03T12:00:00"),
new EventResponse(
1L,
"인프콘 2023",
LocalDateTime.parse("2023-06-03T12:00:00"),
LocalDateTime.parse("2023-09-03T12:00:00"),
List.of("백엔드", "프론트엔드", "안드로이드", "IOS", "AI"), "IN_PROGRESS", "ENDED",
LocalDateTime.parse("2023-09-01T00:00:00"),
LocalDateTime.parse("2023-09-02T23:59:59"),
List.of("백엔드", "프론트엔드", "안드로이드", "IOS", "AI"),
"https://biz.pusan.ac.kr/dext5editordata/2022/08/20220810_160546511_10103.jpg",
3, -30, EventMode.ONLINE.getValue(), PaymentType.PAID.getValue()),
new EventResponse(5L, "웹 컨퍼런스", LocalDateTime.parse("2023-07-03T12:00:00"),
LocalDateTime.parse("2023-08-03T12:00:00"), List.of("백엔드", "프론트엔드"),
"IN_PROGRESS", "IN_PROGRESS",
EventMode.ONLINE.getValue(),
PaymentType.PAID.getValue()
),
new EventResponse(
5L,
"웹 컨퍼런스",
LocalDateTime.parse("2023-07-03T12:00:00"),
LocalDateTime.parse("2023-08-03T12:00:00"),
LocalDateTime.parse("2023-06-23T10:00:00"),
LocalDateTime.parse("2023-07-03T12:00:00"),
List.of("백엔드", "프론트엔드"),
"https://biz.pusan.ac.kr/dext5editordata/2022/08/20220810_160546511_10103.jpg",
3, 3, EventMode.ONLINE.getValue(), PaymentType.PAID.getValue()),
new EventResponse(2L, "AI 컨퍼런스", LocalDateTime.parse("2023-07-22T12:00:00"),
LocalDateTime.parse("2023-07-30T12:00:00"), List.of("AI"), "UPCOMING",
"IN_PROGRESS",
EventMode.ONLINE.getValue(),
PaymentType.PAID.getValue()),
new EventResponse(2L,
"AI 컨퍼런스",
LocalDateTime.parse("2023-07-22T12:00:00"),
LocalDateTime.parse("2023-07-30T12:00:00"),
LocalDateTime.parse("2023-07-01T00:00:00"),
LocalDateTime.parse("2023-07-21T23:59:59"),
List.of("AI"),
"https://biz.pusan.ac.kr/dext5editordata/2022/08/20220810_160546511_10103.jpg",
3, -18, EventMode.ONLINE.getValue(), PaymentType.PAID.getValue())
EventMode.ONLINE.getValue(),
PaymentType.PAID.getValue())
);

final ResponseFieldsSnippet responseFields = PayloadDocumentation.responseFields(
PayloadDocumentation.fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("행사 id"),
PayloadDocumentation.fieldWithPath("[].name").type(JsonFieldType.STRING).description("행사명"),
PayloadDocumentation.fieldWithPath("[].startDate").type(JsonFieldType.STRING)
PayloadDocumentation.fieldWithPath("[].eventStartDate").type(JsonFieldType.STRING)
.description("행사 시작일(yyyy:MM:dd:HH:mm:ss)"),
PayloadDocumentation.fieldWithPath("[].endDate").type(JsonFieldType.STRING)
PayloadDocumentation.fieldWithPath("[].eventEndDate").type(JsonFieldType.STRING)
.description("행사 마감일(yyyy:MM:dd:HH:mm:ss)"),
PayloadDocumentation.fieldWithPath("[].applyStartDate").type(JsonFieldType.STRING)
.description("행사 시작일(yyyy:MM:dd:HH:mm:ss)"),
PayloadDocumentation.fieldWithPath("[].applyEndDate").type(JsonFieldType.STRING)
.description("행사 마감일(yyyy:MM:dd:HH:mm:ss)"),
PayloadDocumentation.fieldWithPath("[].tags[]").type(JsonFieldType.ARRAY)
.description("행사 태그 목록"),
PayloadDocumentation.fieldWithPath("[].status").type(JsonFieldType.STRING)
.description("행사 진행 상황(IN_PROGRESS, UPCOMING, ENDED)"),
PayloadDocumentation.fieldWithPath("[].applyStatus").type(JsonFieldType.STRING)
.description("행사 신청 기간의 진행 상황(IN_PROGRESS, UPCOMING, ENDED)"),
PayloadDocumentation.fieldWithPath("[].remainingDays").type(JsonFieldType.NUMBER)
.description("행사 시작일까지 남은 일 수"),
PayloadDocumentation.fieldWithPath("[].applyRemainingDays").type(JsonFieldType.NUMBER)
.description("행사 신청 시작일까지 남은 일 수"),
PayloadDocumentation.fieldWithPath("[].imageUrl").type(JsonFieldType.STRING)
.description("행사 이미지 URL"),
PayloadDocumentation.fieldWithPath("[].eventMode").type(JsonFieldType.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public List<EventResponse> findEvents(final EventType category,
final EnumMap<EventStatus, List<Event>> eventsForEventStatus
= groupByEventStatus(nowDate, events);

return filterByStatuses(nowDate, statuses, eventsForEventStatus);
return filterByStatuses(statuses, eventsForEventStatus);
}

private boolean isExistTagNames(final List<String> tagNames) {
Expand All @@ -131,7 +131,7 @@ private LocalDateTime validateStartDate(final String date) {
return LocalDate.parse(MIN_DATE).atStartOfDay();
}
return LocalDate.parse(date).atStartOfDay();
} catch (DateTimeParseException exception) {
} catch (final DateTimeParseException exception) {
throw new EventException(EventExceptionType.INVALID_DATE_FORMAT);
}
}
Expand All @@ -142,7 +142,7 @@ private LocalDateTime validateEndDate(final String date) {
return LocalDate.parse(MAX_DATE).atTime(23, 59, 59);
}
return LocalDate.parse(date).atTime(23, 59, 59);
} catch (DateTimeParseException exception) {
} catch (final DateTimeParseException exception) {
throw new EventException(EventExceptionType.INVALID_DATE_FORMAT);
}
}
Expand All @@ -165,30 +165,27 @@ private EnumMap<EventStatus, List<Event>> groupByEventStatus(final LocalDate now
}

private List<EventResponse> filterByStatuses(
final LocalDate today,
final List<EventStatus> statuses,
final EnumMap<EventStatus, List<Event>> eventsForEventStatus
) {
if (isExistStatusName(statuses)) {
return filterEventResponseByStatuses(today, statuses, eventsForEventStatus);
return filterEventResponseByStatuses(statuses, eventsForEventStatus);
}
return EventResponse.mergeEventResponses(today, eventsForEventStatus);
return EventResponse.mergeEventResponses(eventsForEventStatus);
}

private boolean isExistStatusName(final List<EventStatus> statuses) {
return statuses != null;
}

private List<EventResponse> filterEventResponseByStatuses(
final LocalDate today,
final List<EventStatus> statuses,
final EnumMap<EventStatus, List<Event>> eventsForEventStatus
) {
return eventsForEventStatus.entrySet()
.stream()
.filter(entry -> statuses.contains(entry.getKey()))
.map(entry -> EventResponse.makeEventResponsesByStatus(today, entry.getKey(),
entry.getValue()))
.map(entry -> EventResponse.makeEventResponsesByStatus(entry.getValue()))
.reduce(new ArrayList<>(), (combinedEvents, eventsToAdd) -> {
combinedEvents.addAll(eventsToAdd);
return combinedEvents;
Expand Down
Loading

0 comments on commit 67616b9

Please sign in to comment.