Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public record PostCreateRequestDto(
@NotBlank (message = "내용은 필수입니다.")
String content,
String imageUrl,
String videoUrl,
List<String> tags
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public record PostUpdateRequestDto(
String title,
String content,
String imageUrl,
String videoUrl,
List<String> tags
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public record PostResponseDto(
String title,
String content,
String imageUrl,
String videoUrl,
List<String> tags,
Integer likeCount,
Integer commentCount,
Expand All @@ -32,6 +33,7 @@ public PostResponseDto(Post post) {
post.getTitle(),
post.getContent(),
post.getImageUrl(),
post.getVideoUrl(),
post.getPostTags().stream()
.map(postTag -> postTag.getTag().getName())
.toList(),
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/back/domain/post/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public class Post {
@Column(name = "image_url")
private String imageUrl;

// 게시글 동영상 URL
@Column(name = "video_url")
private String videoUrl;

@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PostTag> postTags = new ArrayList<>();

Expand Down Expand Up @@ -118,6 +122,10 @@ public void updateImage(String imageUrl) {
this.imageUrl = imageUrl;
}

public void updateVideo(String videoUrl) {
this.videoUrl = videoUrl;
}

public void addTag(Tag tag) {
PostTag postTag = PostTag.create(this, tag);
this.postTags.add(postTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public PostResponseDto createPost(PostCreateRequestDto reqBody) {
.title(reqBody.title())
.content(reqBody.content())
.imageUrl(reqBody.imageUrl())
.videoUrl(reqBody.videoUrl())
.build();

List<String> tagNames = reqBody.tags();
Expand Down Expand Up @@ -114,6 +115,9 @@ public PostResponseDto updatePost(Long postId, PostUpdateRequestDto reqBody) {
if (reqBody.imageUrl() != null && !reqBody.imageUrl().isBlank()) {
post.updateImage(reqBody.imageUrl());
}
if (reqBody.videoUrl() != null && !reqBody.videoUrl().isBlank()) {
post.updateVideo(reqBody.videoUrl());
}
if (reqBody.tags() != null) {
// 기존 태그들 삭제
post.clearTags();
Expand Down