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

feat(users): Add nbPosts property

parent 8e1abe01
Pipeline #34498 passed with stages
in 8 minutes and 8 seconds
......@@ -19,14 +19,18 @@ public class ShortUser implements WithIdentifier {
public final Integer nbFollowers;
@Schema(description = "Number of follows of this user", example = "2")
public final Integer nbFollows;
@Schema(description = "Number of posts of this user", example = "2")
public final Integer nbPosts;
public ShortUser(String id, String userName, String uri, String description, Integer nbFollowers, Integer nbFollows) {
public ShortUser(String id, String userName, String uri, String description, Integer nbFollowers, Integer nbFollows,
Integer nbPosts) {
this.id = id;
this.userName = userName;
this.uri = uri;
this.description = description;
this.nbFollowers = nbFollowers;
this.nbFollows = nbFollows;
this.nbPosts = nbPosts;
}
public String getId() {
......
......@@ -109,4 +109,9 @@ public class User implements WithIdentifier {
public Integer getNbFollows() {
return getFollows() != null ? getFollows().size() : null;
}
@Schema(description = "Number of posts of this user", example = "2")
public Integer getNbPosts() {
return getPosts() != null ? getPosts().size() : null;
}
}
......@@ -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, null),
return searchWith(limit, lastCursor, orders, new ShortUser(null, userName, null, null, null, null, null),
shortUserNameStartsWith);
}
}
......@@ -8,7 +8,10 @@ import org.apache.commons.lang3.NotImplementedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import fr.univnantes.webandcloud.api.core.Post;
import fr.univnantes.webandcloud.api.core.ShortUser;
import fr.univnantes.webandcloud.api.core.User;
import fr.univnantes.webandcloud.api.services.DBAncestorService;
import fr.univnantes.webandcloud.api.services.db.DBFollowing;
@Service
......@@ -16,6 +19,8 @@ public class ShortUserUtils extends BaseUtils<ShortUser> {
@Autowired
private DBFollowing followingDB;
@Autowired
private DBAncestorService<Post, User> postDB;
@Override
public String getLocalKindValue() {
......@@ -40,7 +45,9 @@ public class ShortUserUtils extends BaseUtils<ShortUser> {
String userName = entity.getString("userName");
int followers = followingDB.searchFollowingIdWithFollowed(entity.getKey().getName()).size();
int follows = followingDB.searchFollowedIdWithFollowed(entity.getKey().getName()).size();
return new ShortUser(entity.getKey().getName(), userName, uri, description, followers, follows);
int posts = postDB.retrieveKeysRelativeOfAncestor(
new User(entity.getKey().getName(), null, null, null, null, null, null, null, null)).size();
return new ShortUser(entity.getKey().getName(), userName, uri, description, followers, follows, posts);
} 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