implemented storing of new transaction
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -45,6 +45,7 @@ public class Field {
|
||||
public static final String DELIVERY_DATE = "delivery_date";
|
||||
public static final String DESCRIPTION = "description";
|
||||
public static final String DESTINATION = "destination";
|
||||
public static final String DISPLAY = "display";
|
||||
public static final String DOCUMENT = "document";
|
||||
public static final String DOCUMENT_ID = "document_id";
|
||||
public static final String DOC_TYPE_ID = "document_type_id";
|
||||
@@ -129,6 +130,7 @@ public class Field {
|
||||
public static final String PROJECT = "project";
|
||||
public static final String PROJECT_ID = "project_id";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PURPOSE = "purpose";
|
||||
|
||||
public static final String RECEIVERS = "receivers";
|
||||
public static final String REDIRECT = "redirect";
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
public record Account(long id, String name, String currency, long ownerId) {
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
|
||||
public record Account(long id, String name, String currency, long ownerId) implements Mappable {
|
||||
public Account withId(long newId) {
|
||||
return new Account(newId,name,currency,ownerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var owner = userService().loadUser(ownerId);
|
||||
return Map.of(
|
||||
Field.ID, id,
|
||||
Field.NAME, name,
|
||||
Field.CURRENCY, currency,
|
||||
Field.OWNER, owner.toMap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
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 {
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var source = this.source;
|
||||
try {
|
||||
var userId = Long.parseLong(source);
|
||||
var user = userService().loadUser(userId);
|
||||
source = user.name();
|
||||
} catch (NumberFormatException ignored) {}
|
||||
|
||||
var destination = this.destination;
|
||||
try {
|
||||
var userId = Long.parseLong(destination);
|
||||
var user = userService().loadUser(userId);
|
||||
destination = user.name();
|
||||
} catch (NumberFormatException ignored) {}
|
||||
|
||||
return Map.of(
|
||||
Field.ID, accountId,
|
||||
Field.DATE, date.toLocalDate(),
|
||||
Field.SOURCE, source,
|
||||
Field.DESTINATION, destination,
|
||||
Field.AMOUNT, amount,
|
||||
Field.PURPOSE, purpose
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user