disallow future fetching

This commit is contained in:
_Bastler 2021-10-06 22:17:31 +02:00
parent fe47739cb8
commit 50c2776f19
2 changed files with 77 additions and 36 deletions

View File

@ -54,12 +54,12 @@ public class CommentController extends BaseController {
/** /**
* Fetch by date. * Fetch by date.
* *
* @param target the target * @param target the target
* @param parent the parent * @param parent the parent
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param dateParameter the date parameter * @param dateParameter the date parameter
* @param descParameter the desc parameter * @param descParameter the desc parameter
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the page * @return the page
*/ */
@ -72,6 +72,14 @@ public class CommentController extends BaseController {
@RequestParam("date") Optional<Instant> dateParameter, @RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("desc") Optional<Boolean> descParameter, @RequestParam("desc") Optional<Boolean> descParameter,
@RequestParam("ignore") Optional<List<String>> ignoreParameter) { @RequestParam("ignore") Optional<List<String>> ignoreParameter) {
if (sizeParameter.isPresent() && sizeParameter.get() > 100) {
sizeParameter = Optional.of(100);
}
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Comment> comments = commentManager.fetchByDate(getCurrentUsername(), target, Page<Comment> comments = commentManager.fetchByDate(getCurrentUsername(), target,
parent.orElse(null), dateParameter.orElse(Instant.now()), pageParameter.orElse(0), parent.orElse(null), dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false)); sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false));
@ -84,12 +92,12 @@ public class CommentController extends BaseController {
/** /**
* Fetch by username. * Fetch by username.
* *
* @param username the username * @param username the username
* @param parent the parent * @param parent the parent
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param dateParameter the date parameter * @param dateParameter the date parameter
* @param ascParameter the asc parameter * @param ascParameter the asc parameter
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the page * @return the page
*/ */
@ -102,6 +110,15 @@ public class CommentController extends BaseController {
@RequestParam("date") Optional<Instant> dateParameter, @RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("asc") Optional<Boolean> ascParameter, @RequestParam("asc") Optional<Boolean> ascParameter,
@RequestParam("ignore") Optional<List<String>> ignoreParameter) { @RequestParam("ignore") Optional<List<String>> ignoreParameter) {
if (sizeParameter.isPresent() && sizeParameter.get() > 100) {
sizeParameter = Optional.of(100);
}
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Comment> comments = commentManager.fetchByUsername(username, parent.orElse(null), Page<Comment> comments = commentManager.fetchByUsername(username, parent.orElse(null),
dateParameter.orElse(Instant.now()), pageParameter.orElse(0), dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false));
@ -127,7 +144,7 @@ public class CommentController extends BaseController {
/** /**
* Gets the comment. * Gets the comment.
* *
* @param id the id * @param id the id
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the comment * @return the comment
*/ */
@ -149,7 +166,7 @@ public class CommentController extends BaseController {
/** /**
* Creates the comment. * Creates the comment.
* *
* @param comment the comment * @param comment the comment
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the comment * @return the comment
*/ */
@ -186,7 +203,7 @@ public class CommentController extends BaseController {
/** /**
* Update comment. * Update comment.
* *
* @param comment the comment * @param comment the comment
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the comment * @return the comment
*/ */

View File

@ -63,11 +63,11 @@ public class EntryController extends BaseController {
/** /**
* Fetch by ranking. * Fetch by ranking.
* *
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param dateParameter the date parameter * @param dateParameter the date parameter
* @param gravityParameter the gravity parameter * @param gravityParameter the gravity parameter
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the page * @return the page
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@ -82,6 +82,14 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
if (gravityParameter.isPresent() && gravityParameter.get() > 2) {
gravityParameter = Optional.of(2.0);
}
Page<RankedEntry> entries = entryManager.fetchByRanking(dateParameter.orElse(Instant.now()), Page<RankedEntry> entries = entryManager.fetchByRanking(dateParameter.orElse(Instant.now()),
gravityParameter.orElse(getGravity()), pageParameter.orElse(0), gravityParameter.orElse(getGravity()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize())); sizeParameter.orElse(settingsManager.getPageSize()));
@ -102,9 +110,9 @@ public class EntryController extends BaseController {
/** /**
* Fetch by date. * Fetch by date.
* *
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param dateParameter the date parameter * @param dateParameter the date parameter
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the page * @return the page
*/ */
@ -119,6 +127,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Entry> entries = entryManager.fetchByDate(dateParameter.orElse(Instant.now()), Page<Entry> entries = entryManager.fetchByDate(dateParameter.orElse(Instant.now()),
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())); pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()));
List<String> ignore = ignoreParameter.orElse(Lists.newArrayList()); List<String> ignore = ignoreParameter.orElse(Lists.newArrayList());
@ -130,11 +142,11 @@ public class EntryController extends BaseController {
/** /**
* Fetch by comments. * Fetch by comments.
* *
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param dateParameter the date parameter * @param dateParameter the date parameter
* @param gravityParameter the gravity parameter * @param gravityParameter the gravity parameter
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the page * @return the page
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@ -149,6 +161,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<RankedEntry> entries = entryManager.fetchByComments( Page<RankedEntry> entries = entryManager.fetchByComments(
dateParameter.orElse(Instant.now()), gravityParameter.orElse(getGravity()), dateParameter.orElse(Instant.now()), gravityParameter.orElse(getGravity()),
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())); pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()));
@ -167,9 +183,9 @@ public class EntryController extends BaseController {
/** /**
* Fetch by last. * Fetch by last.
* *
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param dateParameter the date parameter * @param dateParameter the date parameter
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the page * @return the page
*/ */
@ -184,6 +200,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Entry> entries = entryManager.fetchByLastComment(dateParameter.orElse(Instant.now()), Page<Entry> entries = entryManager.fetchByLastComment(dateParameter.orElse(Instant.now()),
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())); pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()));
@ -196,11 +216,11 @@ public class EntryController extends BaseController {
/** /**
* Fetch by user. * Fetch by user.
* *
* @param username the username * @param username the username
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
* @param dateParameter the date parameter * @param dateParameter the date parameter
* @param ascParameter the asc parameter * @param ascParameter the asc parameter
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the page * @return the page
*/ */
@ -217,6 +237,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Entry> entries = entryManager.fetchByUser(username, Page<Entry> entries = entryManager.fetchByUser(username,
dateParameter.orElse(Instant.now()), pageParameter.orElse(0), dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false));
@ -229,7 +253,7 @@ public class EntryController extends BaseController {
/** /**
* Gets the entry. * Gets the entry.
* *
* @param id the id * @param id the id
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the entry * @return the entry
*/ */
@ -253,7 +277,7 @@ public class EntryController extends BaseController {
/** /**
* Creates the entry. * Creates the entry.
* *
* @param entry the entry * @param entry the entry
* @param ignoreParameter the ignore parameter * @param ignoreParameter the ignore parameter
* @return the entry * @return the entry
*/ */