added map functionality

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-12-27 19:14:33 +01:00
parent 733b5a06a4
commit 9bbf43ce5b
13 changed files with 786 additions and 17 deletions
@@ -47,4 +47,6 @@ public interface Database {
public List<Appointment> listByTags(Set<String> tags, Integer count, Integer offset);
Result<Appointment> loadEvent(long id);
Result<List<String>> findTags(String infix);
}
@@ -39,6 +39,7 @@ public class MariaDB implements Database {
private static final String TID = "tid";
private static final String MIME = "mime";
private static final String APPOINTMENT_ATTACHMENTS = "appointment_attachments";
private static final String TAGS = "tags";
private static Connection connection;
private MariaDB(Connection conn) throws SQLException {
@@ -113,6 +114,19 @@ public class MariaDB implements Database {
return new MariaDB(DriverManager.getConnection(jdbc, user, pass));
}
@Override
public Result<List<String>> findTags(String infix) {
try {
List<String> results = new ArrayList<>();
var rs = Query.select(KEYWORD).from(TAGS).where(KEYWORD, like("%%%s%%".formatted(infix))).sort(KEYWORD).exec(connection);
while (rs.next()) results.add(rs.getString(KEYWORD));
rs.close();
return Payload.of(results);
} catch (SQLException e) {
return Error.format("failed to gather tags from DB.", e);
}
}
@Override
public List<Appointment> list(Integer count, Integer offset) throws SQLException {
var list = new ArrayList<Appointment>();
@@ -219,16 +233,16 @@ public class MariaDB implements Database {
@Override
public List<Appointment> list(LocalDateTime from, LocalDateTime till) throws SQLException {
var list = new ArrayList<Appointment>();
var list = new ArrayList<Appointment>();
var query = Query //
.select("appointments.*", "GROUP_CONCAT(keyword) AS tags")
.from(APPOINTMENTS)
.leftJoin(AID, "appointment_tags", AID)
.leftJoin("tid", "tags", "tid")
.groupBy(AID)
.sort("start DESC");
.select("appointments.*", "GROUP_CONCAT(keyword) AS tags")
.from(APPOINTMENTS)
.leftJoin(AID, "appointment_tags", AID)
.leftJoin("tid", "tags", "tid")
.groupBy(AID)
.sort("start DESC");
nullable(from).ifPresent(start -> query.where("start", moreThan(start)));
nullable(till).ifPresent(end -> query.where("end",lessThan(end)));
nullable(till).ifPresent(end -> query.where("end", lessThan(end)));
var results = query.exec(connection);
while (results.next()) createAppointmentOf(results).optional().ifPresent(list::add);