workin on search based on tags

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-11-10 23:37:40 +01:00
parent 320a0cde1e
commit 88d2dce9e7
2 changed files with 60 additions and 8 deletions
@@ -4,6 +4,7 @@ package de.srsoftware.umbrella.tags;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
import static de.srsoftware.umbrella.core.constants.Field.KEY;
import static de.srsoftware.umbrella.core.constants.Field.USER_LIST;
import static de.srsoftware.umbrella.core.constants.Path.SEARCH;
import static de.srsoftware.umbrella.core.constants.Path.USES;
@@ -94,7 +95,18 @@ public class TagModule extends BaseHandler implements TagService {
var user = userService().loadUser(token);
if (user.isEmpty()) return unauthorized(ex);
var module = path.pop();
if (module == null) throw unprocessable("Module missing in path.");
return switch (module) {
case null -> throw unprocessable("Module missing in path.");
case SEARCH -> postSearch(ex, path, user.get());
default -> postTag(ex, module, path);
};
} catch (UmbrellaException e) {
return send(ex, e);
}
}
private boolean postTag(HttpExchange ex, String module, Path path) throws IOException {
try {
var head = path.pop();
long entityId = Long.parseLong(head);
var json = json(ex);
@@ -102,7 +114,7 @@ public class TagModule extends BaseHandler implements TagService {
List<Long> userList = null;
if (!json.has(USER_LIST)) throw missingField(USER_LIST);
var ul = json.isNull(USER_LIST) ? null : json.get(USER_LIST);
if (ul instanceof JSONArray arr){
if (ul instanceof JSONArray arr) {
userList = arr.toList().stream()
.filter(elem -> elem instanceof Number)
.map(Number.class::cast)
@@ -115,8 +127,6 @@ public class TagModule extends BaseHandler implements TagService {
return sendContent(ex, tag);
} catch (NumberFormatException e) {
return sendContent(ex, HTTP_UNPROCESSABLE, "Entity id missing in path.");
} catch (UmbrellaException e) {
return send(ex, e);
}
}
@@ -149,6 +159,13 @@ public class TagModule extends BaseHandler implements TagService {
return entry;
}
private boolean postSearch(HttpExchange ex, Path path, UmbrellaUser user) throws IOException {
var json = json(ex);
if (!json.has(KEY)) throw missingField(KEY);
var key = json.getString(KEY);
return getTagUses(ex,key,user);
}
@Override
public void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags) {
tagDb.save(userIds,module,entityId,tags.stream().map(String::trim).toList());