Skip to content

Commit

Permalink
feat: 팔로우 요청 API 구현 (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed Feb 8, 2024
1 parent 5491a23 commit 8b8e3c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/listywave/user/presentation/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,15 @@ ResponseEntity<FollowingsResponse> getFollowings(@RequestHeader(value = AUTHORIZ
return ResponseEntity.ok(response);
}

@PostMapping("/follow/{userId}")
ResponseEntity<Void> follow(
@PathVariable(value = "userId") Long followingUserId,
@RequestHeader(value = AUTHORIZATION, defaultValue = "") String accessToken
) {
userService.follow(followingUserId, accessToken);
return ResponseEntity.noContent().build();
}

@DeleteMapping("/follow/{userId}")
ResponseEntity<Void> unfollow(
@PathVariable(value = "userId") Long followingUserId,
Expand Down

0 comments on commit 8b8e3c4

Please sign in to comment.