implemented bookmark search
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -5,6 +5,7 @@ import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
|||||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
import static de.srsoftware.umbrella.core.Paths.LIST;
|
import static de.srsoftware.umbrella.core.Paths.LIST;
|
||||||
|
import static de.srsoftware.umbrella.core.Paths.SEARCH;
|
||||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||||
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
||||||
@@ -21,6 +22,7 @@ import de.srsoftware.umbrella.core.model.Token;
|
|||||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
|
||||||
@@ -71,6 +73,7 @@ public class BookmarkApi extends BaseHandler implements BookmarkService {
|
|||||||
if (user.isEmpty()) return unauthorized(ex);
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
var head = path.pop();
|
var head = path.pop();
|
||||||
return switch (head) {
|
return switch (head) {
|
||||||
|
case SEARCH -> postSearch(user.get(),ex);
|
||||||
case null -> postBookmark(user.get(),ex);
|
case null -> postBookmark(user.get(),ex);
|
||||||
default -> super.doPost(path,ex);
|
default -> super.doPost(path,ex);
|
||||||
};
|
};
|
||||||
@@ -118,4 +121,13 @@ public class BookmarkApi extends BaseHandler implements BookmarkService {
|
|||||||
}
|
}
|
||||||
return sendContent(ex,bookmark);
|
return sendContent(ex,bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean postSearch(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
|
var json = json(ex);
|
||||||
|
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingFieldException(KEY);
|
||||||
|
var keys = Arrays.asList(key.split(" "));
|
||||||
|
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val;
|
||||||
|
var bookmarks = db.find(user.id(),keys);
|
||||||
|
return sendContent(ex,mapValues(bookmarks));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface BookmarkDb {
|
public interface BookmarkDb {
|
||||||
Map<Long, Bookmark> list(long userId, long offset, long limit);
|
Map<Long, Bookmark> find(long userId, Collection<String> key);
|
||||||
|
|
||||||
|
Map<Long, Bookmark> list(long userId, Long offset, Long limit);
|
||||||
|
|
||||||
Bookmark load(long id, long userId);
|
Bookmark load(long id, long userId);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.srsoftware.umbrella.bookmarks;
|
|||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
public static final String CONFIG_DATABASE = "umbrella.modules.bookmark.database";
|
public static final String CONFIG_DATABASE = "umbrella.modules.bookmark.database";
|
||||||
|
public static final String FULLTEXT = "fulltext";
|
||||||
public static final String SHARE = "share";
|
public static final String SHARE = "share";
|
||||||
public static final String TABLE_TOKENS = "tokens";
|
public static final String TABLE_TOKENS = "tokens";
|
||||||
public static final String TABLE_URLS = "urls";
|
public static final String TABLE_URLS = "urls";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package de.srsoftware.umbrella.bookmarks;
|
package de.srsoftware.umbrella.bookmarks;
|
||||||
|
|
||||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||||
|
import static de.srsoftware.tools.jdbc.Condition.like;
|
||||||
import static de.srsoftware.tools.jdbc.Query.*;
|
import static de.srsoftware.tools.jdbc.Query.*;
|
||||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||||
import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
||||||
@@ -69,7 +70,26 @@ CREATE TABLE IF NOT EXISTS {0} (
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Long, Bookmark> list(long userId, long offset, long limit) {
|
public Map<Long, Bookmark> find(long userId, Collection<String> keys) {
|
||||||
|
try {
|
||||||
|
var map = new HashMap<Long,Bookmark>();
|
||||||
|
var query = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS,ID)
|
||||||
|
.where(USER_ID, equal(userId));
|
||||||
|
for (var key : keys) query.where(COMMENT,like("%"+key+"%"));
|
||||||
|
var rs = query.sort(format("{0} DESC",TIMESTAMP)).exec(db);
|
||||||
|
while (rs.next()){
|
||||||
|
var bookmark = Bookmark.of(rs);
|
||||||
|
map.put(bookmark.urlId(),bookmark);
|
||||||
|
}
|
||||||
|
rs.close();;
|
||||||
|
return map;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new UmbrellaException("Failed to load bookmark list");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Long, Bookmark> list(long userId, Long offset, Long limit) {
|
||||||
try {
|
try {
|
||||||
var map = new HashMap<Long,Bookmark>();
|
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)).sort(format("{0} DESC",TIMESTAMP)).skip(offset).limit(limit).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);
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
import { api } from '../../urls.svelte.js';
|
import { api } from '../../urls.svelte.js';
|
||||||
import { t } from '../../translations.svelte.js';
|
import { t } from '../../translations.svelte.js';
|
||||||
|
|
||||||
|
import Bookmark from '../bookmark/Template.svelte';
|
||||||
|
|
||||||
const router = useTinyRouter();
|
const router = useTinyRouter();
|
||||||
console.log(router);
|
console.log(router);
|
||||||
|
let bookmarks = $state(null);
|
||||||
let fulltext = false;
|
let fulltext = false;
|
||||||
let key = $state(router.getQueryParam('key'));
|
let key = $state(router.getQueryParam('key'));
|
||||||
let input = $state(router.getQueryParam('key'));
|
let input = $state(router.getQueryParam('key'));
|
||||||
@@ -37,6 +40,8 @@
|
|||||||
|
|
||||||
async function handleBookmarks(resp){
|
async function handleBookmarks(resp){
|
||||||
if (resp.ok){
|
if (resp.ok){
|
||||||
|
bookmarks = await resp.json();
|
||||||
|
console.log(bookmarks);
|
||||||
} else {
|
} else {
|
||||||
error = await resp.text();
|
error = await resp.text();
|
||||||
}
|
}
|
||||||
@@ -63,11 +68,17 @@
|
|||||||
<button type="submit">{t('go')}</button>
|
<button type="submit">{t('go')}</button>
|
||||||
</form>
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{#if key}
|
{#if bookmarks}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>
|
<legend>
|
||||||
{t('results')}
|
{t('bookmarks')}
|
||||||
</legend>
|
</legend>
|
||||||
{key}
|
<ul>
|
||||||
|
{#each Object.values(bookmarks) as bookmark}
|
||||||
|
<li>
|
||||||
|
<a href={bookmark.url} target="_blank">{@html bookmark.comment.rendered}</a>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -286,3 +286,7 @@ legend{
|
|||||||
nav > form{
|
nav > form{
|
||||||
display:inline;
|
display:inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li > a > p:nth-child(1){
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user