feat(transaction-recurring): #100 replace active with next-execution
This commit was merged in pull request #133.
This commit is contained in:
@@ -57,7 +57,7 @@ func (h TransactionRecurringImpl) handleUpdateTransactionRecurring() http.Handle
|
||||
input := types.TransactionRecurringInput{
|
||||
Id: r.PathValue("id"),
|
||||
IntervalMonths: r.FormValue("interval-months"),
|
||||
Active: r.FormValue("active"),
|
||||
NextExecution: r.FormValue("next-execution"),
|
||||
Party: r.FormValue("party"),
|
||||
Description: r.FormValue("description"),
|
||||
AccountId: r.FormValue("account-id"),
|
||||
|
||||
5
migration/009_recurring_transaction_change.up.sql
Normal file
5
migration/009_recurring_transaction_change.up.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
ALTER TABLE transaction_recurring DROP COLUMN active;
|
||||
ALTER TABLE transaction_recurring DROP COLUMN last_execution;
|
||||
ALTER TABLE transaction_recurring ADD COLUMN next_execution DATETIME;
|
||||
|
||||
@@ -76,9 +76,9 @@ func (s TransactionRecurringImpl) Add(
|
||||
|
||||
r, err := tx.NamedExec(`
|
||||
INSERT INTO "transaction_recurring" (id, user_id, interval_months,
|
||||
active, party, description, account_id, treasure_chest_id, value, created_at, created_by)
|
||||
next_execution, party, description, account_id, treasure_chest_id, value, created_at, created_by)
|
||||
VALUES (:id, :user_id, :interval_months,
|
||||
:active, :party, :description, :account_id, :treasure_chest_id, :value, :created_at, :created_by)`,
|
||||
:next_execution, :party, :description, :account_id, :treasure_chest_id, :value, :created_at, :created_by)`,
|
||||
transactionRecurring)
|
||||
err = db.TransformAndLogDbError("transactionRecurring Insert", r, err)
|
||||
if err != nil {
|
||||
@@ -135,7 +135,7 @@ func (s TransactionRecurringImpl) Update(
|
||||
UPDATE transaction_recurring
|
||||
SET
|
||||
interval_months = :interval_months,
|
||||
active = :active,
|
||||
next_execution = :next_execution,
|
||||
party = :party,
|
||||
description = :description,
|
||||
account_id = :account_id,
|
||||
@@ -444,15 +444,24 @@ func (s TransactionRecurringImpl) validateAndEnrichTransactionRecurring(
|
||||
log.Error("transactionRecurring validate: %v", err)
|
||||
return nil, fmt.Errorf("intervalMonths needs to be greater than 0: %w", ErrBadRequest)
|
||||
}
|
||||
active := input.Active == "on"
|
||||
var nextExecution *time.Time = nil
|
||||
if input.NextExecution != "" {
|
||||
t, err := time.Parse("2006-01-02", input.NextExecution)
|
||||
if err != nil {
|
||||
log.Error("transaction validate: %v", err)
|
||||
return nil, fmt.Errorf("could not parse timestamp: %w", ErrBadRequest)
|
||||
}
|
||||
|
||||
t = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
|
||||
nextExecution = &t
|
||||
}
|
||||
|
||||
transactionRecurring := types.TransactionRecurring{
|
||||
Id: id,
|
||||
UserId: userId,
|
||||
|
||||
IntervalMonths: intervalMonths,
|
||||
Active: active,
|
||||
LastExecution: nil,
|
||||
NextExecution: nextExecution,
|
||||
|
||||
Party: input.Party,
|
||||
Description: input.Description,
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package transaction_recurring
|
||||
|
||||
import "fmt"
|
||||
import "time"
|
||||
import "spend-sparrow/template/svg"
|
||||
import "spend-sparrow/types"
|
||||
|
||||
templ TransactionRecurringItems(transactionsRecurring []*types.TransactionRecurring, editId, accountId, treasureChestId string) {
|
||||
<!-- Don't use table, because embedded forms are only valid for cells -->
|
||||
<div id="transaction-recurring" class="max-w-full grid gap-4 mt-10 grid-cols-[max-content_auto_auto_auto_auto_max-content] items-center text-xl">
|
||||
<span class="text-sm text-gray-500">Active</span>
|
||||
<span class="text-sm text-gray-500">Next Execution</span>
|
||||
<span class="text-sm text-gray-500">Party</span>
|
||||
<span class="text-sm text-gray-500">Description</span>
|
||||
<span class="text-sm text-gray-500">Interval</span>
|
||||
@@ -27,11 +28,11 @@ templ TransactionRecurringItems(transactionsRecurring []*types.TransactionRecurr
|
||||
}
|
||||
|
||||
templ TransactionRecurringItem(transactionRecurring *types.TransactionRecurring, accountId, treasureChestId string) {
|
||||
<p class="text-gray-600 text-center">
|
||||
if transactionRecurring.Active {
|
||||
✅
|
||||
<p class="text-gray-600">
|
||||
if transactionRecurring.NextExecution != nil {
|
||||
{ transactionRecurring.NextExecution.Format("2006/01") }
|
||||
} else {
|
||||
❌
|
||||
-
|
||||
}
|
||||
</p>
|
||||
<p class="text-gray-600">
|
||||
@@ -92,12 +93,15 @@ templ EditTransactionRecurring(transactionRecurring *types.TransactionRecurring,
|
||||
description := ""
|
||||
value := "0.00"
|
||||
intervalMonths := "1"
|
||||
active := true
|
||||
nextExecution := ""
|
||||
if transactionRecurring == nil {
|
||||
id = "new"
|
||||
nextExecution = time.Now().Format("2006-01-02")
|
||||
} else {
|
||||
intervalMonths = fmt.Sprintf("%d", transactionRecurring.IntervalMonths)
|
||||
active = transactionRecurring.Active
|
||||
if transactionRecurring.NextExecution != nil {
|
||||
nextExecution = transactionRecurring.NextExecution.Format("2006-01-02")
|
||||
}
|
||||
party = transactionRecurring.Party
|
||||
description = transactionRecurring.Description
|
||||
value = displayBalance(transactionRecurring.Value)
|
||||
@@ -113,11 +117,10 @@ templ EditTransactionRecurring(transactionRecurring *types.TransactionRecurring,
|
||||
class="hidden"
|
||||
></form>
|
||||
<input
|
||||
name="active"
|
||||
name="next-execution"
|
||||
form="transaction-recurring-form"
|
||||
id="active"
|
||||
type="checkbox"
|
||||
checked?={ active }
|
||||
type="date"
|
||||
value={ nextExecution }
|
||||
class="bg-white input"
|
||||
/>
|
||||
<input
|
||||
|
||||
@@ -11,8 +11,7 @@ type TransactionRecurring struct {
|
||||
UserId uuid.UUID `db:"user_id"`
|
||||
|
||||
IntervalMonths int64 `db:"interval_months"`
|
||||
LastExecution *time.Time `db:"last_execution"`
|
||||
Active bool `db:"active"`
|
||||
NextExecution *time.Time `db:"next_execution"`
|
||||
|
||||
Party string `db:"party"`
|
||||
Description string `db:"description"`
|
||||
@@ -30,7 +29,7 @@ type TransactionRecurring struct {
|
||||
type TransactionRecurringInput struct {
|
||||
Id string
|
||||
IntervalMonths string
|
||||
Active string
|
||||
NextExecution string
|
||||
Party string
|
||||
Description string
|
||||
AccountId string
|
||||
|
||||
Reference in New Issue
Block a user