Skip to content

Commit

Permalink
[TDC-101] targetId 추가, postType -> sectionType 으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yerimkoko committed Jun 20, 2024
1 parent fcb7e87 commit aa8efe3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,30 @@ public class PostAddRequest {

private String title;

private String targetId;

@NotBlank
private String content;

@NotNull
private List<PostSectionRequest> postSectionRequests;
private List<PostSectionRequest> sections;

@Builder
public PostAddRequest(PostGroup postGroup, Long parentId, String title, String content, String accountId, List<PostSectionRequest> postSectionRequests) {
public PostAddRequest(PostGroup postGroup, Long parentId, String title, String content, String targetId, List<PostSectionRequest> sections) {
this.postGroup = postGroup;
this.parentId = parentId;
this.title = title;
this.targetId =
this.content = content;
this.postSectionRequests = postSectionRequests;
this.sections = sections;
}

public Post toEntity(String workspaceId, String accountId) {

Post post = Post.of(postGroup, parentId, workspaceId, title, content, accountId);
Post post = Post.of(postGroup, parentId, workspaceId, title, content, targetId, accountId);

for (PostSectionRequest postSectionRequest : postSectionRequests) {
post.add(postSectionRequest.toEntity(post));
for (PostSectionRequest section : sections) {
post.add(section.toEntity(post));
}
return post;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.threedollar.service.post.request;

import com.threedollar.domain.post.Post;
import com.threedollar.domain.post.PostType;
import com.threedollar.domain.post.SectionType;
import com.threedollar.domain.post.postsection.PostSection;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
Expand All @@ -13,7 +13,7 @@
public class PostSectionRequest {

@NotNull
private PostType postType;
private SectionType sectionType;

private int priority;

Expand All @@ -24,8 +24,8 @@ public class PostSectionRequest {
private int height;

@Builder
public PostSectionRequest(PostType postType, int priority, String url, int width, int height) {
this.postType = postType;
public PostSectionRequest(SectionType sectionType, int priority, String url, int width, int height) {
this.sectionType = sectionType;
this.priority = priority;
this.url = url;
this.width = width;
Expand All @@ -34,7 +34,7 @@ public PostSectionRequest(PostType postType, int priority, String url, int width

public PostSection toEntity(Post post) {

return PostSection.of(postType, post, priority, url, width, height);
return PostSection.of(sectionType, post, priority, url, width, height);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.threedollar.domain.post.Post;
import com.threedollar.domain.post.PostGroup;
import com.threedollar.domain.post.PostStatus;
import com.threedollar.domain.post.PostType;
import com.threedollar.domain.post.SectionType;
import com.threedollar.domain.post.repository.PostRepository;
import com.threedollar.service.post.request.PostAddRequest;
import com.threedollar.service.post.request.PostSectionRequest;
Expand Down Expand Up @@ -46,7 +46,7 @@ void clean_up() {
Post post = postRepository.findAll().get(0);
assertThat(postRepository.findAll()).hasSize(1);
assertThat(workspaceId).isEqualTo(post.getWorkspaceId());
assertPost(post, request.getPostGroup(), request.getTitle(), request.getContent(), accountId);
assertPost(post, request.getPostGroup(), request.getTitle(), request.getContent(), accountId, request.getTargetId());
}

@Test
Expand All @@ -65,12 +65,13 @@ void clean_up() {

}

private void assertPost(Post post, PostGroup postGroup, String title, String content, String accountId) {
private void assertPost(Post post, PostGroup postGroup, String title, String content, String accountId, String targetId) {

assertThat(post.getPostGroup()).isEqualTo(postGroup);
assertThat(post.getTitle()).isEqualTo(title);
assertThat(post.getContent()).isEqualTo(content);
assertThat(post.getAccountId()).isEqualTo(accountId);
assertThat(post.getTargetId()).isEqualTo(targetId);

}

Expand All @@ -79,13 +80,14 @@ private PostAddRequest newRequest() {
PostGroup postGroup = PostGroup.BOSS_NEWS;
String title = "은평구 핫도그 아저씨";
String content = "콘텐트";
PostType postType = PostType.IMAGE;
SectionType sectionType = SectionType.IMAGE;
int height = 400;
int width = 200;
String url = "image.jpg";
String targetId = "111";

PostSectionRequest postSectionRequest = PostSectionRequest.builder()
.postType(postType)
.sectionType(sectionType)
.height(height)
.width(width)
.url(url)
Expand All @@ -94,8 +96,9 @@ private PostAddRequest newRequest() {
return PostAddRequest.builder()
.postGroup(postGroup)
.title(title)
.targetId(targetId)
.content(content)
.postSectionRequests(List.of(postSectionRequest))
.sections(List.of(postSectionRequest))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class Post extends BaseEntity {
@Column(length = 4000)
private String content;

private String targetId;

@Column(nullable = false, length = 200)
private String accountId;

Expand All @@ -48,12 +50,13 @@ public class Post extends BaseEntity {
private final List<PostSection> postSection = new ArrayList<>();

@Builder
public Post(PostGroup postGroup, Long parentId, String workspaceId, String title, String content, String accountId, PostStatus status) {
public Post(PostGroup postGroup, Long parentId, String workspaceId, String title, String content, String targetId, String accountId, PostStatus status) {
this.postGroup = postGroup;
this.parentId = parentId;
this.workspaceId = workspaceId;
this.title = title;
this.content = content;
this.targetId = targetId;
this.accountId = accountId;
this.status = status;
}
Expand All @@ -67,13 +70,14 @@ public void delete() {
}

public static Post of(PostGroup postGroup, Long parentId, String workspaceId,
String title, String content, String accountId) {
String title, String content, String targetId, String accountId) {
return Post.builder()
.postGroup(postGroup)
.parentId(parentId)
.workspaceId(workspaceId)
.title(title)
.content(content)
.targetId(targetId)
.accountId(accountId)
.status(PostStatus.ACTIVE)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Getter
@RequiredArgsConstructor
public enum PostType {
public enum SectionType {

IMAGE("사진"),
TEXT("글"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.threedollar.domain.BaseEntity;
import com.threedollar.domain.post.Post;
import com.threedollar.domain.post.PostType;
import com.threedollar.domain.post.SectionType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand All @@ -22,7 +22,7 @@ public class PostSection extends BaseEntity {

@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 200)
private PostType postType;
private SectionType sectionType;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
Expand All @@ -41,19 +41,19 @@ public class PostSection extends BaseEntity {
private int height;

@Builder
public PostSection(PostType postType, Post post, int priority, String url, int width, int height) {
this.postType = postType;
public PostSection(SectionType sectionType, Post post, int priority, String url, int width, int height) {
this.sectionType = sectionType;
this.post = post;
this.priority = priority;
this.url = url;
this.width = width;
this.height = height;
}

public static PostSection of(PostType postType, Post post, int priority, String url, int width, int height) {
public static PostSection of(SectionType sectionType, Post post, int priority, String url, int width, int height) {
return PostSection.builder()
.post(post)
.postType(postType)
.sectionType(sectionType)
.priority(priority)
.url(url)
.width(width)
Expand Down

0 comments on commit aa8efe3

Please sign in to comment.