remove all aliases for the note that is being deleted
This commit is contained in:
@@ -220,6 +220,21 @@ public class Storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getAliases(UUID noteId) {
|
||||||
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
|
PreparedStatement statement = connection.prepareStatement("SELECT alias FROM aliases WHERE note_id = ?");
|
||||||
|
statement.setString(1, noteId.toString());
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
Set<String> aliases = new HashSet<>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
aliases.add(resultSet.getString("alias"));
|
||||||
|
}
|
||||||
|
return aliases;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Note getNote(@NotNull String alias) {
|
public Note getNote(@NotNull String alias) {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
|
|||||||
@@ -351,7 +351,8 @@ public class SlashCommandListener extends ListenerAdapter {
|
|||||||
|
|
||||||
Storage.Status status = Main.getStorage().deleteNote(note.id);
|
Storage.Status status = Main.getStorage().deleteNote(note.id);
|
||||||
if (status == Storage.Status.SUCCESS) {
|
if (status == Storage.Status.SUCCESS) {
|
||||||
aliases.remove(noteAlias);
|
Set<String> noteAliases = Main.getStorage().getAliases(note.id);
|
||||||
|
noteAliases.forEach(aliases::remove);
|
||||||
event.reply("Note deleted.")
|
event.reply("Note deleted.")
|
||||||
.setEphemeral(true)
|
.setEphemeral(true)
|
||||||
.queue();
|
.queue();
|
||||||
|
|||||||
Reference in New Issue
Block a user