From e6b11d6d0fad8f001a9915a456a1da5fd734f071 Mon Sep 17 00:00:00 2001 From: kms Date: Tue, 6 Dec 2022 00:43:01 +0900 Subject: [PATCH 1/4] feat: [FE] Comment API Add. --- .../article/service/CommentServiceImpl.java | 7 ++--- src/vite-frontend/src/api/index.ts | 24 ++++++++++++++++- .../src/components/commentList.vue | 27 ++++++++++++++++--- src/vite-frontend/src/router/index.ts | 2 +- src/vite-frontend/src/views/ArticleUpdate.vue | 16 +++++------ .../src/views/TheArticleDetail.vue | 27 ++++++++++++++----- 6 files changed, 77 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/io/realworld/domain/aggregate/article/service/CommentServiceImpl.java b/src/main/java/com/io/realworld/domain/aggregate/article/service/CommentServiceImpl.java index 7875636..e6ad1b8 100644 --- a/src/main/java/com/io/realworld/domain/aggregate/article/service/CommentServiceImpl.java +++ b/src/main/java/com/io/realworld/domain/aggregate/article/service/CommentServiceImpl.java @@ -61,9 +61,10 @@ public class CommentServiceImpl implements CommentService { if (article.isEmpty()) { throw new CustomException(Error.ARTICLE_NOT_FOUND); } + System.out.println(user.get().getUsername()+"!!"); Comment comment = commentRepository.save(Comment.builder().body(commentdto.getBody()).article(article.get()).author(user.get()).build()); - return convertComment(userAuth, article.get(), comment); + return convertComment(userAuth, comment); } @Override @@ -80,9 +81,9 @@ public class CommentServiceImpl implements CommentService { commentRepository.delete(comment.get()); } - private CommentResponse convertComment(UserAuth userAuth, Article article, Comment comment) { + private CommentResponse convertComment(UserAuth userAuth, Comment comment) { - ProfileResponse profile = profileService.getProfile(userAuth, article.getAuthor().getUsername()); + ProfileResponse profile = profileService.getProfile(userAuth, userAuth.getUsername()); return CommentResponse.builder() .id(comment.getId()) diff --git a/src/vite-frontend/src/api/index.ts b/src/vite-frontend/src/api/index.ts index 020ab42..d63b5dc 100644 --- a/src/vite-frontend/src/api/index.ts +++ b/src/vite-frontend/src/api/index.ts @@ -74,7 +74,7 @@ const createArticle = async (article: object | undefined): Promise => { +const updateArticle = async (article: object | undefined, slug: string | undefined): Promise => { let currentToken = localStorage.getItem("token"); return await axiosService.put('/api/articles/' + slug, { article },{ headers :{ @@ -84,6 +84,16 @@ const updateArticle = async (article: object | undefined, slug: string): Promise }) } +const deleteArticle = async (slug: string | undefined): Promise => { + let currentToken = localStorage.getItem("token"); + return await axiosService.delete('/api/articles/' + slug,{ + headers :{ + Authorization : "TOKEN " + currentToken, + "Content-Type": `application/json`, + } + }) +} + const listArticles = async (): Promise => { let currentToken = localStorage.getItem("token"); if(currentToken == null){ @@ -171,6 +181,17 @@ const getCommentsFromArticle = async (slug: string | undefined): Promise => { + let currentToken = localStorage.getItem("token"); + return await axiosService.delete('/api/articles/' + slug + '/comments/' + id,{ + headers:{ + Authorization : "TOKEN " + currentToken, + "Content-Type": `application/json`, + } + }); +} + + const favoriteArticle = async (slug: string | undefined): Promise => { let currentToken = localStorage.getItem("token"); return await axiosService.post('/api/articles/' + slug + '/favorite',{}, @@ -206,5 +227,6 @@ export { signUp, signIn, addCommentToArticle, getCommentsFromArticle, favoriteArticle, unFavoriteArticle, listArticlesByFavorite, updateArticle, + deleteArticle, deleteCommentsFromArticle, getTags } \ No newline at end of file diff --git a/src/vite-frontend/src/components/commentList.vue b/src/vite-frontend/src/components/commentList.vue index a2e8294..1e54e2e 100644 --- a/src/vite-frontend/src/components/commentList.vue +++ b/src/vite-frontend/src/components/commentList.vue @@ -7,17 +7,21 @@ -   {{comment.author.username}} {{convertDate(comment.updatedAt)}} + + +