working on loading of account data
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -175,6 +175,7 @@ public class Field {
|
||||
public static final String TO = "to";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String TOTAL_PRIO = "total_prio";
|
||||
public static final String TRANSACTIONS = "transactions";
|
||||
public static final String TYPE = "type";
|
||||
public static final String TYPE_ID = "type_id";
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ package de.srsoftware.umbrella.core.constants;
|
||||
* This is a collection of messages that appear throughout the project
|
||||
*/
|
||||
public class Text {
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String ACCOUNTING = "accounting";
|
||||
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
|
||||
@@ -3,13 +3,27 @@ package de.srsoftware.umbrella.core.model;
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
|
||||
public record Transaction(long accountId, LocalDateTime date, String source, String destination, double amount, String purpose) implements Mappable {
|
||||
public static Transaction of(ResultSet rs) throws SQLException {
|
||||
var accountId = rs.getLong(Field.ACCOUNT);
|
||||
var timestamp = rs.getLong(Field.TIMESTAMP);
|
||||
var date = LocalDateTime.ofEpochSecond(timestamp,0, ZoneOffset.UTC);
|
||||
var source = rs.getString(Field.SOURCE);
|
||||
var destination = rs.getString(Field.DESTINATION);
|
||||
var amount = rs.getDouble(Field.AMOUNT);
|
||||
var purpose = rs.getString(Field.DESCRIPTION);
|
||||
return new Transaction(accountId,date,source,destination,amount,purpose);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var source = this.source;
|
||||
@@ -27,7 +41,7 @@ public record Transaction(long accountId, LocalDateTime date, String source, Str
|
||||
} catch (NumberFormatException ignored) {}
|
||||
|
||||
return Map.of(
|
||||
Field.ID, accountId,
|
||||
Field.ACCOUNT, accountId,
|
||||
Field.DATE, date.toLocalDate(),
|
||||
Field.SOURCE, source,
|
||||
Field.DESTINATION, destination,
|
||||
|
||||
Reference in New Issue
Block a user