Added method for getting tags from db
This commit is contained in:
parent
e7a7b4f40e
commit
29c30d928e
@ -11,6 +11,8 @@ import dev.salmonllama.fsbot.database.models.Outfit;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
@ -86,6 +88,16 @@ public class OutfitController {
|
||||
});
|
||||
}
|
||||
|
||||
public static CompletableFuture<Collection<String>> getDistinctTags() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return getDistinctTagsExec();
|
||||
} catch (SQLException e) {
|
||||
throw new CompletionException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void insertExec(Outfit outfit) throws SQLException {
|
||||
if (outfit.getCreated() == null) {
|
||||
outfit.setCreated(new Timestamp(System.currentTimeMillis()));
|
||||
@ -188,6 +200,18 @@ public class OutfitController {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static Collection<String> getDistinctTagsExec() throws SQLException {
|
||||
ResultSet rs = FSDB.get().select("SELECT DISTINCT tag FROM outfits");
|
||||
|
||||
Collection<String> tags = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
tags.add(rs.getString("tag"));
|
||||
}
|
||||
|
||||
FSDB.get().close(rs);
|
||||
return tags;
|
||||
}
|
||||
|
||||
private static Outfit mapObject(ResultSet rs) throws SQLException {
|
||||
return new Outfit.OutfitBuilder()
|
||||
.setId(rs.getString("id"))
|
||||
|
Loading…
Reference in New Issue
Block a user