preparing storage of tags
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -157,6 +157,7 @@ public class Field {
|
||||
public static final String TAG = "tag";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TAG_COLORS = "tag_colors";
|
||||
public static final String TAG_ID = "tag_id";
|
||||
public static final String TASK = "task";
|
||||
public static final String TASK_IDS = "task_ids";
|
||||
public static final String TASKS = "tasks";
|
||||
@@ -175,6 +176,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 TRANSACTION_ID = "transaction_id";
|
||||
public static final String TRANSACTIONS = "transactions";
|
||||
public static final String TYPE = "type";
|
||||
public static final String TYPE_ID = "type_id";
|
||||
|
||||
@@ -7,9 +7,11 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public record Transaction(long accountId, LocalDateTime date, IdOrString source, IdOrString destination, double amount, String purpose) implements Mappable {
|
||||
public record Transaction(long id, long accountId, LocalDateTime date, IdOrString source, IdOrString destination, double amount, String purpose, Set<String> tags) implements Mappable {
|
||||
|
||||
|
||||
public static Transaction of(ResultSet rs) throws SQLException {
|
||||
@@ -20,12 +22,14 @@ public record Transaction(long accountId, LocalDateTime date, IdOrString source,
|
||||
var destination = IdOrString.of(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);
|
||||
var id = rs.getLong(Field.ID);
|
||||
return new Transaction(id, accountId, date, source, destination, amount, purpose, new HashSet<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(
|
||||
Field.ID, id,
|
||||
Field.ACCOUNT, accountId,
|
||||
Field.DATE, date.toLocalDate(),
|
||||
Field.SOURCE, source.toMap(),
|
||||
@@ -34,4 +38,8 @@ public record Transaction(long accountId, LocalDateTime date, IdOrString source,
|
||||
Field.PURPOSE, purpose
|
||||
);
|
||||
}
|
||||
|
||||
public Transaction withId(long id) {
|
||||
return new Transaction(id, accountId, date, source, destination, amount, purpose, new HashSet<>(tags));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user