improvemnts:

- ordering of bookmarks
- limitation of bookmarks on index page
- date for bookmarks that did not have a date before the transition
This commit is contained in:
2025-08-06 01:55:59 +02:00
parent 6f1fdc1f95
commit a450ef97b8
6 changed files with 35 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.bookmarks;
import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.bookmarks.Constants.*;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
@@ -85,7 +86,19 @@ public class BookmarkApi extends BaseHandler {
}
private boolean getUserBookmarks(UmbrellaUser user, HttpExchange ex) throws IOException {
var bookmarks = db.list(user.id());
var param = queryParam(ex);
long offset = switch (param.get(OFFSET)){
case String s -> Long.parseLong(s);
case Number n -> n.longValue();
case null, default -> 0;
};
long limit = switch (param.get(LIMIT)){
case String s -> Long.parseLong(s);
case Number n -> n.longValue();
case null, default -> 100;
};
var bookmarks = db.list(user.id(),offset,limit);
return sendContent(ex,mapValues(bookmarks));
}

View File

@@ -8,7 +8,7 @@ import java.util.Collection;
import java.util.Map;
public interface BookmarkDb {
Map<Long, Bookmark> list(long userId);
Map<Long, Bookmark> list(long userId, long offset, long limit);
Bookmark load(long id, long userId);

View File

@@ -69,10 +69,10 @@ CREATE TABLE IF NOT EXISTS {0} (
}
@Override
public Map<Long, Bookmark> list(long userId) {
public Map<Long, Bookmark> list(long userId, long offset, long limit) {
try {
var map = new HashMap<Long,Bookmark>();
var rs = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS,ID).where(USER_ID, equal(userId)).exec(db);
var rs = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS,ID).where(USER_ID, equal(userId)).sort(format("{0} DESC",TIMESTAMP)).skip(offset).limit(limit).exec(db);
while (rs.next()){
var bookmark = Bookmark.of(rs);
map.put(bookmark.urlId(),bookmark);