caseinsensitive usernames
This commit is contained in:
@@ -11,6 +11,7 @@ import com.google.common.collect.Lists;
|
||||
|
||||
import de.bstly.board.model.Bookmarks;
|
||||
import de.bstly.board.model.QBookmarks;
|
||||
import de.bstly.board.model.QLocalUser;
|
||||
import de.bstly.board.repository.BookmarksRepository;
|
||||
import de.bstly.board.repository.EntryRepository;
|
||||
import de.bstly.board.repository.LocalUserRepository;
|
||||
@@ -27,6 +28,7 @@ public class BookmarksManager {
|
||||
private EntryRepository entryRepository;
|
||||
@Autowired
|
||||
private LocalUserRepository localUserRepository;
|
||||
private QLocalUser qLocalUser = QLocalUser.localUser;
|
||||
private QBookmarks qBookmarks = QBookmarks.bookmarks;
|
||||
|
||||
/**
|
||||
@@ -36,30 +38,32 @@ public class BookmarksManager {
|
||||
* @return the bookmarks
|
||||
*/
|
||||
public Bookmarks get(String username) {
|
||||
return bookmarksRepository.findById(username).orElse(new Bookmarks(username));
|
||||
return bookmarksRepository.findOne(qBookmarks.username.equalsIgnoreCase(username))
|
||||
.orElse(new Bookmarks(username));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
return bookmarksRepository
|
||||
.exists(qBookmarks.username.eq(username).and(qBookmarks.entries.contains(entryId)));
|
||||
return bookmarksRepository.exists(qBookmarks.username.equalsIgnoreCase(username)
|
||||
.and(qBookmarks.entries.contains(entryId)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
Assert.isTrue(localUserRepository.existsById(username), "Invalid username");
|
||||
Assert.isTrue(localUserRepository.exists(qLocalUser.username.equalsIgnoreCase(username)),
|
||||
"Invalid username");
|
||||
Bookmarks bookmarks = get(username);
|
||||
|
||||
if (bookmarks.getEntries() == null) {
|
||||
@@ -76,12 +80,13 @@ 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");
|
||||
Assert.isTrue(localUserRepository.existsById(username), "Invalid username");
|
||||
|
||||
Assert.isTrue(localUserRepository.exists(qLocalUser.username.equalsIgnoreCase(username)),
|
||||
"Invalid username");
|
||||
|
||||
Bookmarks bookmarks = get(username);
|
||||
|
||||
if (bookmarks.getEntries() == null) {
|
||||
|
||||
Reference in New Issue
Block a user