Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -20,14 +20,14 @@ public class PostAdminFacade {
private final PostSchedulingService postSchedulingService;

public PostPersistResponse createPost(Long fileId, PostCreateRequest request) {
Long id = postCommandService.createPost(request.title(), request.content(), request.category(), fileId);
Long id = postCommandService.createPost(request.title(), request.content(), request.category(), fileId, request.isPinned());
return PostPersistResponse.from(id);
}

@Transactional
public void updatePost(Long postId, PostUpdateRequest request) {
Post post = postQueryService.getById(postId);
postCommandService.updatePost(post, request.title(), request.content(), request.category(), request.fileId());
postCommandService.updatePost(post, request.title(), request.content(), request.category(), request.fileId(), request.isPinned());
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public record PostCreateRequest(
String content,

@Schema(description = "게시물 카테고리", example = "NOTIFICATION", requiredMode = NOT_REQUIRED)
Category category
Category category,

@Schema(description = "게시글 고정 여부", example = "FALSE", requiredMode = REQUIRED)
boolean isPinned
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public record PostUpdateRequest(
Category category,

@Schema(description = "파일 ID", example = "1")
Long fileId
Long fileId,

@Schema(description = "게시글 고정 여부", example = "FALSE", requiredMode = REQUIRED)
boolean isPinned
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ public class PostCommandService {
private final PostRepository postRepository;
private final FileQueryService fileQueryService;

public Long createPost(String title, String content, Category category, Long fileId) {
public Long createPost(String title, String content, Category category, Long fileId, boolean isPinned) {
User author = userQueryService.me();

FileEntity file = null;
if (fileId != null)
file = fileQueryService.getFileById(fileId);

Post post = Post.create(title, content, category, author, file);
Post post = Post.create(title, content, category, author, file, isPinned);
return postRepository.save(post).getId();
}

public void updatePost(Post post, String title, String content, Category category, Long fileId) {
public void updatePost(Post post, String title, String content, Category category, Long fileId, boolean isPinned) {
post.updateTitle(title);
post.updateContent(content);
post.updateCategory(category);
post.updatePinned(isPinned);

FileEntity file = null;
if (fileId != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public class Post extends BaseTimeEntity {
@OneToMany(mappedBy = "post", fetch = LAZY, cascade = ALL, orphanRemoval = true)
private List<Comment> comments = new ArrayList<>();

public static Post create(String title, String content, Category category, User author, FileEntity file) {
public static Post create(String title, String content, Category category, User author, FileEntity file, boolean isPinned) {
return Post.builder()
.title(title)
.content(content)
.views(0)
.isPinned(false)
.isPinned(isPinned)
.category(category)
.author(author) // NOTE: User Setter 주입 방지 위해 생성자 주입
.author(author)
.file(file)
.build();
}
Expand All @@ -89,8 +89,8 @@ public void updateCategory(Category category) {
this.category = category;
}

public void togglePinned() {
this.isPinned = !this.isPinned;
public void updatePinned(boolean isPinned) {
this.isPinned = isPinned;
}

public void increaseViews() {
Expand All @@ -100,4 +100,8 @@ public void increaseViews() {
public void updateFile(FileEntity file) {
this.file = file;
}

public void togglePinned() {
this.isPinned = !this.isPinned;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void createPost_Success() {
Long fileId = 1L;

// when
Long result = postCommandService.createPost(title, content, category, fileId);
Long result = postCommandService.createPost(title, content, category, fileId, false);

// then
assertEquals(1L, result);
Expand All @@ -82,7 +82,7 @@ public void updatePost_Success() {
Category newCategory = NOTIFICATION;

// when
postCommandService.updatePost(post, newTitle, newContent, newCategory, 1L);
postCommandService.updatePost(post, newTitle, newContent, newCategory, 1L, false);

// then
assertEquals(newTitle, post.getTitle());
Expand Down
Loading