Skip to content

Commit

Permalink
feat: 팔로우 요청 API 구현 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed Feb 7, 2024
1 parent 98a4861 commit 4d23b43
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 @@ -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);
}
}
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 @@ -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;
Expand Down Expand Up @@ -54,4 +55,13 @@ ResponseEntity<FollowingsResponse> getFollowings(@RequestHeader(value = AUTHORIZ
FollowingsResponse response = userService.getFollowings(accessToken);
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();
}
}

0 comments on commit 4d23b43

Please sign in to comment.