working on calendar application
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -5,5 +5,6 @@ dependencies {
|
||||
|
||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||
implementation("de.srsoftware:tools.util:1.2.1")
|
||||
implementation("de.srsoftware:tools.web:1.3.4")
|
||||
implementation("de.srsoftware:tools.web:1.3.8")
|
||||
implementation("org.json:json:20240303")
|
||||
}
|
||||
|
||||
@@ -8,20 +8,23 @@ import de.srsoftware.cal.api.Attachment;
|
||||
import de.srsoftware.cal.api.Coords;
|
||||
import de.srsoftware.cal.api.Link;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* basic class for Appointments
|
||||
*/
|
||||
public class BaseAppointment implements Appointment {
|
||||
private final long id;
|
||||
private final String title, description;
|
||||
private final LocalDateTime end, start;
|
||||
private final String hash;
|
||||
private Coords coords = null;
|
||||
private final Set<Attachment> attachments = new HashSet<>();
|
||||
private final Set<String> tags = new HashSet<>();
|
||||
private final Set<Link> links = new HashSet<>();
|
||||
private static final DateTimeFormatter DATE_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
private final long id;
|
||||
private final String title, description;
|
||||
private final LocalDateTime end, start;
|
||||
private final String hash;
|
||||
private Coords coords = null;
|
||||
private final Set<Attachment> attachments = new HashSet<>();
|
||||
private final Set<String> tags = new HashSet<>();
|
||||
private final Set<Link> links = new HashSet<>();
|
||||
private final String location;
|
||||
|
||||
/**
|
||||
@@ -83,26 +86,6 @@ public class BaseAppointment implements Appointment {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds tag
|
||||
* @param newTags the tag to add to the appointment
|
||||
* @return the appointment
|
||||
*/
|
||||
public BaseAppointment tags(String... newTags) {
|
||||
Collections.addAll(tags, newTags);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds tag
|
||||
* @param newTags the tag to add to the appointment
|
||||
* @return the appointment
|
||||
*/
|
||||
public BaseAppointment tags(Collection<String> newTags) {
|
||||
tags.addAll(newTags);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the coordinates of the attachments
|
||||
* @param newCoords the coordinates to apply
|
||||
@@ -133,21 +116,42 @@ public class BaseAppointment implements Appointment {
|
||||
return nullable(end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String slug() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
var json = new JSONObject();
|
||||
json.put("attachments", attachments.stream().map(Attachment::json).toList());
|
||||
json.put("coords", nullable(coords).map(Coords::json).orElse(null));
|
||||
json.put("description", description());
|
||||
json.put("end", end().map(end -> end.format(DATE_TIME)).orElse(null));
|
||||
json.put("id", id());
|
||||
json.put("location", location());
|
||||
json.put("slug", slug());
|
||||
json.put("start", start().format(DATE_TIME));
|
||||
json.put("tags", tags());
|
||||
json.put("title", title());
|
||||
json.put("links", urls().stream().map(Link::json).toList());
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String location() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String slug() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LocalDateTime start() {
|
||||
return start;
|
||||
@@ -155,7 +159,27 @@ public class BaseAppointment implements Appointment {
|
||||
|
||||
@Override
|
||||
public Set<String> tags() {
|
||||
return Set.of();
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds tag
|
||||
* @param newTags the tag to add to the appointment
|
||||
* @return the appointment
|
||||
*/
|
||||
public BaseAppointment tags(String... newTags) {
|
||||
Collections.addAll(tags, newTags);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* adds tag
|
||||
* @param newTags the tag to add to the appointment
|
||||
* @return the appointment
|
||||
*/
|
||||
public BaseAppointment tags(Collection<String> newTags) {
|
||||
tags.addAll(newTags);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,6 +194,6 @@ public class BaseAppointment implements Appointment {
|
||||
|
||||
@Override
|
||||
public Set<Link> urls() {
|
||||
return Set.of();
|
||||
return links;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user