Skip to content

Commit 10e12f3

Browse files
authored
[refactor] 내활동: 내가 좋아요한 게시글 목록 응답 DTO 필드 추가 #341 (#342)
* Revert "chore: initData용 이미지 추가" This reverts commit ef30eef. * . * chore: 수정사항 없음 * feat: MyHistoryPostItemDto에 상세 정보 필드 추가 및 매핑 로직 업데이트 * refactor: 게시글 좋아요 알림 메시지에 게시글 제목 추가 * chore: 수정사항 없음 * chore: 수정사항 없음 * refactor: MyHistoryLikedPostItemDto에 상세 필드 및 로직 개선 추가 * test: MyHistoryControllerTest 내 getMyLikedPosts 테스트 필드 검증 추가
1 parent 4c08b57 commit 10e12f3

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

src/main/java/com/back/domain/myhistory/dto/MyHistoryLikedPostItemDto.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,54 @@
33
import com.back.domain.post.post.entity.Post;
44
import com.back.domain.post.post.entity.PostImage;
55
import com.back.domain.post.post.entity.PostLike;
6-
import java.time.LocalDateTime;
7-
import java.util.List;
6+
import com.back.domain.post.post.enums.PostStatus;
87
import lombok.Builder;
98
import lombok.Getter;
109

10+
import java.time.LocalDateTime;
11+
import java.util.List;
12+
1113
@Getter
1214
@Builder
1315
public class MyHistoryLikedPostItemDto {
1416
private Long id;
17+
private Long postId;
18+
private String categoryName;
19+
private String userNickName;
1520
private String title;
21+
private String content;
1622
private List<String> imageUrls;
17-
private LocalDateTime likedAt;
23+
private LocalDateTime createdAt;
24+
private LocalDateTime updatedAt;
25+
private PostStatus status;
1826
private Integer likeCount;
1927
private Integer commentCount;
28+
private Integer viewCount;
29+
private LocalDateTime likedAt;
2030

2131
public static MyHistoryLikedPostItemDto from(PostLike pl) {
2232
Post p = pl.getPost();
33+
List<String> imageUrls = p.getImages() == null
34+
? List.of()
35+
: p.getImages().stream()
36+
.map(PostImage::getUrl)
37+
.toList();
38+
2339
return MyHistoryLikedPostItemDto.builder()
24-
.id(p.getId())
40+
.id(pl.getId())
41+
.postId(p.getId())
42+
.categoryName(p.getCategory() != null ? p.getCategory().getName() : null)
43+
.userNickName(p.getUser() != null ? p.getUser().getNickname() : null)
2544
.title(p.getTitle())
26-
.imageUrls(p.getImages().stream()
27-
.map(PostImage::getUrl)
28-
.toList())
29-
.likedAt(pl.getCreatedAt())
45+
.content(p.getContent())
46+
.imageUrls(imageUrls)
47+
.createdAt(p.getCreatedAt())
48+
.updatedAt(p.getUpdatedAt())
49+
.status(p.getStatus())
3050
.likeCount(p.getLikeCount())
3151
.commentCount(p.getCommentCount())
52+
.viewCount(p.getViewCount())
53+
.likedAt(pl.getCreatedAt())
3254
.build();
3355
}
3456
}

src/test/java/com/back/domain/myhistory/controller/MyHistoryControllerTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.back.domain.myhistory.controller;
22

33
import com.back.domain.myhistory.dto.*;
4+
import com.back.domain.post.post.enums.PostStatus;
45
import com.back.domain.myhistory.service.MyHistoryService;
56
import com.back.global.aspect.ResponseAspect;
67
import com.back.global.jwt.JwtUtil;
@@ -245,14 +246,24 @@ void getMyComments() throws Exception {
245246
void getMyLikedPosts() throws Exception {
246247
SecurityUser principal = createPrincipal(13L);
247248
LocalDateTime likedAt = LocalDateTime.of(2025, 3, 10, 21, 5, 0);
249+
LocalDateTime createdAt = likedAt.minusDays(2);
250+
LocalDateTime updatedAt = likedAt.minusDays(1);
248251

249252
MyHistoryLikedPostItemDto item = MyHistoryLikedPostItemDto.builder()
250253
.id(70L)
254+
.postId(501L)
255+
.categoryName("칵테일")
256+
.userNickName("하덕코딩")
251257
.title("봄 추천 칵테일")
258+
.content("상큼한 맛을 느껴보세요")
252259
.imageUrls(List.of("https://example.com/spring.png"))
253-
.likedAt(likedAt)
260+
.createdAt(createdAt)
261+
.updatedAt(updatedAt)
262+
.status(PostStatus.PUBLIC)
254263
.likeCount(88)
255264
.commentCount(12)
265+
.viewCount(345)
266+
.likedAt(likedAt)
256267
.build();
257268

258269
MyHistoryLikedPostListDto responseDto = new MyHistoryLikedPostListDto(
@@ -274,11 +285,18 @@ void getMyLikedPosts() throws Exception {
274285
.accept(MediaType.APPLICATION_JSON))
275286
.andExpect(status().isOk())
276287
.andExpect(jsonPath("$.data.items[0].id").value(70L))
288+
.andExpect(jsonPath("$.data.items[0].postId").value(501L))
289+
.andExpect(jsonPath("$.data.items[0].categoryName").value("칵테일"))
290+
.andExpect(jsonPath("$.data.items[0].userNickName").value("하덕코딩"))
277291
.andExpect(jsonPath("$.data.items[0].title").value("봄 추천 칵테일"))
292+
.andExpect(jsonPath("$.data.items[0].content").value("상큼한 맛을 느껴보세요"))
278293
.andExpect(jsonPath("$.data.items[0].imageUrls[0]").value("https://example.com/spring.png"))
279-
.andExpect(jsonPath("$.data.items[0].likedAt").value(ISO_WITH_SECONDS.format(likedAt)))
280-
.andExpect(jsonPath("$.data.items[0].likeCount").value(88))
294+
.andExpect(jsonPath("$.data.items[0].createdAt").value(ISO_WITH_SECONDS.format(createdAt)))
295+
.andExpect(jsonPath("$.data.items[0].updatedAt").value(ISO_WITH_SECONDS.format(updatedAt)))
296+
.andExpect(jsonPath("$.data.items[0].status").value(PostStatus.PUBLIC.name()))
281297
.andExpect(jsonPath("$.data.items[0].commentCount").value(12))
298+
.andExpect(jsonPath("$.data.items[0].viewCount").value(345))
299+
.andExpect(jsonPath("$.data.items[0].likedAt").value(ISO_WITH_SECONDS.format(likedAt)))
282300
.andExpect(jsonPath("$.data.hasNext").value(true))
283301
.andExpect(jsonPath("$.data.nextId").value(55L));
284302

0 commit comments

Comments
 (0)