Unverified Commit b902e4cc authored by Féry Mathieu (Mathius)'s avatar Féry Mathieu (Mathius)
Browse files

feat(shortUsers): Add nbFollows property

parent 0dd10ca8
......@@ -17,13 +17,16 @@ public class ShortUser implements WithIdentifier {
public final String description;
@Schema(description = "Number of followers of this user", example = "2")
public final Integer nbFollowers;
@Schema(description = "Number of follows of this user", example = "2")
public final Integer nbFollows;
public ShortUser(String id, String userName, String uri, String description, Integer nbFollowers) {
public ShortUser(String id, String userName, String uri, String description, Integer nbFollowers, Integer nbFollows) {
this.id = id;
this.userName = userName;
this.uri = uri;
this.description = description;
this.nbFollowers = nbFollowers;
this.nbFollows = nbFollows;
}
public String getId() {
......
......@@ -54,6 +54,10 @@ public class DBFollowing extends DBService<Following> {
return getFollowedIdFromId(searchIdWith(reader, new Following(following, null), followingValue).data);
}
public Set<String> searchFollowedIdWithFollowed(User followed, DatastoreReader reader) {
return getFollowedIdFromId(searchIdWith(reader, new Following(null, followed), followedValue).data);
}
public Set<String> searchFollowedIdWithFollowing(User following) {
return getFollowedIdFromId(searchIdWith(new Following(following, null), followingValue).data);
}
......@@ -62,6 +66,14 @@ public class DBFollowing extends DBService<Following> {
return searchFollowedIdWithFollowing(makeUser(followingId));
}
public Set<String> searchFollowedIdWithFollowed(User followed) {
return getFollowedIdFromId(searchIdWith(new Following(null, followed), followedValue).data);
}
public Set<String> searchFollowedIdWithFollowed(String followedId) {
return searchFollowedIdWithFollowed(makeUser(followedId));
}
public Set<String> searchFollowingIdWithFollowed(User followed) {
return getFollowingIdFromId(searchIdWith(new Following(null, followed), followedValue).data);
}
......
......@@ -45,7 +45,7 @@ public class DBShortUser extends DBService<ShortUser> {
public WithCursor<List<ShortUser>> searchWithUserNameStartsWith(Integer limit, Cursor lastCursor, OrderBy[] orders,
String userName) {
return searchWith(limit, lastCursor, orders, new ShortUser(null, userName, null, null, null),
return searchWith(limit, lastCursor, orders, new ShortUser(null, userName, null, null, null, null),
shortUserNameStartsWith);
}
}
......@@ -39,7 +39,8 @@ public class ShortUserUtils extends BaseUtils<ShortUser> {
try {
String userName = entity.getString("userName");
int followers = followingDB.searchFollowingIdWithFollowed(entity.getKey().getName()).size();
return new ShortUser(entity.getKey().getName(), userName, uri, description, followers);
int follows = followingDB.searchFollowedIdWithFollowed(entity.getKey().getName()).size();
return new ShortUser(entity.getKey().getName(), userName, uri, description, followers, follows);
} catch (DatastoreException ignored) {
throw new RuntimeException(
String.format("Integrity error of user %s (userName missing)", entity.getKey().getName()));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment