refactor naming + user

This commit is contained in:
_Bastler 2021-10-04 16:57:20 +02:00
parent 29cd81b093
commit 59321f4a3d
13 changed files with 218 additions and 125 deletions

View File

@ -43,7 +43,7 @@ public class BookmarksManager {
* Checks for entry. * Checks for entry.
* *
* @param username the username * @param username the username
* @param entryId the entry id * @param entryId the entry id
* @return true, if successful * @return true, if successful
*/ */
public boolean hasEntry(String username, Long entryId) { public boolean hasEntry(String username, Long entryId) {
@ -55,7 +55,7 @@ public class BookmarksManager {
* Adds the entry. * Adds the entry.
* *
* @param username the username * @param username the username
* @param entryId the entry id * @param entryId the entry id
*/ */
public void addEntry(String username, Long entryId) { public void addEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid"); Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");
@ -76,7 +76,7 @@ public class BookmarksManager {
* Removes the entry. * Removes the entry.
* *
* @param username the username * @param username the username
* @param entryId the entry id * @param entryId the entry id
*/ */
public void removeEntry(String username, Long entryId) { public void removeEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid"); Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");

View File

@ -43,12 +43,12 @@ public class CommentManager {
/** /**
* Fetch by ranking. * Fetch by ranking.
* *
* @param target the target * @param target the target
* @param parent the parent * @param parent the parent
* @param date the date * @param date the date
* @param gravity the gravity * @param gravity the gravity
* @param page the page * @param page the page
* @param size the size * @param size the size
* @return the page * @return the page
*/ */
@ -68,23 +68,43 @@ public class CommentManager {
* *
* @param target the target * @param target the target
* @param parent the parent * @param parent the parent
* @param date the date * @param date the date
* @param page the page * @param page the page
* @param size the size * @param size the size
* @param desc the desc
* @return the page * @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) { if (parent == null) {
return commentRepository.findAll( return commentRepository
qComment.target.eq(target).and(qComment.parent.isNull()) .findAll(
.and(qComment.created.before(date)), qComment.target.eq(target).and(qComment.parent.isNull())
PageRequest.of(page, size, Sort.by(Order.asc("created")))); .and(qComment.created.before(date)),
PageRequest.of(page, size, sort));
} }
return commentRepository.findAll( return commentRepository.findAll(qComment.target.eq(target).and(qComment.parent.eq(parent))
qComment.target.eq(target).and(qComment.parent.eq(parent)) .and(qComment.created.before(date)), PageRequest.of(page, size, sort));
.and(qComment.created.before(date)), }
PageRequest.of(page, size, Sort.by(Order.asc("created"))));
/**
* 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. * Apply metadata.
* *
* @param username the username * @param username the username
* @param comment the comment * @param comment the comment
*/ */
public void applyMetadata(String username, Comment comment) { public void applyMetadata(String username, Comment comment) {
if (!comment.getMetadata().containsKey("comments")) { if (!comment.getMetadata().containsKey("comments")) {
@ -153,7 +173,7 @@ public class CommentManager {
* Apply metadata. * Apply metadata.
* *
* @param username the username * @param username the username
* @param entries the entries * @param entries the entries
*/ */
public void applyMetadata(String username, List<Comment> entries) { public void applyMetadata(String username, List<Comment> entries) {
for (Comment comment : entries) { for (Comment comment : entries) {

View File

@ -50,19 +50,16 @@ public class EntryManager {
@Value("${bstly.board.ranking.gravity:1.8}") @Value("${bstly.board.ranking.gravity:1.8}")
private double GRAVITY; private double GRAVITY;
/** /**
* Direct fetch by ranking. * Fetch by ranking.
* *
* @param date the date * @param date the date
* @param gravity the gravity * @param gravity the gravity
* @param page the page * @param page the page
* @param size the size * @param size the size
* @return the page * @return the page
*/ */
public Page<RankedEntry> fetchByRanking(Instant date, double gravity, int page, public Page<RankedEntry> fetchByRanking(Instant date, double gravity, int page, int size) {
int size) {
return entryRepository.findAllByRanking(date, gravity, PageRequest.of(page, 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 username the username
* @param page the page * @param date the date
* @param size the size * @param page the page
* @return the entries * @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) { public Page<Entry> fetchByBookmarks(String username, int page, int size) {
Bookmarks bookmarks = bookmarksManager.get(username); Bookmarks bookmarks = bookmarksManager.get(username);
@ -102,7 +115,7 @@ public class EntryManager {
* Apply metadata. * Apply metadata.
* *
* @param username the username * @param username the username
* @param entry the entry * @param entry the entry
*/ */
public void applyMetadata(String username, Entry entry) { public void applyMetadata(String username, Entry entry) {
if (!entry.getMetadata().containsKey("comments")) { if (!entry.getMetadata().containsKey("comments")) {
@ -142,7 +155,7 @@ public class EntryManager {
* Apply metadata. * Apply metadata.
* *
* @param username the username * @param username the username
* @param entries the entries * @param entries the entries
*/ */
public void applyMetadata(String username, List<Entry> entries) { public void applyMetadata(String username, List<Entry> entries) {
for (Entry entry : entries) { for (Entry entry : entries) {

View File

@ -20,7 +20,7 @@ public class InstantHelper {
* Plus. * Plus.
* *
* @param instant the instant * @param instant the instant
* @param amount the amount * @param amount the amount
* @return the instant * @return the instant
*/ */
public static Instant plus(Instant instant, TemporalAmount amount) { public static Instant plus(Instant instant, TemporalAmount amount) {
@ -30,9 +30,9 @@ public class InstantHelper {
/** /**
* Plus. * Plus.
* *
* @param instant the instant * @param instant the instant
* @param amountToAdd the amount to add * @param amountToAdd the amount to add
* @param unit the unit * @param unit the unit
* @return the instant * @return the instant
*/ */
public static Instant plus(Instant instant, long amountToAdd, TemporalUnit unit) { public static Instant plus(Instant instant, long amountToAdd, TemporalUnit unit) {
@ -43,7 +43,7 @@ public class InstantHelper {
* Minus. * Minus.
* *
* @param instant the instant * @param instant the instant
* @param amount the amount * @param amount the amount
* @return the instant * @return the instant
*/ */
public static Instant minus(Instant instant, TemporalAmount amount) { public static Instant minus(Instant instant, TemporalAmount amount) {
@ -53,9 +53,9 @@ public class InstantHelper {
/** /**
* Minus. * Minus.
* *
* @param instant the instant * @param instant the instant
* @param amountToAdd the amount to add * @param amountToAdd the amount to add
* @param unit the unit * @param unit the unit
* @return the instant * @return the instant
*/ */
public static Instant minus(Instant instant, long amountToAdd, TemporalUnit unit) { public static Instant minus(Instant instant, long amountToAdd, TemporalUnit unit) {
@ -67,7 +67,7 @@ public class InstantHelper {
* Truncate. * Truncate.
* *
* @param instant the instant * @param instant the instant
* @param unit the unit * @param unit the unit
* @return the instant * @return the instant
*/ */
public static Instant truncate(Instant instant, TemporalUnit unit) { public static Instant truncate(Instant instant, TemporalUnit unit) {

View File

@ -64,6 +64,12 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* @see org.springframework.security.core.userdetails.UserDetailsService# * @see org.springframework.security.core.userdetails.UserDetailsService#
* 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 * @see
* de.bstly.board.businesslogic.LocalUserManager#loadUserByUsername(java.lang. * de.bstly.board.businesslogic.LocalUserManager#loadUserByUsername(java.lang.
@ -91,6 +97,12 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* @see org.springframework.beans.factory.SmartInitializingSingleton# * @see org.springframework.beans.factory.SmartInitializingSingleton#
* afterSingletonsInstantiated() * afterSingletonsInstantiated()
*/ */
/*
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
*/
/*
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
*/
/* /*
* *
* @see org.springframework.beans.factory.SmartInitializingSingleton# * @see org.springframework.beans.factory.SmartInitializingSingleton#
@ -199,7 +211,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* Apply metadata. * Apply metadata.
* *
* @param username the username * @param username the username
* @param user the user * @param user the user
*/ */
public void applyMetadata(String username, LocalUser user) { public void applyMetadata(String username, LocalUser user) {
if (user.getUsername().equals(username) && !user.getMetadata().containsKey("self")) { if (user.getUsername().equals(username) && !user.getMetadata().containsKey("self")) {

View File

@ -26,9 +26,9 @@ public class VoteManager {
/** /**
* Gets the. * Gets the.
* *
* @param author the author * @param author the author
* @param targetType the target type * @param targetType the target type
* @param target the target * @param target the target
* @return the vote * @return the vote
*/ */
public Vote get(String author, Types targetType, Long target) { public Vote get(String author, Types targetType, Long target) {
@ -58,7 +58,7 @@ public class VoteManager {
/** /**
* Delete by target. * Delete by target.
* *
* @param target the target * @param target the target
* @param targetType the target type * @param targetType the target type
*/ */
public void deleteByTarget(Long target, Types targetType) { public void deleteByTarget(Long target, Types targetType) {
@ -71,7 +71,7 @@ public class VoteManager {
/** /**
* Gets the points. * Gets the points.
* *
* @param target the target * @param target the target
* @param targetType the target type * @param targetType the target type
* @return the points * @return the points
*/ */

View File

@ -27,7 +27,7 @@ import de.bstly.board.model.Entry;
* The Class BookmarksController. * The Class BookmarksController.
*/ */
@RestController @RestController
@RequestMapping("/b") @RequestMapping("/bookmarks")
public class BookmarksController extends BaseController { public class BookmarksController extends BaseController {
@Autowired @Autowired

View File

@ -29,36 +29,30 @@ import de.bstly.board.model.Types;
import de.bstly.board.model.Vote; import de.bstly.board.model.Vote;
import de.bstly.board.model.VoteType; import de.bstly.board.model.VoteType;
/** /**
* The Class CommentController. * The Class CommentController.
*/ */
@RestController @RestController
@RequestMapping("/c") @RequestMapping("/comments")
public class CommentController extends BaseController { public class CommentController extends BaseController {
@Autowired @Autowired
private CommentManager commentManager; private CommentManager commentManager;
@Autowired @Autowired
private CommentValidator commentValidator; private CommentValidator commentValidator;
@Autowired @Autowired
private VoteManager voteManager; private VoteManager voteManager;
@Value("${bstly.board.size:30}") @Value("${bstly.board.size:30}")
private int SIZE; private int SIZE;
@Value("${bstly.board.ranking.gravity:1.8}") @Value("${bstly.board.ranking.gravity:1.8}")
private double GRAVITY; private double GRAVITY;
/** /**
* Ranked comments. * Fetch by rank.
* *
* @param target the target * @param target the target
* @param parent the parent * @param parent the parent
@ -69,23 +63,70 @@ public class CommentController extends BaseController {
* @return the page * @return the page
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping({ "/e/{target}", "/e/{target}/{parent}" }) @GetMapping({ "/{target}", "/{target}/{parent}" })
public Page<Comment> rankedComments(@PathVariable("target") Long target, public Page<Comment> fetchByRank(@PathVariable("target") Long target,
@PathVariable("parent") Optional<Long> parent, @PathVariable("parent") Optional<Long> parent,
@RequestParam("page") Optional<Integer> pageParameter, @RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("size") Optional<Integer> sizeParameter,
@RequestParam("date") Optional<Instant> dateParameter, @RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("gravity") Optional<Double> gravityParameter) { @RequestParam("gravity") Optional<Double> gravityParameter) {
Page<Comment> comments = newComments(target, parent, pageParameter, sizeParameter, Page<Comment> comments = fetchByDate(target, parent, pageParameter, sizeParameter,
dateParameter); dateParameter, Optional.of(false));
commentManager.applyMetadata(getCurrentUsername(), comments.getContent()); commentManager.applyMetadata(getCurrentUsername(), comments.getContent());
return comments; return comments;
}
// Page<Comment> comments = commentManager.fetchByRanking(target, parent.orElse(null), /**
// dateParameter.orElse(Instant.now()), gravityParameter.orElse(GRAVITY), * Fetch by date.
// pageParameter.orElse(0), sizeParameter.orElse(SIZE)); *
// return comments; * @param target the target
* @param parent the parent
* @param pageParameter the page parameter
* @param sizeParameter the size parameter
* @param dateParameter the date parameter
* @param descParameter the desc parameter
* @return the page
*/
@PreAuthorize("isAuthenticated()")
@GetMapping({ "/new/{target}", "/new/{target}/{parent}" })
public Page<Comment> fetchByDate(@PathVariable("target") Long target,
@PathVariable("parent") Optional<Long> parent,
@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter,
@RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("desc") Optional<Boolean> descParameter) {
Page<Comment> comments = commentManager.fetchByDate(target, parent.orElse(null),
dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(SIZE), descParameter.orElse(false));
commentManager.applyMetadata(getCurrentUsername(), comments.getContent());
return comments;
}
/**
* Fetch by username.
*
* @param username the username
* @param parent the parent
* @param pageParameter the page parameter
* @param sizeParameter the size parameter
* @param dateParameter the date parameter
* @param ascParameter the asc parameter
* @return the page
*/
@PreAuthorize("isAuthenticated()")
@GetMapping({ "/byuser/{username}" })
public Page<Comment> fetchByUsername(@PathVariable("username") String username,
@PathVariable("parent") Optional<Long> parent,
@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter,
@RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("asc") Optional<Boolean> ascParameter) {
Page<Comment> comments = commentManager.fetchByUsername(username, parent.orElse(null),
dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(SIZE), ascParameter.orElse(false));
commentManager.applyMetadata(getCurrentUsername(), comments.getContent());
return comments;
} }
/** /**
@ -96,36 +137,12 @@ public class CommentController extends BaseController {
* @return the long * @return the long
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping({ "/c/{target}", "/c/{target}/{parent}" }) @GetMapping({ "/count/{target}", "/count/{target}/{parent}" })
public Long countComments(@PathVariable("target") Long target, public Long countComments(@PathVariable("target") Long target,
@PathVariable("parent") Optional<Long> parent) { @PathVariable("parent") Optional<Long> parent) {
return commentManager.count(target, parent.orElse(null)); return commentManager.count(target, parent.orElse(null));
} }
/**
* New comments.
*
* @param target the target
* @param parent the parent
* @param pageParameter the page parameter
* @param sizeParameter the size parameter
* @param dateParameter the date parameter
* @return the page
*/
@PreAuthorize("isAuthenticated()")
@GetMapping({ "/e/new/{target}", "/e/new/{target}/{parent}" })
public Page<Comment> newComments(@PathVariable("target") Long target,
@PathVariable("parent") Optional<Long> parent,
@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter,
@RequestParam("date") Optional<Instant> dateParameter) {
Page<Comment> comments = commentManager.fetchByDate(target, parent.orElse(null),
dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(SIZE));
commentManager.applyMetadata(getCurrentUsername(), comments.getContent());
return comments;
}
/** /**
* Gets the comment. * Gets the comment.
* *
@ -133,7 +150,7 @@ public class CommentController extends BaseController {
* @return the comment * @return the comment
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping("/{id}") @GetMapping("/comment/{id}")
public Comment getComment(@PathVariable("id") Long id) { public Comment getComment(@PathVariable("id") Long id) {
Comment comment = commentManager.get(id); Comment comment = commentManager.get(id);
@ -153,7 +170,7 @@ public class CommentController extends BaseController {
* @return the comment * @return the comment
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@PostMapping() @PostMapping
public Comment createComment(@RequestBody Comment comment) { public Comment createComment(@RequestBody Comment comment) {
RequestBodyErrors bindingResult = new RequestBodyErrors(comment); RequestBodyErrors bindingResult = new RequestBodyErrors(comment);
commentValidator.validate(comment, bindingResult); commentValidator.validate(comment, bindingResult);

View File

@ -37,7 +37,7 @@ import de.bstly.board.model.VoteType;
* The Class EntryController. * The Class EntryController.
*/ */
@RestController @RestController
@RequestMapping("/e") @RequestMapping("/entries")
public class EntryController extends BaseController { public class EntryController extends BaseController {
@Autowired @Autowired
@ -56,17 +56,17 @@ public class EntryController extends BaseController {
private double GRAVITY; private double GRAVITY;
/** /**
* Ranked entries. * 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
* @return the page * @return the page
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping() @GetMapping()
public Page<Entry> rankedEntries(@RequestParam("page") Optional<Integer> pageParameter, public Page<Entry> fetchByRanking(@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("size") Optional<Integer> sizeParameter,
@RequestParam("date") Optional<Instant> dateParameter, @RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("gravity") Optional<Double> gravityParameter) { @RequestParam("gravity") Optional<Double> gravityParameter) {
@ -89,7 +89,7 @@ public class EntryController extends BaseController {
} }
/** /**
* New entries. * Fetch by date.
* *
* @param pageParameter the page parameter * @param pageParameter the page parameter
* @param sizeParameter the size parameter * @param sizeParameter the size parameter
@ -98,7 +98,7 @@ public class EntryController extends BaseController {
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping("/new") @GetMapping("/new")
public Page<Entry> newEntries(@RequestParam("page") Optional<Integer> pageParameter, public Page<Entry> fetchByDate(@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("size") Optional<Integer> sizeParameter,
@RequestParam("date") Optional<Instant> dateParameter) { @RequestParam("date") Optional<Instant> dateParameter) {
@ -112,6 +112,35 @@ public class EntryController extends BaseController {
return entries; return entries;
} }
/**
* Fetch by user.
*
* @param username the username
* @param pageParameter the page parameter
* @param sizeParameter the size parameter
* @param dateParameter the date parameter
* @param ascParameter the asc parameter
* @return the page
*/
@PreAuthorize("isAuthenticated()")
@GetMapping("/byuser/{username}")
public Page<Entry> fetchByUser(@PathVariable("username") String username,
@RequestParam("page") Optional<Integer> pageParameter,
@RequestParam("size") Optional<Integer> sizeParameter,
@RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("asc") Optional<Boolean> ascParameter) {
if (sizeParameter.isPresent() && sizeParameter.get() > 100) {
sizeParameter = Optional.of(100);
}
Page<Entry> entries = entryManager.fetchByUser(username,
dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(SIZE), ascParameter.orElse(false));
entryManager.applyMetadata(getCurrentUsername(), entries.getContent());
return entries;
}
/** /**
* Gets the entry. * Gets the entry.
* *
@ -119,7 +148,7 @@ public class EntryController extends BaseController {
* @return the entry * @return the entry
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping("/{id}") @GetMapping("/entry/{id}")
public Entry getEntry(@PathVariable("id") Long id) { public Entry getEntry(@PathVariable("id") Long id) {
Entry entry = entryManager.get(id); Entry entry = entryManager.get(id);

View File

@ -25,7 +25,7 @@ import de.bstly.board.model.LocalUser;
* The Class ModerationController. * The Class ModerationController.
*/ */
@RestController @RestController
@RequestMapping("/m") @RequestMapping("/moderation")
public class ModerationController { public class ModerationController {
@ -46,7 +46,7 @@ public class ModerationController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_MOD')") @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_MOD')")
@DeleteMapping("/c/{id}") @DeleteMapping("/comment/{id}")
public void deleteComment(@PathVariable("id") Long id) { public void deleteComment(@PathVariable("id") Long id) {
if (!commentManager.exists(id)) { if (!commentManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -61,7 +61,7 @@ public class ModerationController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_MOD')") @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_MOD')")
@DeleteMapping("/e/{id}") @DeleteMapping("/entry/{id}")
public void deleteEntry(@PathVariable("id") Long id) { public void deleteEntry(@PathVariable("id") Long id) {
if (!entryManager.exists(id)) { if (!entryManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -76,7 +76,7 @@ public class ModerationController {
* @param username the username * @param username the username
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@PutMapping("/u/{username}") @PutMapping("/user/{username}")
public void makeMod(@PathVariable("username") String username) { public void makeMod(@PathVariable("username") String username) {
LocalUser user = userManager.getByUsername(username); LocalUser user = userManager.getByUsername(username);
@ -103,7 +103,7 @@ public class ModerationController {
* @param username the username * @param username the username
*/ */
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@DeleteMapping("/u/{username}") @DeleteMapping("/user/{username}")
public void unmakeMode(@PathVariable("username") String username) { public void unmakeMode(@PathVariable("username") String username) {
LocalUser user = userManager.getByUsername(username); LocalUser user = userManager.getByUsername(username);

View File

@ -24,7 +24,7 @@ import de.bstly.board.model.LocalUser;
* The Class UserController. * The Class UserController.
*/ */
@RestController @RestController
@RequestMapping("/u") @RequestMapping("/users")
public class UserController extends BaseController { public class UserController extends BaseController {
@ -38,7 +38,7 @@ public class UserController extends BaseController {
* @return the user * @return the user
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping({ "", "/{username}" }) @GetMapping({ "/user", "/user/{username}" })
public LocalUser getUser(@PathVariable("username") Optional<String> usernameParameter) { public LocalUser getUser(@PathVariable("username") Optional<String> usernameParameter) {
String username = usernameParameter.orElse(getCurrentUsername()); String username = usernameParameter.orElse(getCurrentUsername());
@ -68,7 +68,7 @@ public class UserController extends BaseController {
* @return the local user * @return the local user
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@PostMapping() @PostMapping("/user")
public LocalUser updateUser(@RequestBody LocalUser user) { public LocalUser updateUser(@RequestBody LocalUser user) {
if (!getCurrentUsername().equals(user.getUsername())) { if (!getCurrentUsername().equals(user.getUsername())) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);

View File

@ -26,7 +26,7 @@ import de.bstly.board.model.VoteType;
* The Class VoteController. * The Class VoteController.
*/ */
@RestController @RestController
@RequestMapping("/v") @RequestMapping("/votes")
public class VoteController extends BaseController { public class VoteController extends BaseController {
@ -48,7 +48,7 @@ public class VoteController extends BaseController {
* @return the entry points * @return the entry points
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping("/e/{id}") @GetMapping("/entry/{id}")
public long getEntryPoints(@PathVariable("id") Long id) { public long getEntryPoints(@PathVariable("id") Long id) {
if (!entryManager.exists(id)) { if (!entryManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -63,7 +63,7 @@ public class VoteController extends BaseController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@PutMapping("/e/{id}/up") @PutMapping("/entry/{id}/up")
public void voteEntryUp(@PathVariable("id") Long id) { public void voteEntryUp(@PathVariable("id") Long id) {
if (!entryManager.exists(id)) { if (!entryManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -89,7 +89,7 @@ public class VoteController extends BaseController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@PutMapping("/e/{id}/down") @PutMapping("/entry/{id}/down")
public void voteEntryDown(@PathVariable("id") Long id) { public void voteEntryDown(@PathVariable("id") Long id) {
if (!entryManager.exists(id)) { if (!entryManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -115,7 +115,7 @@ public class VoteController extends BaseController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@DeleteMapping("/e/{id}") @DeleteMapping("/entry/{id}")
public void unvoteEntry(@PathVariable("id") Long id) { public void unvoteEntry(@PathVariable("id") Long id) {
if (!entryManager.exists(id)) { if (!entryManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -136,7 +136,7 @@ public class VoteController extends BaseController {
* @return the comment points * @return the comment points
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@GetMapping("/c/{id}") @GetMapping("/comment/{id}")
public long getCommentPoints(@PathVariable("id") Long id) { public long getCommentPoints(@PathVariable("id") Long id) {
if (!commentManager.exists(id)) { if (!commentManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -151,7 +151,7 @@ public class VoteController extends BaseController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@PutMapping("/c/{id}/up") @PutMapping("/comment/{id}/up")
public void voteCommentUp(@PathVariable("id") Long id) { public void voteCommentUp(@PathVariable("id") Long id) {
if (!commentManager.exists(id)) { if (!commentManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -177,7 +177,7 @@ public class VoteController extends BaseController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@PutMapping("/c/{id}/down") @PutMapping("/comment/{id}/down")
public void voteCommentDown(@PathVariable("id") Long id) { public void voteCommentDown(@PathVariable("id") Long id) {
if (!commentManager.exists(id)) { if (!commentManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
@ -203,7 +203,7 @@ public class VoteController extends BaseController {
* @param id the id * @param id the id
*/ */
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
@DeleteMapping("/c/{id}") @DeleteMapping("/comment/{id}")
public void unvoteComment(@PathVariable("id") Long id) { public void unvoteComment(@PathVariable("id") Long id) {
if (!commentManager.exists(id)) { if (!commentManager.exists(id)) {
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);

View File

@ -36,14 +36,16 @@ public class Bookmarks {
private List<Long> entries; private List<Long> entries;
/** /**
* @param username * Instantiates a new bookmarks.
*/ */
public Bookmarks() { public Bookmarks() {
super(); super();
} }
/** /**
* @param username * Instantiates a new bookmarks.
*
* @param username the username
*/ */
public Bookmarks(String username) { public Bookmarks(String username) {
super(); super();