implemented tagging of bookmarks
This commit is contained in:
@@ -3,8 +3,7 @@ package de.srsoftware.umbrella.bookmarks;
|
||||
|
||||
import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.Constants.COMMENT;
|
||||
import static de.srsoftware.umbrella.core.Constants.URL;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Paths.LIST;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
@@ -15,21 +14,27 @@ import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.api.TagService;
|
||||
import de.srsoftware.umbrella.core.api.UserService;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BookmarkApi extends BaseHandler {
|
||||
private final BookmarkDb db;
|
||||
private final UserService users;
|
||||
private final TagService tags;
|
||||
|
||||
public BookmarkApi(Configuration config, UserService userService) {
|
||||
public BookmarkApi(Configuration config, TagService tagService) {
|
||||
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||
db = new SqliteDb(connect(dbFile));
|
||||
users = userService;
|
||||
tags = tagService;
|
||||
users = tagService.userService();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,6 +85,10 @@ public class BookmarkApi extends BaseHandler {
|
||||
if (!(json.has(URL) && json.get(URL) instanceof String url)) throw missingFieldException(URL);
|
||||
if (!(json.has(COMMENT) && json.get(COMMENT) instanceof String comment)) throw missingFieldException(COMMENT);
|
||||
var bookmark = db.save(url,comment, user.id());
|
||||
if (json.has(TAGS) && json.get(TAGS) instanceof JSONArray tagList){
|
||||
var list = tagList.toList().stream().map(Object::toString).toList();
|
||||
tags.save(BOOKMARK,bookmark.id(), List.of(user.id()),list);
|
||||
}
|
||||
return sendContent(ex,bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user