implemented transition from old bookmark database (tags.db) to separate database for bookmarks and tags
This commit is contained in:
@@ -105,7 +105,7 @@ public class BookmarkApi extends BaseHandler {
|
||||
|
||||
if (json.has(TAGS) && json.get(TAGS) instanceof JSONArray tagList){
|
||||
var list = tagList.toList().stream().map(Object::toString).toList();
|
||||
tags.save(BOOKMARK,bookmark.id(), userList, list);
|
||||
tags.save(BOOKMARK,bookmark.urlId(), userList, list);
|
||||
}
|
||||
return sendContent(ex,bookmark);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ package de.srsoftware.umbrella.bookmarks;
|
||||
public class Constants {
|
||||
public static final String CONFIG_DATABASE = "umbrella.modules.bookmark.database";
|
||||
public static final String SHARE = "share";
|
||||
public static final String SAVE = "save";
|
||||
public static final String TABLE_TOKENS = "tokens";
|
||||
public static final String TABLE_URLS = "urls";
|
||||
public static final String TABLE_URL_COMMENTS = "url_comments";
|
||||
public static final String URL_ID = "url_id";
|
||||
|
||||
@@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
var rs = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS,ID).where(USER_ID, equal(userId)).exec(db);
|
||||
while (rs.next()){
|
||||
var bookmark = Bookmark.of(rs);
|
||||
map.put(bookmark.id(),bookmark);
|
||||
map.put(bookmark.urlId(),bookmark);
|
||||
}
|
||||
rs.close();;
|
||||
return map;
|
||||
@@ -92,7 +92,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
if (rs.next()) result = Bookmark.of(rs);
|
||||
rs.close();
|
||||
if (result != null) return result;
|
||||
throw UmbrellaException.notFound("No bookmark with id {0}",id);
|
||||
throw UmbrellaException.notFound("No bookmark with urlId {0}",id);
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException("Failed to load bookmark");
|
||||
}
|
||||
@@ -102,20 +102,20 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
public Bookmark save(String url, String comment, Collection<Long> userIds, LocalDateTime timestamp) {
|
||||
try {
|
||||
var rs = select(ID).from(TABLE_URLS).where(URL, equal(url)).exec(db);
|
||||
var id = 0L;
|
||||
if (rs.next()) id = rs.getLong(ID);
|
||||
var urlId = 0L;
|
||||
if (rs.next()) urlId = rs.getLong(ID);
|
||||
rs.close();
|
||||
if (id == 0) {
|
||||
if (urlId == 0) {
|
||||
var stmt = insertInto(TABLE_URLS, URL).values(url).execute(db);
|
||||
rs = stmt.getGeneratedKeys();
|
||||
if (rs.next()) id = rs.getLong(1);
|
||||
if (rs.next()) urlId = rs.getLong(1);
|
||||
rs.close();
|
||||
stmt.close();
|
||||
}
|
||||
var query = replaceInto(TABLE_URL_COMMENTS,URL_ID,USER_ID,COMMENT, TIMESTAMP);
|
||||
for (long userId : userIds) query.values(id,userId,comment,timestamp.toEpochSecond(UTC));
|
||||
for (long userId : userIds) query.values(urlId,userId,comment,timestamp.toEpochSecond(UTC));
|
||||
query.execute(db).close();
|
||||
return Bookmark.of(id,url,comment,timestamp);
|
||||
return Bookmark.of(urlId,url,comment,timestamp);
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException("Failed to store url");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user