preparing for adding positions to document

This commit is contained in:
2025-07-15 21:58:06 +02:00
parent 148c0f27b5
commit e436f09698
14 changed files with 211 additions and 48 deletions

View File

@@ -13,7 +13,6 @@ import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
public class SqliteDb implements TimeDb {

View File

@@ -4,7 +4,6 @@ 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.List;
public interface TimeDb {
Collection<Time> listTimes(Collection<Long> taskIds) throws UmbrellaException;

View File

@@ -4,9 +4,10 @@ package de.srsoftware.umbrella.time;
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.exceptions.UmbrellaException.forbidden;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
import static de.srsoftware.umbrella.time.Constants.*;
import static java.util.stream.Collectors.toMap;
import static java.util.function.Predicate.not;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.configuration.Configuration;
@@ -16,7 +17,6 @@ import de.srsoftware.umbrella.core.BaseHandler;
import de.srsoftware.umbrella.core.api.*;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.*;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
@@ -66,15 +66,68 @@ public class TimeModule extends BaseHandler implements TimeService {
}
}
/*
{
1 : {
name: Projekt 1
id: 1
times: {
3:{
name: time 3
start: 123456
end: 78901
},
4:{
name: time 4
start: 234567
end: 890123
tasks:{
5:{
name: task5
},
6:{
name: task6
}
}
}
}
},
2: {
name: Projekt 2
id: 2
times: {
7:{
name: time 7
start: 456789
end: 012345
}
}
}
}
*/
private boolean listTimes(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
var json = json(ex);
if (!(json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number cid)) throw missingFieldException(COMPANY_ID);
long companyId = cid.longValue();
if (!companies.membership(companyId,user.id())) throw UmbrellaException.forbidden("You are not a member of compayn {0}",companyId);
var projectMap = projects.listProjects(companyId,false).stream().collect(toMap(Project::id, p -> p));
var taskMap = tasks.listCompanyTasks(companyId).stream().collect(Collectors.toMap(Task::id,t->t));
var taskIds = taskMap.keySet();
var timesList = timeDb.listTimes(taskIds).stream().map();
return sendContent(ex,tree);
var companyId = cid.longValue();
var company = companies.get(companyId);
if (!companies.membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",company.name());
if (!(json.has(PROJECT_ID) && json.get(PROJECT_ID) instanceof Number pid)) throw missingFieldException(PROJECT_ID);
long projectId = pid.longValue();
Map<Long,Task> tasksOfProject = tasks.listProjectTasks(projectId).stream().collect(Collectors.toMap(Task::id,t->t));
List<Map<String, Object>> times = timeDb.listTimes(tasksOfProject.keySet())
.stream().filter(not(Time::isClosed))
.sorted(Comparator.comparing(Time::start))
.map(time -> {
var map = time.toMap();
var timeTasks = time.taskIds().stream().map(tasksOfProject::get).map(Task::toMap).toList();
map.put(TASKS,timeTasks);
return map;
}).toList();
return sendContent(ex,times);
}
}