implemented task search

This commit is contained in:
2025-08-19 09:42:06 +02:00
parent ab3060c2e2
commit 4f481c32ad
6 changed files with 72 additions and 6 deletions

View File

@@ -114,6 +114,30 @@ CREATE TABLE IF NOT EXISTS {0} (
}
}
@Override
public HashMap<Long, Task> find(long userId, List<String> keys, boolean fulltext) {
try {
var tasks = new HashMap<Long,Task>();
var query = select(ALL).from(TABLE_TASKS).leftJoin(ID,TABLE_TASKS_USERS,TASK_ID)
.where(USER_ID,equal(userId));
for (var key : keys) query.where(NAME,like("%"+key+"%"));
if (fulltext) {
for (var key : keys) query.where(DESCRIPTION,like("%"+key+"%"));
}
var rs = query.exec(db);
while (rs.next()){
var task = Task.of(rs);
tasks.put(task.id(),task);
}
rs.close();
return tasks;
} catch (SQLException e){
LOG.log(WARNING,"Failed to load tasks for user (user_id: {0}",userId,e);
throw new UmbrellaException("Failed to load tasks for project id");
}
}
@Override
public Map<Long, Permission> getMembers(Task task) {
try {
@@ -170,7 +194,7 @@ CREATE TABLE IF NOT EXISTS {0} (
}
}
public HashMap<Long, Task> listChildrenOf(Long parentTaskId, UmbrellaUser user, boolean showClosed) {
public HashMap<Long, Task> listChildrenOf(Long parentTaskId, UmbrellaUser user, boolean showClosed) {
try {
var tasks = new HashMap<Long,Task>();
var query = select(ALL).from(TABLE_TASKS).leftJoin(ID,TABLE_TASKS_USERS,TASK_ID)

View File

@@ -15,11 +15,13 @@ public interface TaskDb {
void delete(Task task) throws UmbrellaException;
void dropMember(long projectId, long userId);
HashMap<Long, Task> find(long userId, List<String> keys, boolean fulltext);
Map<Long, Permission> getMembers(Task task);
HashMap<Long, Task> listChildrenOf(Long parentTaskId, UmbrellaUser user, boolean showClosed);
HashMap<Long, Task> listProjectTasks(Long projectId, Long parentTaskId, boolean noIndex) throws UmbrellaException;
HashMap<Long, Task> listRootTasks(Long projectId, UmbrellaUser user, boolean showClosed);
HashMap<Long, Task> listTasks(Collection<Long> projectIds) throws UmbrellaException;
List<Task> listUserTasks(long userId, Long limit, long offset, boolean showClosed);
Task load(long taskId) throws UmbrellaException;

View File

@@ -135,6 +135,7 @@ public class TaskModule extends BaseHandler implements TaskService {
case ADD -> postNewTask(user.get(),ex);
case ESTIMATED_TIMES -> estimatedTimes(user.get(),ex);
case LIST -> postTaskList(user.get(),ex);
case SEARCH -> postSearch(user.get(),ex);
default -> super.doPost(path,ex);
};
} catch (UmbrellaException e){
@@ -346,6 +347,15 @@ public class TaskModule extends BaseHandler implements TaskService {
return sendContent(ex,loadMembers(task));
}
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 tasks = taskDb.find(user.id(),keys,fulltext);
return sendContent(ex,mapValues(tasks));
}
private boolean postTaskList(UmbrellaUser user, HttpExchange ex) throws IOException {
var json = json(ex);
LOG.log(WARNING,"Missing permission check in {0}.postTaskList!",getClass().getSimpleName());