implemented editing of times

This commit is contained in:
2025-08-27 23:54:48 +02:00
parent e1f32c274b
commit 5abfa96dc2
5 changed files with 124 additions and 10 deletions

View File

@@ -6,20 +6,24 @@ import static de.srsoftware.umbrella.core.Util.*;
import static java.time.ZoneOffset.UTC;
import de.srsoftware.tools.Mappable;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import org.json.JSONObject;
public class Time implements Mappable{
private static final DateTimeFormatter DT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
private final HashSet<Long> taskIds = new HashSet<>();
private LocalDateTime end;
private final LocalDateTime start;
private LocalDateTime start;
private long id;
private final long userId;
private final String description, subject;
private String description;
private String subject;
private State state;
public enum State{
@@ -49,9 +53,8 @@ public class Time implements Mappable{
default -> throw new IllegalArgumentException();
};
}
}
public Time(long id, long userId, String subject, String description, LocalDateTime start, LocalDateTime end, State state, Collection<Long> taskIds){
this.id=id;
this.userId = userId;
@@ -62,6 +65,7 @@ public class Time implements Mappable{
this.state = state;
if (taskIds != null) this.taskIds.addAll(taskIds);
}
public String description(){
return description;
}
@@ -104,6 +108,15 @@ public class Time implements Mappable{
);
}
public Time patch(JSONObject json) {
if (json.has(SUBJECT) && json.get(SUBJECT) instanceof String s) subject = s;
if (json.has(DESCRIPTION) && json.get(DESCRIPTION) instanceof String d) description = d;
if (json.has(START_TIME) && json.get(START_TIME) instanceof String st) start = LocalDateTime.parse(st, DT);
if (json.has(END_TIME) && json.get(END_TIME) instanceof String e) end = LocalDateTime.parse(e,DT);
if (end != null && !start.isBefore(end)) throw UmbrellaException.invalidFieldException(END_TIME,"after start_time");
return this;
}
public void setId(long newValue) {
id = newValue;
}
@@ -117,7 +130,7 @@ public class Time implements Mappable{
}
public State state(){
return state;
return state;
}
public Time stop(LocalDateTime endTime) {