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{
|
input := types.TransactionRecurringInput{
|
||||||
Id: r.PathValue("id"),
|
Id: r.PathValue("id"),
|
||||||
IntervalMonths: r.FormValue("interval-months"),
|
IntervalMonths: r.FormValue("interval-months"),
|
||||||
Active: r.FormValue("active"),
|
NextExecution: r.FormValue("next-execution"),
|
||||||
Party: r.FormValue("party"),
|
Party: r.FormValue("party"),
|
||||||
Description: r.FormValue("description"),
|
Description: r.FormValue("description"),
|
||||||
AccountId: r.FormValue("account-id"),
|
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(`
|
r, err := tx.NamedExec(`
|
||||||
INSERT INTO "transaction_recurring" (id, user_id, interval_months,
|
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,
|
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)
|
transactionRecurring)
|
||||||
err = db.TransformAndLogDbError("transactionRecurring Insert", r, err)
|
err = db.TransformAndLogDbError("transactionRecurring Insert", r, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -135,7 +135,7 @@ func (s TransactionRecurringImpl) Update(
|
|||||||
UPDATE transaction_recurring
|
UPDATE transaction_recurring
|
||||||
SET
|
SET
|
||||||
interval_months = :interval_months,
|
interval_months = :interval_months,
|
||||||
active = :active,
|
next_execution = :next_execution,
|
||||||
party = :party,
|
party = :party,
|
||||||
description = :description,
|
description = :description,
|
||||||
account_id = :account_id,
|
account_id = :account_id,
|
||||||
@@ -444,15 +444,24 @@ func (s TransactionRecurringImpl) validateAndEnrichTransactionRecurring(
|
|||||||
log.Error("transactionRecurring validate: %v", err)
|
log.Error("transactionRecurring validate: %v", err)
|
||||||
return nil, fmt.Errorf("intervalMonths needs to be greater than 0: %w", ErrBadRequest)
|
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{
|
transactionRecurring := types.TransactionRecurring{
|
||||||
Id: id,
|
Id: id,
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
|
|
||||||
IntervalMonths: intervalMonths,
|
IntervalMonths: intervalMonths,
|
||||||
Active: active,
|
NextExecution: nextExecution,
|
||||||
LastExecution: nil,
|
|
||||||
|
|
||||||
Party: input.Party,
|
Party: input.Party,
|
||||||
Description: input.Description,
|
Description: input.Description,
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package transaction_recurring
|
package transaction_recurring
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "time"
|
||||||
import "spend-sparrow/template/svg"
|
import "spend-sparrow/template/svg"
|
||||||
import "spend-sparrow/types"
|
import "spend-sparrow/types"
|
||||||
|
|
||||||
templ TransactionRecurringItems(transactionsRecurring []*types.TransactionRecurring, editId, accountId, treasureChestId string) {
|
templ TransactionRecurringItems(transactionsRecurring []*types.TransactionRecurring, editId, accountId, treasureChestId string) {
|
||||||
<!-- Don't use table, because embedded forms are only valid for cells -->
|
<!-- 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">
|
<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">Party</span>
|
||||||
<span class="text-sm text-gray-500">Description</span>
|
<span class="text-sm text-gray-500">Description</span>
|
||||||
<span class="text-sm text-gray-500">Interval</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) {
|
templ TransactionRecurringItem(transactionRecurring *types.TransactionRecurring, accountId, treasureChestId string) {
|
||||||
<p class="text-gray-600 text-center">
|
<p class="text-gray-600">
|
||||||
if transactionRecurring.Active {
|
if transactionRecurring.NextExecution != nil {
|
||||||
✅
|
{ transactionRecurring.NextExecution.Format("2006/01") }
|
||||||
} else {
|
} else {
|
||||||
❌
|
-
|
||||||
}
|
}
|
||||||
</p>
|
</p>
|
||||||
<p class="text-gray-600">
|
<p class="text-gray-600">
|
||||||
@@ -92,12 +93,15 @@ templ EditTransactionRecurring(transactionRecurring *types.TransactionRecurring,
|
|||||||
description := ""
|
description := ""
|
||||||
value := "0.00"
|
value := "0.00"
|
||||||
intervalMonths := "1"
|
intervalMonths := "1"
|
||||||
active := true
|
nextExecution := ""
|
||||||
if transactionRecurring == nil {
|
if transactionRecurring == nil {
|
||||||
id = "new"
|
id = "new"
|
||||||
|
nextExecution = time.Now().Format("2006-01-02")
|
||||||
} else {
|
} else {
|
||||||
intervalMonths = fmt.Sprintf("%d", transactionRecurring.IntervalMonths)
|
intervalMonths = fmt.Sprintf("%d", transactionRecurring.IntervalMonths)
|
||||||
active = transactionRecurring.Active
|
if transactionRecurring.NextExecution != nil {
|
||||||
|
nextExecution = transactionRecurring.NextExecution.Format("2006-01-02")
|
||||||
|
}
|
||||||
party = transactionRecurring.Party
|
party = transactionRecurring.Party
|
||||||
description = transactionRecurring.Description
|
description = transactionRecurring.Description
|
||||||
value = displayBalance(transactionRecurring.Value)
|
value = displayBalance(transactionRecurring.Value)
|
||||||
@@ -113,11 +117,10 @@ templ EditTransactionRecurring(transactionRecurring *types.TransactionRecurring,
|
|||||||
class="hidden"
|
class="hidden"
|
||||||
></form>
|
></form>
|
||||||
<input
|
<input
|
||||||
name="active"
|
name="next-execution"
|
||||||
form="transaction-recurring-form"
|
form="transaction-recurring-form"
|
||||||
id="active"
|
type="date"
|
||||||
type="checkbox"
|
value={ nextExecution }
|
||||||
checked?={ active }
|
|
||||||
class="bg-white input"
|
class="bg-white input"
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ type TransactionRecurring struct {
|
|||||||
UserId uuid.UUID `db:"user_id"`
|
UserId uuid.UUID `db:"user_id"`
|
||||||
|
|
||||||
IntervalMonths int64 `db:"interval_months"`
|
IntervalMonths int64 `db:"interval_months"`
|
||||||
LastExecution *time.Time `db:"last_execution"`
|
NextExecution *time.Time `db:"next_execution"`
|
||||||
Active bool `db:"active"`
|
|
||||||
|
|
||||||
Party string `db:"party"`
|
Party string `db:"party"`
|
||||||
Description string `db:"description"`
|
Description string `db:"description"`
|
||||||
@@ -30,7 +29,7 @@ type TransactionRecurring struct {
|
|||||||
type TransactionRecurringInput struct {
|
type TransactionRecurringInput struct {
|
||||||
Id string
|
Id string
|
||||||
IntervalMonths string
|
IntervalMonths string
|
||||||
Active string
|
NextExecution string
|
||||||
Party string
|
Party string
|
||||||
Description string
|
Description string
|
||||||
AccountId string
|
AccountId string
|
||||||
|
|||||||
Reference in New Issue
Block a user