Skip to content

Commit

Permalink
Removed null if/else and combined error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
shirlsli committed Sep 1, 2023
1 parent 860244f commit 04b54b0
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,15 @@ public Mono<String> getPublicKey(String id, boolean addIfMissing) {
public Mono<String> followerHandler(String id, JsonNode inboxNode, String requestType) {
String follower = inboxNode.get("actor").asText();
if (requestType.equals("Follow")) {
// check id
if (accountRepository.findItemByAcct(id)==null) {
return Mono.error(new RuntimeException("Error: Account to follow doesn't exist."));
}
// find id, grab arraylist, append
else {
return followersRepository.findItemById(id)
.switchIfEmpty(Mono.just(new Followers(id, new ArrayList<>())))
.flatMap(followedUser -> {
followedUser.getFollowers().add(follower);
return followersRepository.save(followedUser).thenReturn("done");
});
}
return accountRepository.findItemByAcct(id)
.switchIfEmpty(Mono.error(new RuntimeException("Error: Account to follow does not exist")))
.then(followersRepository.findItemById(id)
.switchIfEmpty(Mono.just(new Followers(id, new ArrayList<>())))
.flatMap(followedUser -> {
followedUser.getFollowers().add(follower);
return followersRepository.save(followedUser).thenReturn("done");
}));
}
if (requestType.equals("Undo")) {
// find id, grab arraylist, remove
Expand Down

0 comments on commit 04b54b0

Please sign in to comment.