From db6e42d79fbc7ce7c43e0b74e9bdc5c957e4cd43 Mon Sep 17 00:00:00 2001 From: cyj199637 Date: Mon, 19 Oct 2020 23:30:45 +0900 Subject: [PATCH] =?UTF-8?q?[#35]=20=ED=8C=94=EB=A1=9C=EC=9A=B0=ED=95=9C=20?= =?UTF-8?q?=EB=AA=A8=EB=93=A0=20=EA=B3=84=EC=A0=95=EC=9D=98=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EB=AC=BC=20=EC=A1=B0=ED=9A=8C(=EB=A9=94=EC=9D=B8)=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 내가 팔로우한 계정의 게시물만 볼 수 있도록 구현 --- .../snsserver/controller/PostController.java | 9 +++++++++ .../me/liiot/snsserver/mapper/PostMapper.java | 3 +++ .../me/liiot/snsserver/service/PostService.java | 2 ++ .../snsserver/service/PostServiceImpl.java | 8 ++++++++ src/main/resources/mapper/PostMapper.xml | 8 ++++++++ .../snsserver/service/PostServiceTest.java | 17 +++++++++++++++++ 6 files changed, 47 insertions(+) diff --git a/src/main/java/me/liiot/snsserver/controller/PostController.java b/src/main/java/me/liiot/snsserver/controller/PostController.java index 405eb5c..738001d 100644 --- a/src/main/java/me/liiot/snsserver/controller/PostController.java +++ b/src/main/java/me/liiot/snsserver/controller/PostController.java @@ -51,6 +51,15 @@ public ResponseEntity> getUserFeed(@RequestParam(value = "userId") St return new ResponseEntity<>(posts, HttpStatus.OK); } + @GetMapping("/my-follows") + @CheckLogin + public ResponseEntity> getPostsOfAllFollows(@CurrentUser User currentUser) { + + List posts = postService.getPostsOfAllFollows(currentUser.getUserId()); + + return new ResponseEntity<>(posts, HttpStatus.OK); + } + @PatchMapping("/{postId}") @CheckLogin public ResponseEntity updatePost(@PathVariable int postId, diff --git a/src/main/java/me/liiot/snsserver/mapper/PostMapper.java b/src/main/java/me/liiot/snsserver/mapper/PostMapper.java index 309f615..f6f24be 100644 --- a/src/main/java/me/liiot/snsserver/mapper/PostMapper.java +++ b/src/main/java/me/liiot/snsserver/mapper/PostMapper.java @@ -24,6 +24,9 @@ public interface PostMapper { @ClientDatabase(value = ClientDatabases.SLAVE) List getPostsByUserId(String userId); + @ClientDatabase(value = ClientDatabases.SLAVE) + List getPostsOfAllFollows(String userId); + @ClientDatabase(value = ClientDatabases.SLAVE) boolean isAuthorizedOnPost(@Param("userId") String userId, @Param("postId") int postId); diff --git a/src/main/java/me/liiot/snsserver/service/PostService.java b/src/main/java/me/liiot/snsserver/service/PostService.java index 9ee7099..ff44af3 100644 --- a/src/main/java/me/liiot/snsserver/service/PostService.java +++ b/src/main/java/me/liiot/snsserver/service/PostService.java @@ -15,6 +15,8 @@ public interface PostService { public List getPostsByUser(String userId); + public List getPostsOfAllFollows(String userId); + public void updatePost(User user, int postId, String content) throws AccessException; public void deletePost(User user, int postId) throws AccessException; diff --git a/src/main/java/me/liiot/snsserver/service/PostServiceImpl.java b/src/main/java/me/liiot/snsserver/service/PostServiceImpl.java index d21561b..1714f41 100644 --- a/src/main/java/me/liiot/snsserver/service/PostServiceImpl.java +++ b/src/main/java/me/liiot/snsserver/service/PostServiceImpl.java @@ -77,6 +77,14 @@ public List getPostsByUser(String userId) { return posts; } + @Override + public List getPostsOfAllFollows(String userId) { + + List posts = postMapper.getPostsOfAllFollows(userId); + + return posts; + } + @Override @Caching(evict = {@CacheEvict(cacheNames = CacheNames.POST, key = "#postId"), @CacheEvict(cacheNames = CacheNames.FEED, key = "#user.userId")}) diff --git a/src/main/resources/mapper/PostMapper.xml b/src/main/resources/mapper/PostMapper.xml index 76527fb..a8b3f37 100644 --- a/src/main/resources/mapper/PostMapper.xml +++ b/src/main/resources/mapper/PostMapper.xml @@ -50,6 +50,14 @@ ORDER BY p.createTime DESC + +