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 @@ -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 @@ -65,7 +65,7 @@ public void init() {

fakePostRepository.save(
Post.create(
"post title", "post content", NOTIFICATION, author, null
"post title", "post content", NOTIFICATION, author, null, false
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void init() {
.build());

Post post = fakePostRepository.save(Post.create(
"테스트용 제목1", "테스트용 내용1", NEWS, author, null
"테스트용 제목1", "테스트용 내용1", NEWS, author, null, false
));

fakeCommentRepository.save(Comment.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ public void init() {
);

fakePostRepository.save(Post.create(
"first title", "first content", NEWS, author, null
"first title", "first content", NEWS, author, null, false
));

Post delete = fakePostRepository.save(Post.create(
"second title", "second content", NEWS, author, null
"second title", "second content", NEWS, author, null, false
));
delete.delete();

fakePostRepository.save(Post.create(
"third title", "third content", NEWS, author, null
"third title", "third content", NEWS, author, null, false
));
}

Expand Down
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 @@ -13,6 +13,8 @@
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import kgu.developers.domain.comment.application.command.CommentCommandService;
import kgu.developers.domain.comment.domain.Comment;
Expand All @@ -23,8 +25,6 @@
import mock.repository.FakeCommentRepository;
import mock.repository.FakePostRepository;
import mock.repository.FakeUserRepository;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class CommentCommandServiceTest {
private CommentCommandService commentCommandService;
Expand Down Expand Up @@ -53,7 +53,7 @@ private static void saveTestUserAndPost(FakeUserRepository fakeUserRepository,
);
fakePostRepository.save(Post.create(
"SW 부트캠프 4기 교육생 모집", "SW전문인재양성사업단에서는 SW부트캠프 4기 교육생을 모집합니다.", NEWS,
User.builder().build(), null
User.builder().build(), null, false
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static void saveTestComment(FakeCommentRepository fakeCommentRepository,
private static Post saveTestPost() {
FakePostRepository fakePostRepository = new FakePostRepository();
Post commentedPost = Post.create("SW 부트캠프 4기 교육생 모집",
"SW전문인재양성사업단에서는 SW부트캠프 4기 교육생을 모집합니다.", NEWS, User.builder().build(), null);
"SW전문인재양성사업단에서는 SW부트캠프 4기 교육생을 모집합니다.", NEWS, User.builder().build(), null, false);
return fakePostRepository.save(commentedPost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import kgu.developers.domain.comment.domain.Comment;
import kgu.developers.domain.post.domain.Post;
import kgu.developers.domain.user.domain.User;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class CommentDomainTest {
private Comment comment;
Expand Down Expand Up @@ -45,7 +45,8 @@ private Post getPost(User author) {
"content.",
NEWS,
author,
null
null,
false
);
}

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ public void init() {

fakePostRepository.save(Post.create(
"테스트용 제목1", "테스트용 내용1",
NEWS, author, null
NEWS, author, null, true
));

fakePostRepository.save(Post.create(
"테스트용 제목2", "테스트용 내용2",
NEWS, author, null
NEWS, author, null, false
));

Post delete = fakePostRepository.save(Post.create(
"테스트용 제목3", "테스트용 내용3",
NEWS, author, null
NEWS, author, null, false
));
delete.delete();

fakePostRepository.save(Post.create(
"테스트용 제목4", "테스트용 내용4",
NOTIFICATION, author, null
NOTIFICATION, author, null, false
));

fakePostRepository.save(Post.create(
"테스트용 제목5", "테스트용 내용5",
NEWS, author, null
NEWS, author, null, false
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import kgu.developers.domain.post.domain.Category;
import kgu.developers.domain.post.domain.Post;
import kgu.developers.domain.user.domain.User;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class PostDomainTest {
private Post post;
Expand All @@ -29,7 +29,7 @@ public class PostDomainTest {
@BeforeEach
public void init() {
User author = user();
post = Post.create(TITLE, CONTENT, NEWS, author, null);
post = Post.create(TITLE, CONTENT, NEWS, author, null, true);
}

private User user() {
Expand All @@ -52,7 +52,7 @@ public void createPost_Success() {
assertEquals(TITLE, post.getTitle());
assertEquals(CONTENT, post.getContent());
assertEquals(0, post.getViews());
assertFalse(post.isPinned());
assertTrue(post.isPinned());
assertEquals(NEWS, post.getCategory());
}

Expand Down Expand Up @@ -116,11 +116,11 @@ public void togglePostPinned_Success() {
// when
post.togglePinned();
// then
assertTrue(post.isPinned());
assertFalse(post.isPinned());

// when
post.togglePinned();
// then
assertFalse(post.isPinned());
assertTrue(post.isPinned());
}
}