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