From 803a13da241b09d89b9cca696089b39b64297c3c Mon Sep 17 00:00:00 2001 From: harsita <131437586+harsita-keerthi@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:37:11 -0700 Subject: [PATCH 1/2] implemented followers and following lists --- .../moth/server/controller/AccountController.java | 12 +++++++++++- .../edu/sjsu/moth/server/service/AccountService.java | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java b/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java index 51813a2..5dc1b8e 100644 --- a/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java +++ b/server/src/main/java/edu/sjsu/moth/server/controller/AccountController.java @@ -187,7 +187,17 @@ public Mono> userFollowing( @RequestParam(required = false, defaultValue = "0") String since_id, @RequestParam(required = false) String min_id, @RequestParam(required = false, defaultValue = "20") int limit) { - return accountService.usersFollow(id, max_id, since_id, min_id, limit); + return accountService.userFollowInfo(id, max_id, since_id, min_id, limit); + } + + @GetMapping("/api/v1/accounts/{id}/followers") + public Mono> userFollowers( + @PathVariable("id") String id, + @RequestParam(required = false) String max_id, + @RequestParam(required = false, defaultValue = "0") String since_id, + @RequestParam(required = false) String min_id, + @RequestParam(required = false, defaultValue = "20") int limit) { + return accountService.userFollowingInfo(id, max_id, since_id, min_id, limit); } @GetMapping("/api/v1/follow_requests") diff --git a/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java b/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java index 4a9605f..b3e51d1 100644 --- a/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java +++ b/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java @@ -100,13 +100,20 @@ public Mono followerHandler(String id, JsonNode inboxNode, String reques return Mono.empty(); } - public Mono> usersFollow(String id, String max_id, String since_id, String min_id, + public Mono> userFollowInfo(String id, String max_id, String since_id, String min_id, Integer limit) { return followRepository.findAllByFollowerId(id) .flatMap(follow -> accountRepository.findById(follow.id.followed_id)) .collect(ArrayList::new, ArrayList::add); } + public Mono> userFollowingInfo(String id, String max_id, String since_id, String min_id, + Integer limit) { + return followRepository.findAllByFollowedId(id) + .flatMap(follow -> accountRepository.findById(follow.id.follower_id)) + .collect(ArrayList::new, ArrayList::add); + } + public Mono usersFollow(String id, Integer page, Integer limit, String followType) { var items = followType.equals("following") ? From 2cd1ab80d64fc40d46444efb3ea53605c1000d87 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 1 Oct 2024 22:45:54 +0000 Subject: [PATCH 2/2] Auto-format code --- .../java/edu/sjsu/moth/server/service/AccountService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java b/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java index b3e51d1..96a835d 100644 --- a/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java +++ b/server/src/main/java/edu/sjsu/moth/server/service/AccountService.java @@ -101,14 +101,14 @@ public Mono followerHandler(String id, JsonNode inboxNode, String reques } public Mono> userFollowInfo(String id, String max_id, String since_id, String min_id, - Integer limit) { + Integer limit) { return followRepository.findAllByFollowerId(id) .flatMap(follow -> accountRepository.findById(follow.id.followed_id)) .collect(ArrayList::new, ArrayList::add); } public Mono> userFollowingInfo(String id, String max_id, String since_id, String min_id, - Integer limit) { + Integer limit) { return followRepository.findAllByFollowedId(id) .flatMap(follow -> accountRepository.findById(follow.id.follower_id)) .collect(ArrayList::new, ArrayList::add);