working on update of transactions
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -159,11 +159,9 @@ public class AccountingModule extends BaseHandler implements AccountingService {
|
||||
var transaction = accountDb.loadTransaction(transactionId);
|
||||
LOG.log(WARNING,"Missing permission check in patchTransaction(…)!");
|
||||
var json = json(ex);
|
||||
if (json.has(Field.DATE)){
|
||||
var date = LocalDate.parse(json.getString(Field.DATE));
|
||||
transaction.date(date);
|
||||
if (json.has(Field.DATE)) transaction.date(LocalDate.parse(json.getString(Field.DATE)));
|
||||
if (json.has(Field.PURPOSE)) transaction.purpose(json.getString(Field.PURPOSE));
|
||||
accountDb.save(transaction);
|
||||
}
|
||||
return sendContent(ex,transaction);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,12 +217,12 @@ public class SqliteDb extends BaseDb implements AccountDb {
|
||||
} catch (SQLException e) {
|
||||
throw failedToStoreObject(transaction);
|
||||
}
|
||||
} else {
|
||||
} else if (transaction.isDirty()) {
|
||||
try {
|
||||
Query.replaceInto(TABLE_TRANSACTIONS, Field.ID, Field.ACCOUNT, Field.TIMESTAMP, Field.SOURCE, Field.DESTINATION, Field.AMOUNT, Field.DESCRIPTION)
|
||||
.values(transaction.id(), transaction.accountId(), timestamp, transaction.source().value(), transaction.destination().value(), transaction.amount(), transaction.purpose())
|
||||
.execute(db).close();
|
||||
return transaction;
|
||||
return transaction.clearDirtyState();
|
||||
} catch (SQLException e) {
|
||||
throw failedToStoreObject(transaction);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public class Transaction implements Mappable {
|
||||
private double amount;
|
||||
private String purpose;
|
||||
private Set<String> tags;
|
||||
private HashSet<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public Transaction(long id, long accountId, LocalDateTime date, IdOrString source, IdOrString destination, double amount, String purpose, Set<String> tags){
|
||||
this.id = id;
|
||||
@@ -41,17 +42,23 @@ public class Transaction implements Mappable {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Transaction clearDirtyState(){
|
||||
dirtyFields.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalDateTime date(){
|
||||
return date;
|
||||
}
|
||||
|
||||
public Transaction date(LocalDateTime newVal){
|
||||
date = newVal;
|
||||
dirtyFields.add(Field.DATE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void date(LocalDate date) {
|
||||
this.date = this.date.withYear(date.getYear()).withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth());
|
||||
public Transaction date(LocalDate date) {
|
||||
return date(this.date.withYear(date.getYear()).withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth()));
|
||||
}
|
||||
|
||||
public IdOrString destination(){
|
||||
@@ -62,6 +69,10 @@ public class Transaction implements Mappable {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isDirty(){
|
||||
return !dirtyFields.isEmpty();
|
||||
}
|
||||
|
||||
public static Transaction of(ResultSet rs) throws SQLException {
|
||||
var accountId = rs.getLong(Field.ACCOUNT);
|
||||
var timestamp = rs.getLong(Field.TIMESTAMP);
|
||||
@@ -78,6 +89,12 @@ public class Transaction implements Mappable {
|
||||
return purpose;
|
||||
}
|
||||
|
||||
public Transaction purpose(String newVal){
|
||||
purpose = newVal;
|
||||
dirtyFields.add(Field.PURPOSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IdOrString source(){
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
async function setDate(newDate){
|
||||
return await update({date:newDate});
|
||||
async function setDate(date){
|
||||
return await update({date});
|
||||
}
|
||||
|
||||
async function setPurpose(purpose){
|
||||
return await update({purpose});
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -42,7 +46,9 @@
|
||||
→ {transaction.destination.value}
|
||||
{/if}
|
||||
</td>
|
||||
<td class="purpose">{transaction.purpose}</td>
|
||||
<td class="purpose">
|
||||
<LineEditor wrapper="span" editable="true" value={transaction.purpose} onSet={setPurpose} />
|
||||
</td>
|
||||
<td class="tags">
|
||||
{transaction.tags.join(', ')}
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user