Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mathieu Féry
M1Alma WebAndCloud Server
Commits
75c290a4
Unverified
Commit
75c290a4
authored
Dec 09, 2021
by
Féry Mathieu (Mathius)
Browse files
feat(users): Add nbPosts property
parent
8e1abe01
Pipeline
#34498
passed with stages
in 8 minutes and 8 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/univnantes/webandcloud/api/core/ShortUser.java
View file @
75c290a4
...
...
@@ -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
()
{
...
...
src/main/java/fr/univnantes/webandcloud/api/core/User.java
View file @
75c290a4
...
...
@@ -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
;
}
}
src/main/java/fr/univnantes/webandcloud/api/services/db/DBShortUser.java
View file @
75c290a4
...
...
@@ -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
);
}
}
src/main/java/fr/univnantes/webandcloud/api/services/utils/ShortUserUtils.java
View file @
75c290a4
...
...
@@ -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
()));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment