working on time list

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-08-18 01:23:29 +02:00
parent cedb798af8
commit 8bb44d0d7f
9 changed files with 52 additions and 15 deletions

View File

@@ -1,10 +1,12 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.time;
import static de.srsoftware.tools.jdbc.Condition.equal;
import static de.srsoftware.tools.jdbc.Condition.in;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
import static de.srsoftware.tools.jdbc.Query.select;
import static de.srsoftware.umbrella.core.Constants.ID;
import static de.srsoftware.umbrella.core.Constants.USER_ID;
import static de.srsoftware.umbrella.time.Constants.*;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
@@ -24,7 +26,7 @@ public class SqliteDb implements TimeDb {
}
@Override
public Collection<Time> listTimes(Collection<Long> taskIds) throws UmbrellaException {
public HashMap<Long,Time> listTimes(Collection<Long> taskIds) throws UmbrellaException {
try {
var rs = select(ALL).from(TABLE_TASK_TIMES).where(TASK_ID,in(taskIds.toArray())).exec(db);
var mapFromTimesToTasks = new HashMap<Long,HashSet<Long>>();
@@ -35,11 +37,34 @@ public class SqliteDb implements TimeDb {
}
rs.close();
rs = select(ALL).from(TABLE_TIMES).where(ID,in(mapFromTimesToTasks.keySet().toArray())).exec(db);
var times = new HashSet<Time>();
var times = new HashMap<Long,Time>();
while (rs.next()) {
var time = Time.of(rs);
time.taskIds().addAll(mapFromTimesToTasks.get(time.id()));
times.add(time);
times.put(time.id(),time);
}
rs.close();
return times;
} catch (SQLException e) {
throw new UmbrellaException("Failed to load times for task list");
}
}
@Override
public HashMap<Long, Time> listUserTimes(long userId) {
try {
var rs = select(ALL).from(TABLE_TIMES).where(USER_ID,equal(userId)).exec(db);
var times = new HashMap<Long,Time>();
while (rs.next()) {
var time = Time.of(rs);
times.put(time.id(),time);
}
rs.close();
rs = select(ALL).from(TABLE_TASK_TIMES).where(TIME_ID,in(times.keySet().toArray())).exec(db);
while (rs.next()){
var time = times.get(rs.getLong(TIME_ID));
time.taskIds().add(rs.getLong(TASK_ID));
System.out.println(time);
}
rs.close();
return times;

View File

@@ -4,7 +4,10 @@ package de.srsoftware.umbrella.time;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Time;
import java.util.Collection;
import java.util.HashMap;
public interface TimeDb {
Collection<Time> listTimes(Collection<Long> taskIds) throws UmbrellaException;
HashMap<Long,Time> listTimes(Collection<Long> taskIds) throws UmbrellaException;
HashMap<Long,Time> listUserTimes(long userId);
}

View File

@@ -5,6 +5,7 @@ import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Paths.LIST;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_NOT_IMPLEMENTED;
import static de.srsoftware.umbrella.core.Util.mapValues;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.forbidden;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
import static de.srsoftware.umbrella.time.Constants.*;
@@ -82,9 +83,12 @@ public class TimeModule extends BaseHandler implements TimeService {
private boolean getUserTimes(UmbrellaUser user, HttpExchange ex) throws IOException {
// TODO
var taskIds = new HashSet<Long>();
Map<Long, Project> projects = projectService().listUserProjects(user.id(), true);
//timeDb.
return sendEmptyResponse(HTTP_NOT_IMPLEMENTED,ex);
for (var pid : projects.keySet()) taskIds.addAll(taskService().listProjectTasks(pid).keySet());
var times = timeDb.listTimes(taskIds);
times.putAll(timeDb.listUserTimes(user.id()));
return sendContent(ex,mapValues(times));
}
/*
@@ -138,9 +142,11 @@ public class TimeModule extends BaseHandler implements TimeService {
Map<Long,Task> tasksOfProject = taskService().listProjectTasks(projectId);
List<Map<String, Object>> times = timeDb.listTimes(tasksOfProject.keySet())
.stream().filter(not(Time::isClosed))
.sorted(Comparator.comparing(Time::start))
.map(time -> {
.entrySet().stream()
.filter(entry -> !entry.getValue().isClosed())
.sorted(Comparator.comparing(entry ->entry.getValue().start()))
.map(entry -> {
var time = entry.getValue();
var map = time.toMap();
var timeTasks = time.taskIds().stream().map(tasksOfProject::get).map(Task::toMap).toList();
map.put(TASKS,timeTasks);