Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follower Autocreate Hotfix #81

Merged
merged 4 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import edu.sjsu.moth.server.db.Followers;
import edu.sjsu.moth.server.db.FollowersRepository;
import edu.sjsu.moth.server.db.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
Expand All @@ -16,6 +17,8 @@
public class InboxController {
@Autowired
FollowersRepository followersRepository;
@Autowired
AccountRepository accountRepository;

//required to map payload from JSON to a Java Object for data access
ObjectMapper mappedLoad;
Expand All @@ -36,12 +39,19 @@ public Mono<String> usersInbox(@PathVariable String id, @RequestBody JsonNode in
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."));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be on the same line as the else. did you reformat the code before your committed?

// find id, grab arraylist, append
return followersRepository.findItemById(id).switchIfEmpty(Mono.just(new Followers(id, new ArrayList<>())))
.flatMap(followedUser -> {
followedUser.getFollowers().add(follower);
return followersRepository.save(followedUser).thenReturn("done");
});
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");
});
}
}
if (requestType.equals("Undo")) {
// find id, grab arraylist, remove
Expand Down
Loading