Skip to content

Commit ee2cf83

Browse files
authored
refactor/#230 게시글 고정 여부 추가 (#231)
* refactor: 게시글 생성 시 고정 여부 추가 * refactor: 게시글 수정 시 고정 여부 추가 * refactor: testcode 수정 * Update PostAdminFacadeTest.java * Update CommentFacadeTest.java * Update PostFacadeTest.java * Update PostDomainTest.java
1 parent 6d33707 commit ee2cf83

File tree

14 files changed

+49
-37
lines changed

14 files changed

+49
-37
lines changed

aics-admin/src/main/java/kgu/developers/admin/post/application/PostAdminFacade.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public class PostAdminFacade {
2020
private final PostSchedulingService postSchedulingService;
2121

2222
public PostPersistResponse createPost(Long fileId, PostCreateRequest request) {
23-
Long id = postCommandService.createPost(request.title(), request.content(), request.category(), fileId);
23+
Long id = postCommandService.createPost(request.title(), request.content(), request.category(), fileId, request.isPinned());
2424
return PostPersistResponse.from(id);
2525
}
2626

2727
@Transactional
2828
public void updatePost(Long postId, PostUpdateRequest request) {
2929
Post post = postQueryService.getById(postId);
30-
postCommandService.updatePost(post, request.title(), request.content(), request.category(), request.fileId());
30+
postCommandService.updatePost(post, request.title(), request.content(), request.category(), request.fileId(), request.isPinned());
3131
}
3232

3333
@Transactional

aics-admin/src/main/java/kgu/developers/admin/post/presentation/request/PostCreateRequest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public record PostCreateRequest(
2828
String content,
2929

3030
@Schema(description = "게시물 카테고리", example = "NOTIFICATION", requiredMode = NOT_REQUIRED)
31-
Category category
31+
Category category,
32+
33+
@Schema(description = "게시글 고정 여부", example = "FALSE", requiredMode = REQUIRED)
34+
boolean isPinned
3235
) {
3336
}

aics-admin/src/main/java/kgu/developers/admin/post/presentation/request/PostUpdateRequest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public record PostUpdateRequest(
3131
Category category,
3232

3333
@Schema(description = "파일 ID", example = "1")
34-
Long fileId
34+
Long fileId,
35+
36+
@Schema(description = "게시글 고정 여부", example = "FALSE", requiredMode = REQUIRED)
37+
boolean isPinned
3538
) {
3639
}

aics-admin/src/testFixtures/java/post/application/PostAdminFacadeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void init() {
6565

6666
fakePostRepository.save(
6767
Post.create(
68-
"post title", "post content", NOTIFICATION, author, null
68+
"post title", "post content", NOTIFICATION, author, null, false
6969
)
7070
);
7171
}

aics-api/src/testFixtures/java/comment/application/CommentFacadeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void init() {
6262
.build());
6363

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

6868
fakeCommentRepository.save(Comment.create(

aics-api/src/testFixtures/java/post/application/PostFacadeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ public void init() {
6767
);
6868

6969
fakePostRepository.save(Post.create(
70-
"first title", "first content", NEWS, author, null
70+
"first title", "first content", NEWS, author, null, false
7171
));
7272

7373
Post delete = fakePostRepository.save(Post.create(
74-
"second title", "second content", NEWS, author, null
74+
"second title", "second content", NEWS, author, null, false
7575
));
7676
delete.delete();
7777

7878
fakePostRepository.save(Post.create(
79-
"third title", "third content", NEWS, author, null
79+
"third title", "third content", NEWS, author, null, false
8080
));
8181
}
8282

aics-domain/src/main/java/kgu/developers/domain/post/application/command/PostCommandService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ public class PostCommandService {
1818
private final PostRepository postRepository;
1919
private final FileQueryService fileQueryService;
2020

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

2424
FileEntity file = null;
2525
if (fileId != null)
2626
file = fileQueryService.getFileById(fileId);
2727

28-
Post post = Post.create(title, content, category, author, file);
28+
Post post = Post.create(title, content, category, author, file, isPinned);
2929
return postRepository.save(post).getId();
3030
}
3131

32-
public void updatePost(Post post, String title, String content, Category category, Long fileId) {
32+
public void updatePost(Post post, String title, String content, Category category, Long fileId, boolean isPinned) {
3333
post.updateTitle(title);
3434
post.updateContent(content);
3535
post.updateCategory(category);
36+
post.updatePinned(isPinned);
3637

3738
FileEntity file = null;
3839
if (fileId != null)

aics-domain/src/main/java/kgu/developers/domain/post/domain/Post.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ public class Post extends BaseTimeEntity {
6565
@OneToMany(mappedBy = "post", fetch = LAZY, cascade = ALL, orphanRemoval = true)
6666
private List<Comment> comments = new ArrayList<>();
6767

68-
public static Post create(String title, String content, Category category, User author, FileEntity file) {
68+
public static Post create(String title, String content, Category category, User author, FileEntity file, boolean isPinned) {
6969
return Post.builder()
7070
.title(title)
7171
.content(content)
7272
.views(0)
73-
.isPinned(false)
73+
.isPinned(isPinned)
7474
.category(category)
75-
.author(author) // NOTE: User Setter 주입 방지 위해 생성자 주입
75+
.author(author)
7676
.file(file)
7777
.build();
7878
}
@@ -89,8 +89,8 @@ public void updateCategory(Category category) {
8989
this.category = category;
9090
}
9191

92-
public void togglePinned() {
93-
this.isPinned = !this.isPinned;
92+
public void updatePinned(boolean isPinned) {
93+
this.isPinned = isPinned;
9494
}
9595

9696
public void increaseViews() {
@@ -100,4 +100,8 @@ public void increaseViews() {
100100
public void updateFile(FileEntity file) {
101101
this.file = file;
102102
}
103+
104+
public void togglePinned() {
105+
this.isPinned = !this.isPinned;
106+
}
103107
}

aics-domain/src/testFixtures/java/comment/application/CommentCommandServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.springframework.security.core.context.SecurityContext;
1414
import org.springframework.security.core.context.SecurityContextHolder;
1515
import org.springframework.security.core.userdetails.UserDetails;
16+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
17+
import org.springframework.security.crypto.password.PasswordEncoder;
1618

1719
import kgu.developers.domain.comment.application.command.CommentCommandService;
1820
import kgu.developers.domain.comment.domain.Comment;
@@ -23,8 +25,6 @@
2325
import mock.repository.FakeCommentRepository;
2426
import mock.repository.FakePostRepository;
2527
import mock.repository.FakeUserRepository;
26-
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
27-
import org.springframework.security.crypto.password.PasswordEncoder;
2828

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

aics-domain/src/testFixtures/java/comment/application/CommentQueryServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static void saveTestComment(FakeCommentRepository fakeCommentRepository,
5555
private static Post saveTestPost() {
5656
FakePostRepository fakePostRepository = new FakePostRepository();
5757
Post commentedPost = Post.create("SW 부트캠프 4기 교육생 모집",
58-
"SW전문인재양성사업단에서는 SW부트캠프 4기 교육생을 모집합니다.", NEWS, User.builder().build(), null);
58+
"SW전문인재양성사업단에서는 SW부트캠프 4기 교육생을 모집합니다.", NEWS, User.builder().build(), null, false);
5959
return fakePostRepository.save(commentedPost);
6060
}
6161

0 commit comments

Comments
 (0)