working on tak use list
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -4,6 +4,7 @@ package de.srsoftware.umbrella.tags;
|
||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||
import static de.srsoftware.tools.jdbc.Condition.isNull;
|
||||
import static de.srsoftware.tools.jdbc.Query.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
|
||||
import static de.srsoftware.umbrella.core.Constants.USER_ID;
|
||||
@@ -16,9 +17,7 @@ import de.srsoftware.tools.jdbc.Query;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class SqliteDb implements TagDB{
|
||||
private static final int INITIAL_DB_VERSION = 1;
|
||||
@@ -110,6 +109,23 @@ CREATE TABLE IF NOT EXISTS "{0}" (
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<Long>> getUses(String tag, long userId) {
|
||||
try {
|
||||
var rs = select(ALL).from(TABLE_TAGS).where(TAG,equal(tag)).where(USER_ID,equal(userId)).exec(db);
|
||||
var result = new HashMap<String,List<Long>>();
|
||||
while (rs.next()){
|
||||
var module = rs.getString(MODULE);
|
||||
var entityId = rs.getLong(ID);
|
||||
result.computeIfAbsent(module, k -> new ArrayList<>()).add(entityId);
|
||||
}
|
||||
rs.close();
|
||||
return result;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException("Failed to load uses of tag \"{0}\"!",tag);
|
||||
}
|
||||
}
|
||||
|
||||
private void init(){
|
||||
var version = createTables();
|
||||
LOG.log(INFO,"Updated task db to version {0}",version);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
package de.srsoftware.umbrella.tags;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface TagDB {
|
||||
@@ -9,6 +11,8 @@ public interface TagDB {
|
||||
|
||||
void deleteEntity(String module, long entityId);
|
||||
|
||||
Map<String, List<Long>> getUses(String tag, long id);
|
||||
|
||||
Set<String> list(long id, String module, long entityId);
|
||||
|
||||
void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags);
|
||||
|
||||
@@ -68,6 +68,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
var module = path.pop();
|
||||
if (module == null) throw unprocessable("Module missing in path.");
|
||||
var head = path.pop();
|
||||
if (USES.equals(module)) return getTagUses(ex,head,user.get());
|
||||
long entityId = Long.parseLong(head);
|
||||
return sendContent(ex, getTags(module,entityId,user.get()));
|
||||
} catch (NumberFormatException e){
|
||||
@@ -77,6 +78,10 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getTagUses(HttpExchange ex, String tag, UmbrellaUser user) throws IOException {
|
||||
return sendContent(ex,tagDb.getUses(tag,user.id()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
|
||||
Reference in New Issue
Block a user