diff --git a/src/main/java/com/mallang/post/domain/Post.java b/src/main/java/com/mallang/post/domain/Post.java index a9b21be2..2362892a 100644 --- a/src/main/java/com/mallang/post/domain/Post.java +++ b/src/main/java/com/mallang/post/domain/Post.java @@ -82,7 +82,7 @@ public void update( List tags ) { this.visibilityPolish = new PostVisibilityPolicy(visibility, password); - this.content.update(title, intro, bodyText, postThumbnailImageName, category, tags); + this.content = new PostContent(title, intro, bodyText, postThumbnailImageName, category, tags, getWriter()); } public void delete() { @@ -90,7 +90,7 @@ public void delete() { } public void removeCategory() { - this.content.removeCategory(); + this.content = content.removeCategory(); } public void clickLike() { diff --git a/src/main/java/com/mallang/post/domain/PostContent.java b/src/main/java/com/mallang/post/domain/PostContent.java index f368ceb1..d54f5eee 100644 --- a/src/main/java/com/mallang/post/domain/PostContent.java +++ b/src/main/java/com/mallang/post/domain/PostContent.java @@ -59,26 +59,10 @@ public PostContent( Member writer ) { this.title = title; - this.bodyText = bodyText; - this.postThumbnailImageName = postThumbnailImageName; this.postIntro = new PostIntro(postIntro); - this.writer = writer; - setCategory(category); - setTags(tags); - } - - public void update( - String title, - String postIntro, - String bodyText, - @Nullable String postThumbnailImageName, - @Nullable Category category, - List tags - ) { - this.title = title; this.bodyText = bodyText; this.postThumbnailImageName = postThumbnailImageName; - this.postIntro = new PostIntro(postIntro); + this.writer = writer; setCategory(category); setTags(tags); } @@ -114,8 +98,16 @@ public boolean isWriter(Member member) { return writer.equals(member); } - public void removeCategory() { - this.category = null; + public PostContent removeCategory() { + return new PostContent( + getTitle(), + getPostIntro(), + getBodyText(), + getPostThumbnailImageName(), + null, + getTags(), + getWriter() + ); } public String getPostIntro() { diff --git a/src/main/java/com/mallang/post/domain/draft/Draft.java b/src/main/java/com/mallang/post/domain/draft/Draft.java index 4e0247f7..a30405db 100644 --- a/src/main/java/com/mallang/post/domain/draft/Draft.java +++ b/src/main/java/com/mallang/post/domain/draft/Draft.java @@ -73,11 +73,11 @@ public void update( @Nullable Category category, List tags ) { - this.content.update(title, intro, bodyText, postThumbnailImageName, category, tags); + this.content = new PostContent(title, intro, bodyText, postThumbnailImageName, category, tags, getWriter()); } public void removeCategory() { - this.content.removeCategory(); + this.content = content.removeCategory(); } public void validateWriter(Member member) { diff --git a/src/test/java/com/mallang/post/domain/PostContentTest.java b/src/test/java/com/mallang/post/domain/PostContentTest.java index cb2a9332..a57174a5 100644 --- a/src/test/java/com/mallang/post/domain/PostContentTest.java +++ b/src/test/java/com/mallang/post/domain/PostContentTest.java @@ -12,7 +12,6 @@ import com.mallang.category.domain.Category; import com.mallang.category.exception.NoAuthorityCategoryException; import com.mallang.post.exception.DuplicatedTagsInPostException; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; @@ -45,10 +44,14 @@ class PostContentTest { .build(); // when - postContent.removeCategory(); + PostContent removeCategory = postContent.removeCategory(); // then - assertThat(postContent.getCategory()).isNull(); + assertThat(removeCategory.getCategory()).isNull(); + assertThat(removeCategory) + .usingRecursiveComparison() + .ignoringFields("category") + .isEqualTo(postContent); } @Nested @@ -155,60 +158,6 @@ class 생성_시 { } } - @Nested - class 수정_시 { - - @Test - void 수정에_성공한다() { - // given - PostContent postContent = PostContent.builder() - .title("제목") - .postIntro("intro") - .bodyText("내용") - .writer(mallang) - .tags(List.of("태그1")) - .build(); - - // when - postContent.update( - "수정제목", - "수정인트로", "수정내용", - "postThumbnailImageName", - null, - List.of("태그2") - ); - - // then - assertThat(postContent.getTitle()).isEqualTo("수정제목"); - assertThat(postContent.getBodyText()).isEqualTo("수정내용"); - assertThat(postContent.getTags()) - .containsExactly("태그2"); - } - - @Test - void 다른_사람의_카테고리로_수정_시_예외() { - // given - PostContent postContent = PostContent.builder() - .title("제목") - .postIntro("intro") - .bodyText("내용") - .writer(mallang) - .tags(List.of("태그1")) - .build(); - - // when & then - assertThatThrownBy(() -> { - postContent.update( - "수정제목", - "수정인트로", "수정내용", - "postThumbnailImageName", - otherCategory, - Collections.emptyList() - ); - }).isInstanceOf(NoAuthorityCategoryException.class); - } - } - @Test void 작성자_확인() { // given