From 8b8e3c4b029c817950915f9709dec4d2aca523e2 Mon Sep 17 00:00:00 2001 From: kdkdhoho Date: Thu, 8 Feb 2024 11:40:30 +0900 Subject: [PATCH] =?UTF-8?q?=20feat:=20=ED=8C=94=EB=A1=9C=EC=9A=B0=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20API=20=EA=B5=AC=ED=98=84=20(#79)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/application/service/UserService.java | 10 ++++++++++ .../listywave/user/presentation/UserController.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/com/listywave/user/application/service/UserService.java b/src/main/java/com/listywave/user/application/service/UserService.java index 3aa309b9..8085e671 100644 --- a/src/main/java/com/listywave/user/application/service/UserService.java +++ b/src/main/java/com/listywave/user/application/service/UserService.java @@ -85,6 +85,16 @@ public FollowingsResponse getFollowings(String accessToken) { return FollowingsResponse.of(followingUsers); } + public void follow(Long followingUserId, String accessToken) { + User followingUser = userRepository.getById(followingUserId); + + Long followerUserId = jwtManager.read(accessToken); + User followerUser = userRepository.getById(followerUserId); + + Follow follow = new Follow(followingUser, followerUser); + followRepository.save(follow); + } + public void unfollow(Long followingUserId, String accessToken) { User followingUser = userRepository.getById(followingUserId); diff --git a/src/main/java/com/listywave/user/presentation/UserController.java b/src/main/java/com/listywave/user/presentation/UserController.java index 860960c2..5f3d3890 100644 --- a/src/main/java/com/listywave/user/presentation/UserController.java +++ b/src/main/java/com/listywave/user/presentation/UserController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -56,6 +57,15 @@ ResponseEntity getFollowings(@RequestHeader(value = AUTHORIZ return ResponseEntity.ok(response); } + @PostMapping("/follow/{userId}") + ResponseEntity follow( + @PathVariable(value = "userId") Long followingUserId, + @RequestHeader(value = AUTHORIZATION, defaultValue = "") String accessToken + ) { + userService.follow(followingUserId, accessToken); + return ResponseEntity.noContent().build(); + } + @DeleteMapping("/follow/{userId}") ResponseEntity unfollow( @PathVariable(value = "userId") Long followingUserId,