userkarma
This commit is contained in:
parent
8b0fab7488
commit
1a9f582967
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>11</java.version>
|
||||
<revision>0.3.2-SNAPSHOT</revision>
|
||||
<revision>0.3.3-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
|
@ -218,4 +218,21 @@ public class EntryManager {
|
||||
return upvotes - downvotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user points.
|
||||
*
|
||||
* @param entryId the entry id
|
||||
* @param username the username
|
||||
* @return the user points
|
||||
*/
|
||||
public long getUserPoints(Long entryId, String username) {
|
||||
long upvotes = voteRepository.count(qVote.targetType.eq(Types.entry)
|
||||
.and(qVote.type.eq(VoteType.up).and(qVote.author.ne(username)))
|
||||
.and(qVote.target.eq(entryId)));
|
||||
long downvotes = voteRepository.count(qVote.targetType.eq(Types.entry)
|
||||
.and(qVote.type.eq(VoteType.down).and(qVote.author.ne(username)))
|
||||
.and(qVote.target.eq(entryId)));
|
||||
return upvotes - downvotes;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,10 +65,16 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
|
||||
* loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#
|
||||
* loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#
|
||||
* loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.security.core.userdetails.UserDetailsService#
|
||||
* loadUserByUsername(java.lang.String)
|
||||
*/
|
||||
/*
|
||||
* @see
|
||||
@ -98,10 +104,16 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
* @see org.springframework.beans.factory.SmartInitializingSingleton#
|
||||
* afterSingletonsInstantiated()
|
||||
*/
|
||||
/*
|
||||
*
|
||||
@ -211,7 +223,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
|
||||
* Apply metadata.
|
||||
*
|
||||
* @param username the username
|
||||
* @param user the user
|
||||
* @param user the user
|
||||
*/
|
||||
public void applyMetadata(String username, LocalUser user) {
|
||||
if (user.getUsername().equals(username) && !user.getMetadata().containsKey("self")) {
|
||||
@ -221,7 +233,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
|
||||
if (!user.getMetadata().containsKey("points")) {
|
||||
long points = 0;
|
||||
for (Entry entry : entryRepository.findAll(qEntry.author.eq(username))) {
|
||||
points += entryManager.getPoints(entry.getId());
|
||||
points += entryManager.getUserPoints(entry.getId(), user.getUsername());
|
||||
}
|
||||
user.getMetadata().put("points", points);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user