Browse Source

made Appointment.location() return an optional

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main
Stephan Richter 4 months ago
parent
commit
b16f2f9cd5
  1. 1
      build.gradle.kts
  2. 2
      de.srsoftware.cal.api/src/main/java/de/srsoftware/cal/api/Appointment.java
  3. 8
      de.srsoftware.cal.base/src/main/java/de/srsoftware/cal/BaseAppointment.java
  4. 4
      de.srsoftware.cal.db/src/main/java/de/srsoftware/cal/db/MariaDB.java

1
build.gradle.kts

@ -12,7 +12,6 @@ spotless { @@ -12,7 +12,6 @@ spotless {
removeUnusedImports()
importOrder()
licenseHeader("/* © SRSoftware 2024 */")
toggleOffOn()
}
}

2
de.srsoftware.cal.api/src/main/java/de/srsoftware/cal/api/Appointment.java

@ -65,7 +65,7 @@ public interface Appointment { @@ -65,7 +65,7 @@ public interface Appointment {
* descriptive text of the location, e.g. address
* @return location text
*/
String location();
Optional<String> location();
/**
* The date and time, when the appointment starts

8
de.srsoftware.cal.base/src/main/java/de/srsoftware/cal/BaseAppointment.java

@ -134,7 +134,7 @@ public class BaseAppointment implements Appointment { @@ -134,7 +134,7 @@ public class BaseAppointment implements Appointment {
sb.append(contentLine(SUMMARY,title()));
sb.append(contentLine(DESCRIPTION,description()));
coords().map(Coords::icalFormat).map(geo -> contentLine(GEO,geo)).ifPresent(sb::append);
if (!location().isBlank()) sb.append(contentLine(LOCATION,location()));
location().map(loc -> contentLine(LOCATION,loc)).ifPresent(sb::append);
for (var attachment : attachments()) sb.append(contentLine("ATTACH;FMTYPE=%s".formatted(attachment.mime()),attachment.url().toString()));
for (var link : links) sb.append(contentLine("ATTACH;TITLE="+paramText(link.desciption()),link.url().toString()));
sb.append(contentLine("CLASS","PUBLIC"));
@ -156,7 +156,7 @@ public class BaseAppointment implements Appointment { @@ -156,7 +156,7 @@ public class BaseAppointment implements Appointment {
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("location", location().orElse(null));
json.put("start", start().format(DATE_TIME));
json.put("tags", tags());
json.put("title", title());
@ -166,8 +166,8 @@ public class BaseAppointment implements Appointment { @@ -166,8 +166,8 @@ public class BaseAppointment implements Appointment {
}
@Override
public String location() {
return location;
public Optional<String> location() {
return nullable(location);
}
@Override

4
de.srsoftware.cal.db/src/main/java/de/srsoftware/cal/db/MariaDB.java

@ -62,7 +62,7 @@ public class MariaDB implements Database { @@ -62,7 +62,7 @@ public class MariaDB implements Database {
public Result<Appointment> add(Appointment appointment) {
try {
ResultSet keys = insertInto(APPOINTMENTS, TITLE, DESCRIPTION, START, END, LOCATION, COORDS) //
.values(appointment.title(), appointment.description(), appointment.start(), appointment.end().orElse(null), appointment.location(), appointment.coords().orElse(null))
.values(appointment.title(), appointment.description(), appointment.start(), appointment.end().orElse(null), appointment.location().orElse(null), appointment.coords().orElse(null))
.execute(connection)
.getGeneratedKeys();
Appointment saved = null;
@ -316,7 +316,7 @@ public class MariaDB implements Database { @@ -316,7 +316,7 @@ public class MariaDB implements Database {
.set(TITLE, DESCRIPTION, START, END, LOCATION, COORDS)
.where(AID, equal(event.id()))
.prepare(connection)
.apply(event.title(), event.description(), Timestamp.valueOf(event.start()), end, event.location(), event.coords().orElse(null));
.apply(event.title(), event.description(), Timestamp.valueOf(event.start()), end, event.location().orElse(null), event.coords().orElse(null));
// TODO: update links, attachments, tags

Loading…
Cancel
Save