refactor naming + user

This commit is contained in:
2021-10-04 16:57:20 +02:00
parent 29cd81b093
commit 59321f4a3d
13 changed files with 218 additions and 125 deletions
@@ -43,7 +43,7 @@ public class BookmarksManager {
* Checks for entry.
*
* @param username the username
* @param entryId the entry id
* @param entryId the entry id
* @return true, if successful
*/
public boolean hasEntry(String username, Long entryId) {
@@ -55,7 +55,7 @@ public class BookmarksManager {
* Adds the entry.
*
* @param username the username
* @param entryId the entry id
* @param entryId the entry id
*/
public void addEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");
@@ -76,7 +76,7 @@ public class BookmarksManager {
* Removes the entry.
*
* @param username the username
* @param entryId the entry id
* @param entryId the entry id
*/
public void removeEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");
@@ -43,12 +43,12 @@ public class CommentManager {
/**
* Fetch by ranking.
*
* @param target the target
* @param parent the parent
* @param date the date
* @param target the target
* @param parent the parent
* @param date the date
* @param gravity the gravity
* @param page the page
* @param size the size
* @param page the page
* @param size the size
* @return the page
*/
@@ -68,23 +68,43 @@ public class CommentManager {
*
* @param target the target
* @param parent the parent
* @param date the date
* @param page the page
* @param size the size
* @param date the date
* @param page the page
* @param size the size
* @param desc the desc
* @return the page
*/
public Page<Comment> fetchByDate(Long target, Long parent, Instant date, int page, int size) {
public Page<Comment> fetchByDate(Long target, Long parent, Instant date, int page, int size,
boolean desc) {
Sort sort = Sort.by(desc ? Order.desc("created") : Order.asc("created"));
if (parent == null) {
return commentRepository.findAll(
qComment.target.eq(target).and(qComment.parent.isNull())
.and(qComment.created.before(date)),
PageRequest.of(page, size, Sort.by(Order.asc("created"))));
return commentRepository
.findAll(
qComment.target.eq(target).and(qComment.parent.isNull())
.and(qComment.created.before(date)),
PageRequest.of(page, size, sort));
}
return commentRepository.findAll(
qComment.target.eq(target).and(qComment.parent.eq(parent))
.and(qComment.created.before(date)),
PageRequest.of(page, size, Sort.by(Order.asc("created"))));
return commentRepository.findAll(qComment.target.eq(target).and(qComment.parent.eq(parent))
.and(qComment.created.before(date)), PageRequest.of(page, size, sort));
}
/**
* Fetch by username.
*
* @param username the username
* @param orElse the or else
* @param date the date
* @param page the page
* @param size the size
* @param asc the asc
* @return the page
*/
public Page<Comment> fetchByUsername(String username, Long orElse, Instant date, int page,
int size, boolean asc) {
Sort sort = Sort.by(asc ? Order.asc("created") : Order.desc("created"));
return commentRepository.findAll(qComment.author.eq(username).and(qComment.parent.isNull())
.and(qComment.created.before(date)), PageRequest.of(page, size, sort));
}
/**
@@ -116,7 +136,7 @@ public class CommentManager {
* Apply metadata.
*
* @param username the username
* @param comment the comment
* @param comment the comment
*/
public void applyMetadata(String username, Comment comment) {
if (!comment.getMetadata().containsKey("comments")) {
@@ -153,7 +173,7 @@ public class CommentManager {
* Apply metadata.
*
* @param username the username
* @param entries the entries
* @param entries the entries
*/
public void applyMetadata(String username, List<Comment> entries) {
for (Comment comment : entries) {
@@ -50,19 +50,16 @@ public class EntryManager {
@Value("${bstly.board.ranking.gravity:1.8}")
private double GRAVITY;
/**
* Direct fetch by ranking.
* Fetch by ranking.
*
* @param date the date
* @param date the date
* @param gravity the gravity
* @param page the page
* @param size the size
* @param page the page
* @param size the size
* @return the page
*/
public Page<RankedEntry> fetchByRanking(Instant date, double gravity, int page,
int size) {
public Page<RankedEntry> fetchByRanking(Instant date, double gravity, int page, int size) {
return entryRepository.findAllByRanking(date, gravity, PageRequest.of(page, size));
}
@@ -80,12 +77,28 @@ public class EntryManager {
}
/**
* Gets the entries.
* Fetch by user.
*
* @param username the username
* @param page the page
* @param size the size
* @return the entries
* @param date the date
* @param page the page
* @param size the size
* @param asc the asc
* @return the page
*/
public Page<Entry> fetchByUser(String username, Instant date, int page, int size, boolean asc) {
Sort sort = Sort.by(asc ? Order.asc("created") : Order.desc("created"));
return entryRepository.findAll(qEntry.author.eq(username).and(qEntry.created.before(date)),
PageRequest.of(page, size, sort));
}
/**
* Fetch by bookmarks.
*
* @param username the username
* @param page the page
* @param size the size
* @return the page
*/
public Page<Entry> fetchByBookmarks(String username, int page, int size) {
Bookmarks bookmarks = bookmarksManager.get(username);
@@ -102,7 +115,7 @@ public class EntryManager {
* Apply metadata.
*
* @param username the username
* @param entry the entry
* @param entry the entry
*/
public void applyMetadata(String username, Entry entry) {
if (!entry.getMetadata().containsKey("comments")) {
@@ -142,7 +155,7 @@ public class EntryManager {
* Apply metadata.
*
* @param username the username
* @param entries the entries
* @param entries the entries
*/
public void applyMetadata(String username, List<Entry> entries) {
for (Entry entry : entries) {
@@ -20,7 +20,7 @@ public class InstantHelper {
* Plus.
*
* @param instant the instant
* @param amount the amount
* @param amount the amount
* @return the instant
*/
public static Instant plus(Instant instant, TemporalAmount amount) {
@@ -30,9 +30,9 @@ public class InstantHelper {
/**
* Plus.
*
* @param instant the instant
* @param instant the instant
* @param amountToAdd the amount to add
* @param unit the unit
* @param unit the unit
* @return the instant
*/
public static Instant plus(Instant instant, long amountToAdd, TemporalUnit unit) {
@@ -43,7 +43,7 @@ public class InstantHelper {
* Minus.
*
* @param instant the instant
* @param amount the amount
* @param amount the amount
* @return the instant
*/
public static Instant minus(Instant instant, TemporalAmount amount) {
@@ -53,9 +53,9 @@ public class InstantHelper {
/**
* Minus.
*
* @param instant the instant
* @param instant the instant
* @param amountToAdd the amount to add
* @param unit the unit
* @param unit the unit
* @return the instant
*/
public static Instant minus(Instant instant, long amountToAdd, TemporalUnit unit) {
@@ -67,7 +67,7 @@ public class InstantHelper {
* Truncate.
*
* @param instant the instant
* @param unit the unit
* @param unit the unit
* @return the instant
*/
public static Instant truncate(Instant instant, TemporalUnit unit) {
@@ -64,6 +64,12 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* @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
* de.bstly.board.businesslogic.LocalUserManager#loadUserByUsername(java.lang.
@@ -91,6 +97,12 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* @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#
@@ -199,7 +211,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")) {
@@ -26,9 +26,9 @@ public class VoteManager {
/**
* Gets the.
*
* @param author the author
* @param author the author
* @param targetType the target type
* @param target the target
* @param target the target
* @return the vote
*/
public Vote get(String author, Types targetType, Long target) {
@@ -58,7 +58,7 @@ public class VoteManager {
/**
* Delete by target.
*
* @param target the target
* @param target the target
* @param targetType the target type
*/
public void deleteByTarget(Long target, Types targetType) {
@@ -71,7 +71,7 @@ public class VoteManager {
/**
* Gets the points.
*
* @param target the target
* @param target the target
* @param targetType the target type
* @return the points
*/