Skip to content

Commit

Permalink
fixed follow count (#152)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
harsita-keerthi and github-actions[bot] authored Nov 12, 2024
1 parent 95c9e43 commit df0533d
Showing 1 changed file with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,28 @@ public Mono<String> followerHandler(String id, JsonNode inboxNode, String reques

if (requestType.equals("Follow")) {
var follow = new Follow(follower, id);
// find id, grab arraylist, append

// check if the account to follow exists
return accountRepository.findItemByAcct(id)
.switchIfEmpty(Mono.error(new RuntimeException("Error: Account to follow does not exist")))
.then(followRepository.save(follow)).thenReturn("done");
.flatMap(account -> {
// check if the follower's account exists
return accountRepository.findItemByAcct(follower)
.switchIfEmpty(Mono.error(new RuntimeException("Error: Follower account does not exist")))
.flatMap(followerAccount -> {
// save follow
return followRepository.save(follow)
.then(followRepository.countAllByFollowedId(account.id).flatMap(followersCount -> {
// update follower count of the followed account
account.followers_count = followersCount.intValue();
return accountRepository.save(account);
})).then(followRepository.countAllByFollowerId(followerAccount.id)
.flatMap(followingCount -> {
// update following count of the follower account
followerAccount.following_count = followingCount.intValue();
return accountRepository.save(followerAccount);
})).thenReturn("done");
});
});

} else if (requestType.equals("Undo")) {
return accountRepository.findItemByAcct(follower).switchIfEmpty(
Mono.error(new RuntimeException("Error: Follower account does not exist")))
.flatMap(followerAccount -> {
return followRepository.save(follow)
.then(followRepository.countAllByFollowedId(account.id)
.flatMap(followersCount -> {
account.followers_count = followersCount.intValue();
return accountRepository.save(account);
}))
.then(followRepository.countAllByFollowerId(followerAccount.id)
.flatMap(followingCount -> {
followerAccount.following_count =
followingCount.intValue();
return accountRepository.save(followerAccount);
})).thenReturn("done");
});
});
}

return Mono.error(new RuntimeException("Error: Unsupported request type"));
}

Expand Down

0 comments on commit df0533d

Please sign in to comment.