Skip to content

Commit

Permalink
Merge branch 'backend-main' of https://github.com/woowacourse-teams/2…
Browse files Browse the repository at this point in the history
…023-emmsale into Feature/#562-피드_이미지_업로드
  • Loading branch information
hyeonjerry committed Sep 20, 2023
2 parents 953eaeb + d16dd49 commit a4abf90
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ void findAllFeedsTest() throws Exception {
fieldWithPath("feeds").type(JsonFieldType.ARRAY).description("피드 리스트"),
fieldWithPath("feeds[].id").type(JsonFieldType.NUMBER).description("피드 id"),
fieldWithPath("feeds[].title").type(JsonFieldType.STRING).description("피드 제목"),
fieldWithPath("feeds[].content").type(JsonFieldType.STRING).description("피드 내용"),
fieldWithPath("feeds[].writerId").type(JsonFieldType.NUMBER).description("피드 작성자 id"),
fieldWithPath("feeds[].commentsCount").type(JsonFieldType.NUMBER).description("피드의 댓글 개수"),
fieldWithPath("feeds[].createdAt").type(JsonFieldType.STRING).description("피드 작성 일시")
fieldWithPath("feeds[].updatedAt").type(JsonFieldType.STRING).description("피드 업데이트 일시")
);

final long eventId = 11L;
final List<FeedSimpleResponse> feeds = List.of(
new FeedSimpleResponse(34L, "피드1 제목", 23L, 0L,
new FeedSimpleResponse(34L, "피드1 제목", "피드 내용", 23L, 0L,
LocalDateTime.of(LocalDate.of(2023, 7, 13), LocalTime.of(11, 43, 11))),
new FeedSimpleResponse(35L, "피드2 제목", 43L, 3L,
new FeedSimpleResponse(35L, "피드2 제목", "피드 내용", 43L, 3L,
LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)))
);
final FeedListResponse response = new FeedListResponse(eventId, feeds);
Expand All @@ -78,15 +79,16 @@ void findDetailFeedTest() throws Exception {
fieldWithPath("writer.name").type(JsonFieldType.STRING).description("작성자명"),
fieldWithPath("writer.imageUrl").type(JsonFieldType.STRING).description("작성자 이미지 url"),
fieldWithPath("title").type(JsonFieldType.STRING).description("피드 제목"),
fieldWithPath("content").type(JsonFieldType.STRING).description("피드 내용")
fieldWithPath("content").type(JsonFieldType.STRING).description("피드 내용"),
fieldWithPath("updatedAt").type(JsonFieldType.STRING).description("피드 업데이트 일시")
);

final long eventId = 11L;
final long feedId = 34L;
final WriterProfileResponse writer = new WriterProfileResponse(8L, "작성자명",
"https://member-image.com");
final FeedDetailResponse response = new FeedDetailResponse(feedId, eventId, writer, "피드 제목",
"피드 상세 내용");
"피드 상세 내용", LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)));

when(feedQueryService.findFeed(any())).thenReturn(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public FeedListResponse findAllFeeds(final Long eventId) {

final List<FeedSimpleResponse> feedSimpleResponses = commentCountByFeed.entrySet().stream()
.map(FeedSimpleResponse::from)
.sorted(Comparator.comparing(FeedSimpleResponse::getCreatedAt).reversed())
.sorted(Comparator.comparing(FeedSimpleResponse::getUpdatedAt).reversed())
.collect(Collectors.toList());

return new FeedListResponse(eventId, feedSimpleResponses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

import com.emmsale.feed.domain.Feed;
import com.emmsale.member.domain.Member;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class FeedDetailResponse {

private static final String DATE_TIME_FORMAT = "yyyy:MM:dd:HH:mm:ss";

private final Long id;
private final Long eventId;
private final WriterProfileResponse writer;
private final String title;
private final String content;
@JsonFormat(pattern = DATE_TIME_FORMAT)
private final LocalDateTime updatedAt;

public static FeedDetailResponse from(final Feed feed) {
final WriterProfileResponse writerResponse = WriterProfileResponse.from(feed.getWriter());
Expand All @@ -23,7 +29,8 @@ public static FeedDetailResponse from(final Feed feed) {
feed.getEvent().getId(),
writerResponse,
feed.getTitle(),
feed.getContent()
feed.getContent(),
feed.getUpdatedAt()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
@RequiredArgsConstructor
public class FeedSimpleResponse {

public static final String DATE_TIME_FORMAT = "yyyy:MM:dd:HH:mm:ss";
private static final String DATE_TIME_FORMAT = "yyyy:MM:dd:HH:mm:ss";

private final Long id;
private final String title;
private final String content;
private final Long writerId;
@JsonFormat(pattern = DATE_TIME_FORMAT)
private final Long commentsCount;
private final LocalDateTime createdAt;
@JsonFormat(pattern = DATE_TIME_FORMAT)
private final LocalDateTime updatedAt;

public static FeedSimpleResponse from(final Entry<Feed, Long> entry) {
final Feed feed = entry.getKey();
Expand All @@ -27,9 +28,10 @@ public static FeedSimpleResponse from(final Entry<Feed, Long> entry) {
return new FeedSimpleResponse(
feed.getId(),
feed.getTitle(),
feed.getContent(),
feed.getWriter().getId(),
commentCount,
feed.getCreatedAt()
feed.getUpdatedAt()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void findAllFeedsTest() {
.map(FeedSimpleResponse::from)
.collect(Collectors.toList());
final FeedListResponse expect = new FeedListResponse(eventId, feedSimpleResponses);
expect.getFeeds().sort(Comparator.comparing(FeedSimpleResponse::getCreatedAt).reversed());
expect.getFeeds().sort(Comparator.comparing(FeedSimpleResponse::getUpdatedAt).reversed());

//when
final FeedListResponse actual = feedQueryService.findAllFeeds(eventId);
Expand Down

0 comments on commit a4abf90

Please sign in to comment.