Skip to content

Commit

Permalink
adding followkey class for primary key purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishanth Uchil authored and Nishanth Uchil committed May 5, 2024
1 parent f5b8046 commit 35caecf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions server/src/main/java/edu/sjsu/moth/server/db/Follow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
public class Follow {

public static class FollowKey{
public String followerId;
public String followedId;
public String follower_id;
public String followed_id;

public FollowKey(String follower_id, String followed_id){
this.followerId = follower_id;
this.followedId = followed_id;
this.follower_id = follower_id;
this.followed_id = followed_id;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

public interface FollowRepository extends ReactiveMongoRepository<Follow, Follow.FollowKey> {
@Query("{'id.followedId': ?0}")
Mono<List<Follow>> findAllByIdFollowedId(String followed_id);
Mono<List<Follow>> findAllByFollowedId(String followed_id);
@Query("{'id.followerId': ?0}")
Mono<List<Follow>> findAllByIdFollowerId(String follower_id);
Mono<List<Follow>> findAllByFollowerId(String follower_id);
// Mono<Integer> countAllByIdFollowedId(String followed_id);
// Mono<Integer> countAllByIdFollowerId(String follower_id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public Mono<InboxController.UsersFollowResponse> usersFollow(String id,
@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer limit,
String followType) {
var items = followType.equals("following") ? followRepository.findAllByIdFollowerId(id)
.map(list -> list.stream().map(f -> f.id.followedId).toList()) : followRepository.findAllByIdFollowedId(id)
.map(list -> list.stream().map(f -> f.id.followerId).toList());
var items = followType.equals("following") ? followRepository.findAllByFollowerId(id)
.map(list -> list.stream().map(f -> f.id.followed_id).toList()) : followRepository.findAllByFollowedId(id)
.map(list -> list.stream().map(f -> f.id.follower_id).toList());
String returnID = MothController.BASE_URL + "/users/" + id + followType;
int pageSize = limit != null ? limit : DEFAULT_PAGE_SIZE;
if (page == null) {
Expand Down Expand Up @@ -153,8 +153,8 @@ public Mono<Account> updateAccount(Account a) {

public Mono<SearchResult> filterAccountSearch(String query, Principal user, Boolean following, String max_id,
String min_id, Integer limit, Integer offset, SearchResult result) {
return followRepository.findAllByIdFollowerId(((Account) user).id).flatMap(f -> {
var followers = f.stream().map(follow -> follow.id.followedId).collect(Collectors.toSet());
return followRepository.findAllByFollowerId(((Account) user).id).flatMap(f -> {
var followers = f.stream().map(follow -> follow.id.followed_id).collect(Collectors.toSet());
return accountRepository.findByAcctLike(query)
.filter(account -> following == null || !following || followers.contains(account.id))
.take(limit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.sjsu.moth.generated.Status;
import edu.sjsu.moth.server.db.ExternalStatus;
import edu.sjsu.moth.server.db.ExternalStatusRepository;
import edu.sjsu.moth.server.db.Follow;
import edu.sjsu.moth.server.db.FollowRepository;
import edu.sjsu.moth.server.db.StatusRepository;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,6 +19,7 @@

import java.security.Principal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Configuration
Expand Down Expand Up @@ -125,11 +127,11 @@ public Mono<SearchResult> filterStatusSearch(String query, Principal user, Strin
private Flux<Status> filterStatusByViewable(Principal user, Status status, boolean isFollowingTimeline) {
return accountService.getAccount(user.getName())
.switchIfEmpty(Mono.error(new UsernameNotFoundException(user.getName())))
.flatMapMany(acct -> followRepository.findAllByIdFollowerId(acct.id)
.defaultIfEmpty(new Mono.just())
.map(list -> list.stream().map(f -> f.id.followedId).toList())
.flatMapMany(followings -> ((!isFollowingTimeline && status.visibility.equals("public")) || followings.contains(
status.id)) ? Flux.just(status) : Flux.empty()));
.flatMapMany(acct -> followRepository.findAllByFollowerId(acct.id)
.defaultIfEmpty(Collections.emptyList())
.map(list -> list.stream().map(f -> f.id.followed_id).toList())
.flatMapMany(followings -> ((status.account.id.equals(acct.id)) || (!isFollowingTimeline && status.visibility.equals("public")) || followings.contains(
status.account.id)) ? Flux.just(status) : Flux.empty()));
}

}

0 comments on commit 35caecf

Please sign in to comment.