From 4d23b43b5a10985fe73c024a3bd4966577c8603d Mon Sep 17 00:00:00 2001 From: kdkdhoho Date: Wed, 7 Feb 2024 11:22:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=8C=94=EB=A1=9C=EC=9A=B0=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20API=20=EA=B5=AC=ED=98=84=20(#66)?= 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 ed5b214f..a548b275 100644 --- a/src/main/java/com/listywave/user/application/service/UserService.java +++ b/src/main/java/com/listywave/user/application/service/UserService.java @@ -89,4 +89,14 @@ public FollowingsResponse getFollowings(String accessToken) { .toList(); 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); + } } diff --git a/src/main/java/com/listywave/user/presentation/UserController.java b/src/main/java/com/listywave/user/presentation/UserController.java index 6b4aaf24..ef61730e 100644 --- a/src/main/java/com/listywave/user/presentation/UserController.java +++ b/src/main/java/com/listywave/user/presentation/UserController.java @@ -12,6 +12,7 @@ import org.springframework.http.ResponseEntity; 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; @@ -54,4 +55,13 @@ ResponseEntity getFollowings(@RequestHeader(value = AUTHORIZ FollowingsResponse response = userService.getFollowings(accessToken); 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(); + } }