Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/#803 행사 및 함께해요 관련 api 명세 수정 #808

Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public EventResponse addEvent(final EventDetailRequest request,
.saveImages(ImageType.EVENT, event.getId(), images));

eventPublisher.publish(event);
final String thumbnailImageUrl = savedImages.extractThumbnailImage();
final List<String> informationImageUrls = savedImages.extractInformationImages();
return EventResponse.from(event, thumbnailImageUrl, informationImageUrls);
return EventResponse.from(event, savedImages);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드리뷰 해줬던 부분을 반영하고, 하나의 커밋으로 합쳐서 커밋했네.
앞으로는 쪼개서 커밋해보도록 하자

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵...!👀

}

public EventResponse updateEvent(final Long eventId, final EventDetailRequest request,
Expand Down Expand Up @@ -76,9 +74,7 @@ public EventResponse updateEvent(final Long eventId, final EventDetailRequest re
imageCommandService.deleteImages(ImageType.EVENT, eventId);
final AllImagesOfContent savedImages = new AllImagesOfContent(imageCommandService
.saveImages(ImageType.EVENT, event.getId(), images));
final String thumbnailImageUrl = savedImages.extractThumbnailImage();
final List<String> informationImageUrls = savedImages.extractInformationImages();
return EventResponse.from(updatedEvent, thumbnailImageUrl, informationImageUrls);
return EventResponse.from(updatedEvent, savedImages);
}

public void deleteEvent(final Long eventId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public EventResponse findEvent(final Long id, final LocalDate today) {
.stream()
.sorted(comparing(Image::getOrder))
.collect(toList()));
final String thumbnailImageUrl = images.extractThumbnailImage();
final List<String> informationImageUrls = images.extractInformationImages();
return EventResponse.from(event, thumbnailImageUrl, informationImageUrls);
return EventResponse.from(event, images);
}

public List<EventResponse> findEvents(final EventType category,
Expand Down Expand Up @@ -215,7 +213,7 @@ private List<EventResponse> filterEventResponseByStatuses(
private Map<Long, AllImagesOfContent> makeImagesPerEventId(final List<Event> events) {
final List<Long> eventIds = events.stream()
.map(Event::getId)
.collect(Collectors.toList());
.collect(Collectors.toUnmodifiableList());

Map<Long, AllImagesOfContent> imagesPerEventId = new HashMap<>();
for (Long eventId : eventIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public List<RecruitmentPostQueryResponse> findRecruitmentPostsByMemberId(

return posts.stream()
.map(RecruitmentPostQueryResponse::from)
.collect(Collectors.toList());
.collect(Collectors.toUnmodifiableList());
}

private void validateOwner(final Member member, final Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public class EventResponse {

public static EventResponse from(
final Event event,
final String thumbnailUrl,
final List<String> imageUrls
final AllImagesOfContent images
) {
final List<String> tagNames = event.getTags().stream()
.map(EventTag::getTag)
Expand All @@ -62,9 +61,9 @@ public static EventResponse from(
event.getEventPeriod().getApplyEndDate(),
event.getLocation(),
tagNames,
thumbnailUrl,
images.extractThumbnailImage(),
event.getType().toString(),
imageUrls,
images.extractInformationImages(),
event.getOrganization(),
event.getPaymentType().getValue(),
event.getEventMode().getValue()
Expand All @@ -74,13 +73,14 @@ public static EventResponse from(
public static List<EventResponse> makeEventResponsesByStatus(final List<Event> events,
final Map<Long, AllImagesOfContent> imagesPerEventId) {
return events.stream()
.map(event -> {
final AllImagesOfContent allImageUrls = imagesPerEventId.get(event.getId());
final String thumbnailImageUrl = allImageUrls.extractThumbnailImage();
final List<String> informationImageUrls = allImageUrls.extractInformationImages();
return EventResponse.from(event, thumbnailImageUrl, informationImageUrls);
})
.collect(Collectors.toList());
.map(event -> toEventResponse(imagesPerEventId, event))
.collect(Collectors.toUnmodifiableList());
}

private static EventResponse toEventResponse(
final Map<Long, AllImagesOfContent> imagesPerEventId, final Event event) {
final AllImagesOfContent allImageUrls = imagesPerEventId.get(event.getId());
return EventResponse.from(event, allImageUrls);
}

public static List<EventResponse> mergeEventResponses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public RecruitmentPost createRecruitmentPost(final Member member, final String c
public void addAllEventTags(final List<Tag> tags) {
final List<EventTag> eventTags = tags.stream()
.map(tag -> new EventTag(this, tag))
.collect(Collectors.toList());
.collect(Collectors.toUnmodifiableList());
this.tags.addAll(eventTags);
}

Expand Down Expand Up @@ -150,6 +150,6 @@ public boolean isDiffer(final Long eventId) {
public List<String> extractTags() {
return tags.stream()
.map(tag -> tag.getTag().getName())
.collect(Collectors.toList());
.collect(Collectors.toUnmodifiableList());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.emmsale.image.domain;

import static com.emmsale.image.exception.ImageExceptionType.NOT_FOUND_THUMBNAIL;
import static java.util.Comparator.comparing;

import com.emmsale.image.exception.ImageException;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
Expand All @@ -20,7 +22,7 @@ public String extractThumbnailImage() {
return images.stream()
.filter(Image::isThumbnail)
.findFirst()
.orElseThrow()
.orElseThrow(() -> new ImageException(NOT_FOUND_THUMBNAIL))
.getName();
}

Expand All @@ -29,6 +31,6 @@ public List<String> extractInformationImages() {
.sorted(comparing(Image::getOrder))
.filter(Image::isNotThumbnail)
.map(Image::getName)
.collect(Collectors.toList());
.collect(Collectors.toUnmodifiableList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import org.springframework.http.HttpStatus;

public enum ImageExceptionType implements BaseExceptionType {


NOT_FOUND_THUMBNAIL(
HttpStatus.NOT_FOUND,
"주어진 이미지들 중 섬네일 이미지가 존재하지 않습니다."
),
INVALID_FILE_FORMAT(
HttpStatus.BAD_REQUEST,
"잘못된 형식의 파일입니다."
Expand All @@ -29,20 +33,20 @@ public enum ImageExceptionType implements BaseExceptionType {
HttpStatus.INTERNAL_SERVER_ERROR,
"이미지를 DB서 삭제하지 못했습니다."
);

private final HttpStatus httpStatus;
private final String errorMessage;

ImageExceptionType(final HttpStatus httpStatus, final String errorMessage) {
this.httpStatus = httpStatus;
this.errorMessage = errorMessage;
}

@Override
public HttpStatus httpStatus() {
return httpStatus;
}

@Override
public String errorMessage() {
return errorMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public List<EventResponse> findAllScraps(final Member member) {
final List<Event> scrappedEvents = scrapRepository.findAllByMemberId(member.getId())
.stream()
.map(Scrap::getEvent)
.collect(Collectors.toList());
.collect(Collectors.toUnmodifiableList());

final Map<EventStatus, List<Event>> eventGroupByStatus = scrappedEvents.stream()
.collect(
Expand All @@ -46,9 +46,9 @@ public List<EventResponse> findAllScraps(final Member member) {
private Map<Long, AllImagesOfContent> makeImageUrlsPerEventId(final List<Event> events) {
final List<Long> eventIds = events.stream()
.map(Event::getId)
.collect(Collectors.toList());
.collect(Collectors.toUnmodifiableList());

Map<Long, AllImagesOfContent> imageUrlsPerEventId = new HashMap<>();
final Map<Long, AllImagesOfContent> imageUrlsPerEventId = new HashMap<>();
for (Long eventId : eventIds) {
final AllImagesOfContent images = new AllImagesOfContent(
imageRepository.findAllByTypeAndContentId(ImageType.EVENT, eventId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.emmsale.event.domain.repository.EventTagRepository;
import com.emmsale.event.exception.EventException;
import com.emmsale.helper.ServiceIntegrationTestHelper;
import com.emmsale.image.domain.AllImagesOfContent;
import com.emmsale.image.domain.Image;
import com.emmsale.image.domain.ImageType;
import com.emmsale.image.domain.repository.ImageRepository;
Expand Down Expand Up @@ -143,21 +144,21 @@ class findEventTest {
void success() {
//given
final Event event = eventRepository.save(eventFixture());
imageRepository.save(
new Image("imageUrl1", ImageType.EVENT, event.getId(), 1, LocalDateTime.now())
final String thumbnailUrl = "imageUrl2";
final String imageUrl1 = "imageUrl1";
final String imageUrl2 = "imageUrl3";
final Image image1 = imageRepository.save(
new Image(imageUrl1, ImageType.EVENT, event.getId(), 1, LocalDateTime.now())
);
imageRepository.save(
new Image("imageUrl2", ImageType.EVENT, event.getId(), 0, LocalDateTime.now())
final Image image2 = imageRepository.save(
new Image(thumbnailUrl, ImageType.EVENT, event.getId(), 0, LocalDateTime.now())
);
imageRepository.save(
new Image("imageUrl3", ImageType.EVENT, event.getId(), 2, LocalDateTime.now())
final Image image3 = imageRepository.save(
new Image(imageUrl2, ImageType.EVENT, event.getId(), 2, LocalDateTime.now())
);

final String thumbnailUrl = "imageUrl2";
final List<String> imageUrls = List.of("imageUrl1", "imageUrl3");

final EventResponse expected = EventResponse.from(event, thumbnailUrl,
imageUrls);
final EventResponse expected = EventResponse.from(event,
new AllImagesOfContent(List.of(image2, image1, image3)));

//when
final EventResponse actual = eventQueryService.findEvent(event.getId(), 날짜_8월_10일());
Expand All @@ -174,8 +175,8 @@ void success_imageUrl_null_imageUrls_empty() {
//given
final Event event = eventRepository.save(eventFixture());

final EventResponse expected = EventResponse.from(event, null,
Collections.emptyList());
final EventResponse expected = EventResponse.from(event,
new AllImagesOfContent(Collections.emptyList()));

//when
final EventResponse actual = eventQueryService.findEvent(event.getId(), 날짜_8월_10일());
Expand All @@ -191,13 +192,12 @@ void success_imageUrl_null_imageUrls_empty() {
void success_imageUrls_empty() {
//given
final Event event = eventRepository.save(eventFixture());
imageRepository.save(
final Image image = imageRepository.save(
new Image("imageUrl2", ImageType.EVENT, event.getId(), 0, LocalDateTime.now())
);

final String thumbnailUrl = "imageUrl2";
final EventResponse expected = EventResponse.from(event, thumbnailUrl,
Collections.emptyList());
final EventResponse expected = EventResponse.from(event,
new AllImagesOfContent(List.of(image)));

//when
final EventResponse actual = eventQueryService.findEvent(event.getId(), 날짜_8월_10일());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.emmsale.event.domain.Event;
import com.emmsale.event.domain.EventMode;
import com.emmsale.event.domain.PaymentType;
import com.emmsale.image.domain.AllImagesOfContent;
import com.emmsale.image.domain.Image;
import com.emmsale.image.domain.ImageType;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -19,7 +22,16 @@ void createEventDetailResponseTest() {
//given
final Event 구름톤 = EventFixture.구름톤();
final String thumbnailUrl = "thumbnail";
final List<String> imageUrls = List.of("imageUrl1", "imageUrl2");
final String imageUrl1 = "imageUrl1";
final String imageUrl2 = "imageUrl2";
final List<String> imageUrls = List.of(imageUrl1, imageUrl2);
final AllImagesOfContent images = new AllImagesOfContent(
List.of(
new Image(thumbnailUrl, ImageType.EVENT, 구름톤.getId(), 0, null),
new Image(imageUrl1, ImageType.EVENT, 구름톤.getId(), 1, null),
new Image(imageUrl2, ImageType.EVENT, 구름톤.getId(), 2, null)
)
);

final EventResponse expected = new EventResponse(
구름톤.getId(),
Expand All @@ -40,7 +52,7 @@ void createEventDetailResponseTest() {
);

//when
final EventResponse actual = EventResponse.from(구름톤, thumbnailUrl, imageUrls);
final EventResponse actual = EventResponse.from(구름톤, images);

//then
assertThat(actual)
Expand Down
Loading