implemented download of account data as CSV
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -78,7 +78,7 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
case null -> getAccounts(user.get(),ex);
|
||||
default -> {
|
||||
try {
|
||||
yield getAccount(user.get(),Long.parseLong(head),ex);
|
||||
yield getAccount(user.get(),Long.parseLong(head), path.pop(), ex);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
yield super.doGet(path,ex);
|
||||
}
|
||||
@@ -184,9 +184,17 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean getAccount(UmbrellaUser user, long accountId, HttpExchange ex) throws IOException {
|
||||
private boolean getAccount(UmbrellaUser user, long accountId, String format, HttpExchange ex) throws IOException {
|
||||
if (!accountDb.getMembers(accountId).contains(user)) throw forbidden("You are not allowed to access account {id}",Field.ID,accountId);
|
||||
return sendContent(ex, loadAccount(accountId));
|
||||
var data = loadAccount(accountId);
|
||||
return switch (format){
|
||||
case "csv" -> {
|
||||
ex.getResponseHeaders().add("Content-Type", "text/csv");
|
||||
var users = userService().loader();
|
||||
yield sendContent(ex,data.toCsv(users));
|
||||
}
|
||||
case null, default -> sendContent(ex,data);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean getAccounts(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user