working on bookmark editing
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -7,15 +7,24 @@ import static de.srsoftware.tools.jdbc.Query.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Errors.*;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.tagService;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.BOOKMARK;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;
|
||||
import static de.srsoftware.umbrella.messagebus.events.Event.EventType.CREATE;
|
||||
import static de.srsoftware.umbrella.messagebus.events.Event.EventType.UPDATE;
|
||||
import static java.text.MessageFormat.format;
|
||||
import static java.time.ZoneOffset.UTC;
|
||||
|
||||
import de.srsoftware.umbrella.core.BaseDb;
|
||||
import de.srsoftware.umbrella.core.constants.Module;
|
||||
import de.srsoftware.umbrella.core.model.Bookmark;
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.messagebus.events.BookmarkEvent;
|
||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -117,16 +126,29 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bookmark load(long id, long userId) {
|
||||
public Bookmark load(long urlId, long userId) {
|
||||
try {
|
||||
Bookmark result = null;
|
||||
var rs = select(ALL).from(TABLE_URLS).leftJoin(ID,TABLE_URL_COMMENTS,URL_ID).where(ID,equal(id)).where(USER_ID,equal(userId)).exec(db);
|
||||
var rs = select(ALL).from(TABLE_URLS).leftJoin(ID,TABLE_URL_COMMENTS,URL_ID).where(ID,equal(urlId)).where(USER_ID,equal(userId)).exec(db);
|
||||
if (rs.next()) result = Bookmark.of(rs);
|
||||
rs.close();
|
||||
if (result != null) return result;
|
||||
throw failedToLoadObject(Translatable.t(BOOKMARK),id);
|
||||
throw failedToLoadObject(Translatable.t(BOOKMARK),urlId);
|
||||
} catch (SQLException e) {
|
||||
throw failedToLoadObject(Translatable.t(BOOKMARK),id).causedBy(e);
|
||||
throw failedToLoadObject(Translatable.t(BOOKMARK),urlId).causedBy(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(UmbrellaUser user, Bookmark bookmark) {
|
||||
try {
|
||||
var urlId = bookmark.urlId();
|
||||
var userId = user.id();
|
||||
delete().from(TABLE_URL_COMMENTS).where(USER_ID, equal(userId)).where(URL_ID, equal(urlId)).execute(db);
|
||||
messageBus().dispatch(new BookmarkEvent(user,bookmark, Event.EventType.DELETE));
|
||||
tagService().deleteEntity(Module.BOOKMARK,urlId,userId);
|
||||
} catch (SQLException e){
|
||||
throw failedToDropObject(BOOKMARK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user