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

feat: 임시 글 발행 시 포스트 이미지, 인트로 받지 않도록 변경 #213

Merged
merged 1 commit into from
Jan 13, 2024
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
3 changes: 1 addition & 2 deletions src/main/java/com/mallang/post/application/DraftService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void update(UpdateDraftCommand command) {
draft.validateWriter(member);
draft.update(
command.title(),
command.intro(), command.bodyText(),
command.postThumbnailImageName(),
command.bodyText(),
postCategory,
command.tags()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ public record CreateDraftCommand(
Long memberId,
String blogName,
String title,
String intro,
String bodyText,
@Nullable String postThumbnailImageName,
@Nullable Long categoryId,
List<String> tags
) {
public Draft toDraft(Member member, Blog blog, @Nullable PostCategory postCategory) {
return Draft.builder()
.blog(blog)
.title(title)
.intro(intro)
.bodyText(bodyText)
.postThumbnailImageName(postThumbnailImageName)
.category(postCategory)
.tags(tags)
.writer(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public record UpdateDraftCommand(
Long memberId,
Long draftId,
String title,
String intro,
String bodyText,
@Nullable String postThumbnailImageName,
@Nullable Long categoryId,
List<String> tags
) {
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/com/mallang/post/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.mallang.post.exception.PostLikeCountNegativeException;
import jakarta.annotation.Nullable;
import jakarta.persistence.AssociationOverride;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -43,6 +44,12 @@ public class Post extends CommonRootEntity<PostId> {
@AssociationOverride(name = "tags", joinTable = @JoinTable(name = "post_tags"))
private PostContent content;

@Embedded
private PostIntro postIntro;

@Column(nullable = true)
private String postThumbnailImageName;

private int likeCount = 0;

@Builder
Expand All @@ -62,7 +69,9 @@ public Post(
this.id = id;
this.blog = blog;
this.visibilityPolish = new PostVisibilityPolicy(visibility, password);
this.content = new PostContent(title, intro, bodyText, postThumbnailImageName, category, tags, writer);
this.content = new PostContent(title, bodyText, category, tags, writer);
this.postThumbnailImageName = postThumbnailImageName;
setPostIntro(intro, bodyText);
blog.validateOwner(writer);
}

Expand All @@ -77,7 +86,17 @@ public void update(
List<String> tags
) {
this.visibilityPolish = new PostVisibilityPolicy(visibility, password);
this.content = new PostContent(title, intro, bodyText, postThumbnailImageName, category, tags, getWriter());
this.content = new PostContent(title, bodyText, category, tags, getWriter());
this.postThumbnailImageName = postThumbnailImageName;
setPostIntro(intro, bodyText);
}

private void setPostIntro(String postIntro, String bodyText) {
if (postIntro == null || postIntro.isBlank()) {
this.postIntro = new PostIntro(bodyText.substring(0, Math.min(150, bodyText.length())));
return;
}
this.postIntro = new PostIntro(postIntro);
}

public void delete() {
Expand Down Expand Up @@ -130,16 +149,12 @@ public String getBodyText() {
return content.getBodyText();
}

public String getPostThumbnailImageName() {
return content.getPostThumbnailImageName();
}

public PostCategory getCategory() {
return content.getCategory();
}

public String getPostIntro() {
return content.getPostIntro();
return this.postIntro.getIntro();
}

public List<String> getTags() {
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/com/mallang/post/domain/PostContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.util.ArrayList;
Expand All @@ -30,12 +29,6 @@ public class PostContent {
@Column(nullable = false, columnDefinition = "TEXT")
private String bodyText;

@Column(nullable = true)
private String postThumbnailImageName;

@Embedded
private PostIntro postIntro;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "category_id", nullable = true)
private PostCategory category;
Expand All @@ -50,30 +43,18 @@ public class PostContent {
@Builder
public PostContent(
String title,
String postIntro,
String bodyText,
@Nullable String postThumbnailImageName,
@Nullable PostCategory category,
List<String> tags,
Member writer
) {
this.title = title;
this.bodyText = bodyText;
this.postThumbnailImageName = postThumbnailImageName;
this.writer = writer;
setPostIntro(postIntro, bodyText);
setPostCategory(category);
setTags(tags);
}

private void setPostIntro(String postIntro, String bodyText) {
if (postIntro == null || postIntro.isBlank()) {
this.postIntro = new PostIntro(bodyText.substring(0, Math.min(150, bodyText.length())));
return;
}
this.postIntro = new PostIntro(postIntro);
}

private void setPostCategory(@Nullable PostCategory category) {
if (category == null) {
this.category = null;
Expand Down Expand Up @@ -108,19 +89,13 @@ public boolean isWriter(Member member) {
public PostContent removeCategory() {
return new PostContent(
getTitle(),
getPostIntro(),
getBodyText(),
getPostThumbnailImageName(),
null,
getTags(),
getWriter()
);
}

public String getPostIntro() {
return postIntro.getIntro();
}

public List<String> getTags() {
return tags.stream()
.map(Tag::getContent)
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/com/mallang/post/domain/draft/Draft.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,23 @@ public class Draft extends CommonRootEntity<Long> {
public Draft(
Blog blog,
String title,
String intro,
String bodyText,
@Nullable String postThumbnailImageName,
@Nullable PostCategory category,
List<String> tags,
Member writer
) {
this.blog = blog;
this.content = new PostContent(title, intro, bodyText, postThumbnailImageName, category, tags, writer);
this.content = new PostContent(title, bodyText, category, tags, writer);
blog.validateOwner(writer);
}

public void update(
String title,
String intro,
String bodyText,
@Nullable String postThumbnailImageName,
@Nullable PostCategory category,
List<String> tags
) {
this.content = new PostContent(title, intro, bodyText, postThumbnailImageName, category, tags, getWriter());
this.content = new PostContent(title, bodyText, category, tags, getWriter());
}

public void removeCategory() {
Expand All @@ -94,18 +90,10 @@ public String getBodyText() {
return content.getBodyText();
}

public String getPostThumbnailImageName() {
return content.getPostThumbnailImageName();
}

public PostCategory getCategory() {
return content.getCategory();
}

public String getPostIntro() {
return content.getPostIntro();
}

public List<String> getTags() {
return content.getTags();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
public record CreateDraftRequest(
String blogName,
String title,
@Nullable String intro,
String bodyText,
@Nullable String postThumbnailImageName,
@Nullable Long categoryId,
List<String> tags
) {
Expand All @@ -19,8 +17,6 @@ public CreateDraftCommand toCommand(Long memberId) {
.blogName(blogName)
.title(title)
.bodyText(bodyText)
.postThumbnailImageName(postThumbnailImageName)
.intro(intro)
.categoryId(categoryId)
.tags(tags)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

public record UpdateDraftRequest(
String title,
@Nullable String intro,
String bodyText,
@Nullable String postThumbnailImageName,
@Nullable Long categoryId,
List<String> tags
) {
Expand All @@ -18,8 +16,6 @@ public UpdateDraftCommand toCommand(Long memberId, Long draftId) {
.draftId(draftId)
.title(title)
.bodyText(bodyText)
.postThumbnailImageName(postThumbnailImageName)
.intro(intro)
.categoryId(categoryId)
.tags(tags)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.mallang.post.domain.PostCategory;
import com.mallang.post.domain.PostContent;
import com.mallang.post.domain.draft.Draft;
import jakarta.annotation.Nullable;
import java.util.List;

public record DraftDetailResponse(
Long draftId,
String title,
String bodyText,
@Nullable String postThumbnailImageName,
CategoryResponse category,
TagResponses tags
) {
Expand All @@ -19,7 +17,6 @@ public static DraftDetailResponse from(Draft draft) {
draft.getId(),
draft.getTitle(),
draft.getBodyText(),
draft.getPostThumbnailImageName(),
CategoryResponse.from(draft.getContent()),
TagResponses.from(draft.getContent())
);
Expand Down
18 changes: 6 additions & 12 deletions src/test/java/com/mallang/acceptance/post/DraftAcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ protected void setUp() {
임시_글_생성_요청 = new CreateDraftRequest(
말랑_블로그_이름,
"첫 임시_글",
"첫 임시_글 인트로", "첫 임시_글이네요.",
"임시_글 썸네일 이름",
"첫 임시_글이네요.",
Spring_카테고리_ID,
List.of("태그1", "태그2")
);
Expand All @@ -82,8 +81,7 @@ class 임시_글_저장_API {
CreateDraftRequest createDraftRequest = new CreateDraftRequest(
말랑_블로그_이름,
"첫 임시_글",
"첫 임시_글 인트로", "첫 임시_글이네요.",
"임시_글 썸네일 이름",
"첫 임시_글이네요.",
Spring_카테고리_ID,
List.of("태그1", "태그2")
);
Expand All @@ -105,8 +103,7 @@ class 임시_글_수정_API {
var 임시_글_ID = ID를_추출한다(임시_글_생성_요청(말랑_세션_ID, 임시_글_생성_요청));
UpdateDraftRequest 임시_글_수정_요청 = new UpdateDraftRequest(
"업데이트 제목",
"업데이트 인트로", "업데이트 내용",
"업데이트 임시_글 썸네일 이름",
"업데이트 내용",
Spring_카테고리_ID,
List.of("태그1", "태그2")
);
Expand All @@ -124,8 +121,7 @@ class 임시_글_수정_API {
var 임시_글_ID = ID를_추출한다(임시_글_생성_요청(말랑_세션_ID, 임시_글_생성_요청));
UpdateDraftRequest 임시_글_수정_요청 = new UpdateDraftRequest(
"업데이트 제목",
"업데이트 인트로", "업데이트 내용",
"업데이트 임시_글 썸네일 이름",
"업데이트 내용",
Spring_카테고리_ID,
List.of("태그1", "태그2")
);
Expand Down Expand Up @@ -175,16 +171,14 @@ class 임시_글_목록_조회_API {
CreateDraftRequest 임시_글_1_생성_요청 = new CreateDraftRequest(
말랑_블로그_이름,
"임시 글 1",
"첫 임시 글 인트로", "첫 임시 글이네요.",
"임시 글 썸네일 이름",
"첫 임시 글이네요.",
Spring_카테고리_ID,
List.of("태그1", "태그2")
);
CreateDraftRequest 임시_글_2_생성_요청 = new CreateDraftRequest(
말랑_블로그_이름,
"임시 글 2",
"임시 글 2 인트로", "두번째",
"임시 글 썸네일 이름",
"두번째",
null,
Collections.emptyList()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ void setUp() {
var 임시_글_생성_요청 = new CreateDraftRequest(
말랑_블로그_이름,
"첫 임시_글",
"첫 임시_글 인트로", "첫 임시_글이네요.",
"임시_글 썸네일 이름",
"첫 임시_글이네요.",
Spring_카테고리_ID,
List.of("태그1", "태그2")
);
Expand Down
Loading