Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Article CRUD and Comment CRUD #13

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e313192
Add: article create
thelight0804 Jul 5, 2023
fe9b97e
Add: find by title in article
thelight0804 Jul 5, 2023
d85b433
Add: like search by title or content in article
thelight0804 Jul 5, 2023
5a563f8
Add: Update article feature in test code
thelight0804 Jul 5, 2023
71c21fb
Add: Delete article feature in test code
thelight0804 Jul 5, 2023
10e249c
Add: Create comment
thelight0804 Jul 8, 2023
67e0277
Add: Read comment
thelight0804 Jul 8, 2023
247011c
Fix: test get comment
thelight0804 Jul 8, 2023
c305540
Add: update comment
thelight0804 Jul 8, 2023
bdc530d
Add: delete comment
thelight0804 Jul 8, 2023
e76bd33
Add save login user in comment
thelight0804 Jul 9, 2023
e33831b
Add save login user in Article
thelight0804 Jul 9, 2023
55fa8a2
Add method article controller and service
thelight0804 Jul 9, 2023
3d14903
Add Principal in article and comment controller method
thelight0804 Jul 10, 2023
ea9c945
Add Swagger annotation
thelight0804 Jul 11, 2023
6630e49
Fix DI to Article controller of UserService
thelight0804 Jul 12, 2023
8a8d54a
Fix sendError() when create Article
thelight0804 Jul 12, 2023
3d08cfe
Add dto in article
thelight0804 Jul 12, 2023
877e468
Fix http 400, 500 error of Article CRUD
thelight0804 Jul 12, 2023
a72394c
Fix add @controller in ArticleController
thelight0804 Jul 12, 2023
5d5be0a
Add comment DTO
thelight0804 Jul 12, 2023
9c66e7c
Add feature of Comment Create and Read
thelight0804 Jul 12, 2023
dd1ba9b
Fix typo postID -> commentID
thelight0804 Jul 12, 2023
48c9199
Add feature of comment update and delete
thelight0804 Jul 12, 2023
d2f4145
Update: apply mapping path as HTTP Method of REST API
thelight0804 Jul 14, 2023
7c153c1
Update: HttpServletRequest Swagger parameter to hidden
thelight0804 Jul 14, 2023
2073414
Update: add @Parameter to @PathVariable
thelight0804 Jul 14, 2023
ac9ac26
Remove Swagger documentation in service
thelight0804 Jul 14, 2023
3b99ccf
Add: get article by title
thelight0804 Jul 14, 2023
6fd13b0
Update: use orElseThrow() instead of if-else
thelight0804 Jul 14, 2023
a8d6e2f
Fix typo: 게시글 id instead of 댓글 id in swagger parameter annotation
thelight0804 Jul 14, 2023
66e9e2c
Remove findByArticleIdx method
thelight0804 Jul 14, 2023
122bb7b
Refactor: improve responsibility distribution by create Article, Comm…
thelight0804 Jul 14, 2023
d39ccfd
Add: Base Entity to remove Duplicate code in entity
thelight0804 Jul 14, 2023
c510964
Add: Transactional annotation
thelight0804 Jul 14, 2023
79683bd
Remove: save() method in update
thelight0804 Jul 14, 2023
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
Prev Previous commit
Next Next commit
Add: delete comment
나중에 로그인 인증 후 CRUD을 수행할 수 있게 추가하겠습니다
thelight0804 committed Jul 8, 2023
commit bdc530dd2862774dfdbd1a9b8c6042b463d39167

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위의 ArtileController에서 리뷰했던 부분들 중 상당수가 CommentController에서도 적용되기 때문에, 해당 리뷰 한번 쭉 읽어보신 후 CommentController에도 마찬가지로 적용시켜 주세요!

Original file line number Diff line number Diff line change
@@ -61,4 +61,10 @@ public void updateComment(@PathVariable("commentId") Long idx, @RequestParam Str
comment.setModifyData(LocalDateTime.now()); //update modify date
this.commentService.update(comment); //save comment
}

@PostMapping("/delete/{commentId}")
public void deleteComment(@PathVariable("commentId") Long idx){
Comment comment = this.commentService.getComment(idx); //get comment object
this.commentService.delete(comment); //delete comment
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위의 ArticleService에서 리뷰했던 부분들 중 상당수가 CommentService에서도 적용되기 때문에, 해당 리뷰 한번 쭉 읽어보신 후 CommentService에도 마찬가지로 적용시켜 주세요!

Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public void create(Article article, String content){
* @return comment object
*/
public Comment getComment(Long idx){
//return comment object if exists, or thorw exception
//return comment object if exists, or throw exception
return this.commentRepository.findById(idx).orElseThrow();
}

@@ -43,4 +43,8 @@ public Comment getComment(Long idx){
public void update(Comment comment){
this.commentRepository.save(comment);
}

public void delete(Comment comment){
this.commentRepository.delete(comment);
}
}
4 changes: 4 additions & 0 deletions src/test/java/com/gdsc/blog/BlogApplicationTests.java

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 테스트가 많이 들어가 있는 거 같은데...ArticleTest와 CommentTest로 분리되면 좋을 듯 합니다!

Copy link
Member Author

@thelight0804 thelight0804 Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 코드에서 로그인을 유지하는 방법이 어려워서 처음에 구현한 코드 그대로 두었습니다!
(현 시점에서 테스트 코드 돌리면 에러 발생합니다..)

수정해서 다시 올리겠습니다

Original file line number Diff line number Diff line change
@@ -127,5 +127,9 @@ void testComment(){
c.setModifyData(LocalDateTime.now());
this.commentService.update(c);
assertEquals("post1 comment3 updated", c.getContent()); //check updated content

//delete comment
this.commentService.delete(c);
assertEquals(2, this.commentRepository.count()); //check comment count
}
}