Skip to content

Commit c36104a

Browse files
committed
Feat: Post thumbnailUrl 필드 추가
1 parent 343b423 commit c36104a

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

src/main/java/com/back/domain/board/post/dto/PostListResponse.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ public class PostListResponse {
1616
private final Long postId;
1717
private final AuthorResponse author;
1818
private final String title;
19+
private final String thumbnailUrl;
20+
21+
@Setter
22+
private List<CategoryResponse> categories;
23+
1924
private final long likeCount;
2025
private final long bookmarkCount;
2126
private final long commentCount;
2227
private final LocalDateTime createdAt;
2328
private final LocalDateTime updatedAt;
2429

25-
@Setter
26-
private List<CategoryResponse> categories;
27-
2830
@QueryProjection
2931
public PostListResponse(Long postId,
3032
AuthorResponse author,
3133
String title,
34+
String thumbnailUrl,
3235
List<CategoryResponse> categories,
3336
long likeCount,
3437
long bookmarkCount,
@@ -38,6 +41,7 @@ public PostListResponse(Long postId,
3841
this.postId = postId;
3942
this.author = author;
4043
this.title = title;
44+
this.thumbnailUrl = thumbnailUrl;
4145
this.categories = categories;
4246
this.likeCount = likeCount;
4347
this.bookmarkCount = bookmarkCount;

src/main/java/com/back/domain/board/post/dto/PostRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
*
1010
* @param title 게시글 제목
1111
* @param content 게시글 내용
12+
* @param thumbnailUrl 썸네일 URL
1213
* @param categoryIds 카테고리 ID 리스트
1314
*/
1415
public record PostRequest(
1516
@NotBlank String title,
1617
@NotBlank String content,
18+
String thumbnailUrl,
1719
List<Long> categoryIds
1820
) {}

src/main/java/com/back/domain/board/post/entity/Post.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import java.util.ArrayList;
1111
import java.util.List;
12+
import java.util.regex.Matcher;
13+
import java.util.regex.Pattern;
1214

1315
@Entity
1416
@Getter
@@ -22,6 +24,9 @@ public class Post extends BaseEntity {
2224

2325
private String content;
2426

27+
@Column(length = 500)
28+
private String thumbnailUrl;
29+
2530
// TODO: 추후 PostRepositoryImpl#searchPosts 로직 개선 필요, ERD에도 반영할 것
2631
@Column(nullable = false)
2732
private Long likeCount = 0L;
@@ -49,6 +54,14 @@ public Post(User user, String title, String content) {
4954
this.user = user;
5055
this.title = title;
5156
this.content = content;
57+
this.thumbnailUrl = null;
58+
}
59+
60+
public Post(User user, String title, String content, String thumbnailUrl) {
61+
this.user = user;
62+
this.title = title;
63+
this.content = content;
64+
this.thumbnailUrl = thumbnailUrl;
5265
}
5366

5467
// -------------------- 비즈니스 메서드 --------------------

src/main/java/com/back/domain/board/post/repository/PostRepositoryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private List<PostListResponse> fetchPosts(BooleanBuilder where, List<OrderSpecif
162162
post.id,
163163
new QAuthorResponse(user.id, profile.nickname, profile.profileImageUrl), // 작성자 정보 (N+1 방지 join)
164164
post.title,
165+
post.thumbnailUrl,
165166
Expressions.constant(Collections.emptyList()), // categories는 별도 주입
166167
likeCount,
167168
bookmarkCount,

src/main/java/com/back/domain/board/post/service/PostService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public PostResponse createPost(PostRequest request, Long userId) {
4747
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
4848

4949
// Post 생성
50-
Post post = new Post(user, request.title(), request.content());
50+
Post post = new Post(user, request.title(), request.content(), request.thumbnailUrl());
5151

5252
// Category 매핑
5353
if (request.categoryIds() != null) {

0 commit comments

Comments
 (0)