From 1a9f582967d90345101e414e03385e58c86ca87b Mon Sep 17 00:00:00 2001 From: _Bastler Date: Mon, 4 Oct 2021 18:29:04 +0200 Subject: [PATCH] userkarma --- pom.xml | 2 +- .../board/businesslogic/EntryManager.java | 17 +++++++++++++ .../board/businesslogic/UserManager.java | 24 ++++++++++++++----- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 1784432..2acdf7e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ UTF-8 11 - 0.3.2-SNAPSHOT + 0.3.3-SNAPSHOT diff --git a/src/main/java/de/bstly/board/businesslogic/EntryManager.java b/src/main/java/de/bstly/board/businesslogic/EntryManager.java index 07a42ec..44b6a57 100644 --- a/src/main/java/de/bstly/board/businesslogic/EntryManager.java +++ b/src/main/java/de/bstly/board/businesslogic/EntryManager.java @@ -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; + } + } diff --git a/src/main/java/de/bstly/board/businesslogic/UserManager.java b/src/main/java/de/bstly/board/businesslogic/UserManager.java index 8ffabc7..d8cbe0f 100644 --- a/src/main/java/de/bstly/board/businesslogic/UserManager.java +++ b/src/main/java/de/bstly/board/businesslogic/UserManager.java @@ -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); }