added map functionality
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user