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

feat(users): Add some description on data

parent 8f9f70c4
Pipeline #34310 passed with stages
in 6 minutes and 15 seconds
......@@ -13,13 +13,16 @@ public class ShortUser implements WithIdentifier {
public final String userName;
@Schema(description = "Uri of image related to this User", example = "foo.org/someImage.png")
public final String uri;
@Schema(description = "Description of User", example = "Some Description here")
public final String description;
@Schema(description = "Number of followers of this user")
public final Integer nbFollowers;
public ShortUser(String id, String userName, String uri, Integer nbFollowers) {
public ShortUser(String id, String userName, String uri, String description, Integer nbFollowers) {
this.id = id;
this.userName = userName;
this.uri = uri;
this.description = description;
this.nbFollowers = nbFollowers;
}
......
......@@ -16,6 +16,8 @@ public class User implements WithIdentifier {
private String email;
@Schema(description = "Uri of image related to this User", example = "foo.org/someImage.png")
private String uri;
@Schema(description = "Description of User", example = "Some Description here")
private String description;
@Schema(description = "List of follows of this user")
private List<User> follows;
@Schema(description = "List of followers of this user")
......@@ -23,23 +25,24 @@ public class User implements WithIdentifier {
@Schema(description = "List of liked posts of this user")
private List<Post> likedPosts;
public User(String id, String userName, String email, String uri, List<Post> likedPosts, List<User> follows,
List<User> followers) {
public User(String id, String userName, String email, String uri, String description, List<Post> likedPosts,
List<User> follows, List<User> followers) {
this.id = id;
this.userName = userName;
this.email = email;
this.uri = uri;
this.description = description;
this.likedPosts = likedPosts;
this.follows = follows;
this.followers = followers;
}
public User(String id, String userName, String email, String uri) {
this(id, userName, email, uri, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
public User(String id, String userName, String email, String uri, String description) {
this(id, userName, email, uri, description, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
}
public User(UserPayload payload) {
this(payload.id, payload.userName, payload.email, payload.uri);
this(payload.id, payload.userName, payload.email, payload.uri, payload.description);
}
public User updateFromPayload(UserPayload payload) {
......@@ -49,6 +52,8 @@ public class User implements WithIdentifier {
userName = payload.userName;
if (payload.uri != null)
uri = payload.uri;
if (payload.description != null)
description = payload.description;
return this;
}
......@@ -73,6 +78,10 @@ public class User implements WithIdentifier {
return this.email;
}
public String getDescription() {
return this.description;
}
public List<User> getFollows() {
return follows;
}
......
......@@ -19,13 +19,17 @@ public class UserPayload {
public final String email;
@Schema(description = "Uri of image related to this User", example = "foo.org/someImage.png")
public final String uri;
@Schema(description = "Description of User", example = "Some Description here")
public final String description;
@JsonCreator
public UserPayload(@NonNull @JsonProperty("id") String id, @NonNull @JsonProperty("userName") String userName,
@NonNull @JsonProperty("email") String email, @Nullable @JsonProperty("uri") String uri) {
@NonNull @JsonProperty("email") String email, @Nullable @JsonProperty("uri") String uri,
@Nullable @JsonProperty("description") String description) {
this.id = id;
this.userName = userName;
this.email = email;
this.uri = uri;
this.description = description;
}
}
......@@ -25,7 +25,7 @@ public class DBFollowing extends DBService<Following> {
private FollowedValue followedValue;
private User makeUser(String id) {
return new User(id, null, null, null, null, null, null);
return new User(id, null, null, null, null, null, null, null);
}
protected Set<String> getFollowedIdFromId(Set<String> ids) {
......
......@@ -26,7 +26,7 @@ public class DBLike extends DBService<Like> {
private PostRelatedValue postRelatedValue;
private User makeUser(String id) {
return new User(id, null, null, null, null, null, null);
return new User(id, null, null, null, null, null, null, null);
}
private Post makePost(String id) {
......
......@@ -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),
return searchWith(limit, lastCursor, orders, new ShortUser(null, userName, null, null, null),
shortUserNameStartsWith);
}
}
......@@ -23,7 +23,7 @@ public class DBUser extends DBService<User> {
private UserNameStartsWith userNameStartsWith;
public User searchFirstWithEmail(String email) {
return searchFirstWith(new User(null, null, email, null, null, null, null), emailValue).data;
return searchFirstWith(new User(null, null, email, null, null, null, null, null), emailValue).data;
}
public WithCursor<List<User>> searchWithUserNameStartsWith(String userName) {
......@@ -56,7 +56,7 @@ public class DBUser extends DBService<User> {
public WithCursor<List<User>> searchWithUserNameStartsWith(Integer limit, Cursor lastCursor, OrderBy[] orders,
String userName) {
return searchWith(limit, lastCursor, orders, new User(null, userName, null, null, null, null, null),
return searchWith(limit, lastCursor, orders, new User(null, userName, null, null, null, null, null, null),
userNameStartsWith);
}
}
......@@ -84,6 +84,6 @@ public class OAuthUserDataService {
firstName = nameSplit[0];
}
}
return new User(null, nickName, email, null);
return new User(null, nickName, email, null, null);
}
}
......@@ -50,9 +50,9 @@ public class FollowingUtils extends BaseUtils<Following> {
@Override
public Following createFromEntityWithoutLinks(Entity entity) {
try {
User followed = new User(entity.getString("followed"), null, null, null);
User followed = new User(entity.getString("followed"), null, null, null, null);
try {
User following = new User(entity.getString("following"), null, null, null);
User following = new User(entity.getString("following"), null, null, null, null);
return new Following(following, followed);
} catch (DatastoreException ignored) {
throw new RuntimeException(String.format("Integrity error of useroauth %s (following missing)",
......
......@@ -54,7 +54,7 @@ public class LikeUtils extends BaseUtils<Like> {
@Override
public Like createFromEntityWithoutLinks(Entity entity) {
try {
User userRelated = new User(entity.getString("userRelated"), null, null, null);
User userRelated = new User(entity.getString("userRelated"), null, null, null, null);
try {
Post postRelated = new Post(entity.getString("postRelated"), null, null, null, null, null, null);
return new Like(userRelated, postRelated);
......
......@@ -68,7 +68,7 @@ public class OAuthStateUtils extends BaseUtils<OAuthState> {
public OAuthState createFromEntityWithoutLinks(Entity entity) {
User userRelated = null;
try {
userRelated = new User(entity.getString("userRelated"), null, null, null);
userRelated = new User(entity.getString("userRelated"), null, null, null, null);
} catch (DatastoreException ignored) {
// Exception ignored because User may be null (But deletion of user isn't
// managed)
......
......@@ -30,10 +30,16 @@ public class ShortUserUtils extends BaseUtils<ShortUser> {
} catch (DatastoreException ignored) {
// Uri missing, is optional, exception is ignored
}
String description = null;
try {
description = entity.getString("description");
} catch (DatastoreException ignored) {
// Description missing, is optional, exception is ignored
}
try {
String userName = entity.getString("userName");
int followers = followingDB.searchFollowingIdWithFollowed(entity.getKey().getName()).size();
return new ShortUser(entity.getKey().getName(), userName, uri, followers);
return new ShortUser(entity.getKey().getName(), userName, uri, description, followers);
} catch (DatastoreException ignored) {
throw new RuntimeException(
String.format("Integrity error of user %s (userName missing)", entity.getKey().getName()));
......
......@@ -48,6 +48,12 @@ public class UserUtils extends BaseUtils<User> {
} catch (DatastoreException ignored) {
// Uri missing, is optional, exception is ignored
}
String description = null;
try {
description = entity.getString("description");
} catch (DatastoreException ignored) {
// Description missing, is optional, exception is ignored
}
try {
String userName = entity.getString("userName");
try {
......@@ -76,7 +82,8 @@ public class UserUtils extends BaseUtils<User> {
// follower may be disappear if deleted
}
}
return new User(entity.getKey().getName(), userName, email, uri, likedPosts, follows, followers);
return new User(entity.getKey().getName(), userName, email, uri, description, likedPosts, follows,
followers);
} catch (DatastoreException ignored) {
throw new RuntimeException(
String.format("Integrity error of user %s (email missing)", entity.getKey().getName()));
......@@ -92,6 +99,8 @@ public class UserUtils extends BaseUtils<User> {
builder.set("userName", instance.getUserName());
if (instance.getUri() != null)
builder.set("uri", instance.getUri());
if (instance.getDescription() != null)
builder.set("description", instance.getDescription());
builder.set("email", instance.getEmail());
if (instance.getFollows() != null)
updateFollows(instance);
......@@ -137,11 +146,17 @@ public class UserUtils extends BaseUtils<User> {
} catch (DatastoreException ignored) {
// Uri missing, is optional, exception is ignored
}
String description = null;
try {
description = entity.getString("description");
} catch (DatastoreException ignored) {
// Description missing, is optional, exception is ignored
}
try {
String userName = entity.getString("userName");
try {
String email = entity.getString("email");
return new User(entity.getKey().getName(), userName, email, uri, null, null, null);
return new User(entity.getKey().getName(), userName, email, uri, description, null, null, null);
} catch (DatastoreException ignored) {
throw new RuntimeException(
String.format("Integrity error of user %s (email 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