userkarma

This commit is contained in:
_Bastler 2021-10-04 18:29:04 +02:00
parent 8b0fab7488
commit 1a9f582967
3 changed files with 36 additions and 7 deletions

View File

@ -10,7 +10,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version> <java.version>11</java.version>
<revision>0.3.2-SNAPSHOT</revision> <revision>0.3.3-SNAPSHOT</revision>
</properties> </properties>
<parent> <parent>

View File

@ -218,4 +218,21 @@ public class EntryManager {
return upvotes - downvotes; 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;
}
} }

View File

@ -65,10 +65,16 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* loadUserByUsername(java.lang.String) * 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 * @see
@ -98,10 +104,16 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* afterSingletonsInstantiated() * 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()
*/ */
/* /*
* *
@ -221,7 +233,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
if (!user.getMetadata().containsKey("points")) { if (!user.getMetadata().containsKey("points")) {
long points = 0; long points = 0;
for (Entry entry : entryRepository.findAll(qEntry.author.eq(username))) { 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); user.getMetadata().put("points", points);
} }