Add DB method to retrieve all
This commit is contained in:
parent
81a6f2985c
commit
fbfc6c9dfd
@ -49,6 +49,16 @@ public class StaticPermissionController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Optional<Collection<StaticPermission>>> getAll() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
try {
|
||||||
|
return getAllExec();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new CompletionException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Void> delete(StaticPermission perm) {
|
public static CompletableFuture<Void> delete(StaticPermission perm) {
|
||||||
return delete(perm.getUserId(), perm.getPermission());
|
return delete(perm.getUserId(), perm.getPermission());
|
||||||
}
|
}
|
||||||
@ -105,6 +115,23 @@ public class StaticPermissionController {
|
|||||||
return Optional.of(users);
|
return Optional.of(users);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Optional<Collection<StaticPermission>> getAllExec() throws SQLException {
|
||||||
|
ResultSet rs = FSDB.get().select("SELECT * FROM static_permissions");
|
||||||
|
|
||||||
|
Collection<StaticPermission> permissions = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
permissions.add(mapObject(rs));
|
||||||
|
}
|
||||||
|
|
||||||
|
FSDB.get().close(rs);
|
||||||
|
|
||||||
|
if (permissions.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(permissions);
|
||||||
|
}
|
||||||
|
|
||||||
private static void deleteExec(String userId, String perm) throws SQLException {
|
private static void deleteExec(String userId, String perm) throws SQLException {
|
||||||
FSDB.get().query("DELETE FROM static_permissions WHERE user_id = ? AND permission = ?", userId, perm);
|
FSDB.get().query("DELETE FROM static_permissions WHERE user_id = ? AND permission = ?", userId, perm);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user