feat(transaction): #66 refine inputs
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 4m55s
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 4m55s
This commit is contained in:
@@ -83,9 +83,9 @@ func (s TransactionImpl) Update(user *types.User, input types.TransactionInput)
|
|||||||
return nil, fmt.Errorf("could not parse Id: %w", ErrBadRequest)
|
return nil, fmt.Errorf("could not parse Id: %w", ErrBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
var transaction *types.Transaction
|
transaction := &types.Transaction{}
|
||||||
err = s.db.Select(transaction, `SELECT * FROM "transaction" WHERE user_id = ? AND id = ?`, user.Id, uuid)
|
err = s.db.Get(transaction, `SELECT * FROM "transaction" WHERE user_id = ? AND id = ?`, user.Id, uuid)
|
||||||
err = db.TransformAndLogDbError("transaction Get", nil, err)
|
err = db.TransformAndLogDbError("transaction Update", nil, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == db.ErrNotFound {
|
if err == db.ErrNotFound {
|
||||||
return nil, fmt.Errorf("transaction %v not found: %w", input.Id, ErrBadRequest)
|
return nil, fmt.Errorf("transaction %v not found: %w", input.Id, ErrBadRequest)
|
||||||
@@ -99,7 +99,7 @@ func (s TransactionImpl) Update(user *types.User, input types.TransactionInput)
|
|||||||
}
|
}
|
||||||
|
|
||||||
r, err := s.db.NamedExec(`
|
r, err := s.db.NamedExec(`
|
||||||
UPDATE transaction
|
UPDATE "transaction"
|
||||||
SET
|
SET
|
||||||
account_id = :account_id,
|
account_id = :account_id,
|
||||||
treasure_chest_id = :treasure_chest_id,
|
treasure_chest_id = :treasure_chest_id,
|
||||||
@@ -182,8 +182,8 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
id uuid.UUID
|
id uuid.UUID
|
||||||
accountUuid uuid.UUID
|
accountUuid *uuid.UUID
|
||||||
treasureChestUuid uuid.UUID
|
treasureChestUuid *uuid.UUID
|
||||||
createdAt time.Time
|
createdAt time.Time
|
||||||
createdBy uuid.UUID
|
createdBy uuid.UUID
|
||||||
updatedAt *time.Time
|
updatedAt *time.Time
|
||||||
@@ -210,12 +210,13 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
|||||||
}
|
}
|
||||||
|
|
||||||
if input.AccountId != "" {
|
if input.AccountId != "" {
|
||||||
accountUuid, err = uuid.Parse(input.AccountId)
|
temp, err := uuid.Parse(input.AccountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("transaction validate: %v", err)
|
log.Error("transaction validate: %v", err)
|
||||||
return nil, fmt.Errorf("could not parse accountId: %w", ErrBadRequest)
|
return nil, fmt.Errorf("could not parse accountId: %w", ErrBadRequest)
|
||||||
}
|
}
|
||||||
err = s.db.Select(&rowCount, `SELECT COUNT(*) FROM account WHERE id = ? AND user_id = ?`, accountUuid, userId)
|
accountUuid = &temp
|
||||||
|
err = s.db.Get(&rowCount, `SELECT COUNT(*) FROM account WHERE id = ? AND user_id = ?`, accountUuid, userId)
|
||||||
err = db.TransformAndLogDbError("transaction validate", nil, err)
|
err = db.TransformAndLogDbError("transaction validate", nil, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -228,12 +229,13 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
|||||||
}
|
}
|
||||||
|
|
||||||
if input.TreasureChestId != "" {
|
if input.TreasureChestId != "" {
|
||||||
treasureChestUuid, err = uuid.Parse(input.TreasureChestId)
|
temp, err := uuid.Parse(input.TreasureChestId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("transaction validate: %v", err)
|
log.Error("transaction validate: %v", err)
|
||||||
return nil, fmt.Errorf("could not parse treasureChestId: %w", ErrBadRequest)
|
return nil, fmt.Errorf("could not parse treasureChestId: %w", ErrBadRequest)
|
||||||
}
|
}
|
||||||
err = s.db.Select(&rowCount, `SELECT COUNT(*) FROM treasure_chest WHERE id = ? AND user_id = ?`, accountUuid, userId)
|
treasureChestUuid = &temp
|
||||||
|
err = s.db.Get(&rowCount, `SELECT COUNT(*) FROM treasure_chest WHERE id = ? AND user_id = ?`, treasureChestUuid, userId)
|
||||||
err = db.TransformAndLogDbError("transaction validate", nil, err)
|
err = db.TransformAndLogDbError("transaction validate", nil, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -276,8 +278,8 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
|||||||
Id: id,
|
Id: id,
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
|
|
||||||
AccountId: &accountUuid,
|
AccountId: accountUuid,
|
||||||
TreasureChestId: &treasureChestUuid,
|
TreasureChestId: treasureChestUuid,
|
||||||
Value: valueInt,
|
Value: valueInt,
|
||||||
Timestamp: timestampTime,
|
Timestamp: timestampTime,
|
||||||
Note: input.Note,
|
Note: input.Note,
|
||||||
|
|||||||
@@ -29,28 +29,28 @@ templ EditTransaction(transaction *types.Transaction, accounts []*types.Account,
|
|||||||
{{
|
{{
|
||||||
var (
|
var (
|
||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
note string
|
|
||||||
// accountId string
|
|
||||||
// treasureChestId string
|
|
||||||
value string
|
value string
|
||||||
|
|
||||||
id string
|
id string
|
||||||
cancelUrl string
|
cancelUrl string
|
||||||
)
|
)
|
||||||
|
note := ""
|
||||||
|
accountId := ""
|
||||||
|
treasureChestId := ""
|
||||||
if transaction == nil {
|
if transaction == nil {
|
||||||
timestamp = time.Now().UTC().Truncate(time.Minute)
|
timestamp = time.Now().UTC().Truncate(time.Minute)
|
||||||
note = ""
|
|
||||||
// accountId = ""
|
|
||||||
// treasureChestId = ""
|
|
||||||
value = "0.00"
|
|
||||||
|
|
||||||
id = "new"
|
id = "new"
|
||||||
cancelUrl = "/empty"
|
cancelUrl = "/empty"
|
||||||
} else {
|
} else {
|
||||||
timestamp = transaction.Timestamp.UTC().Truncate(time.Minute)
|
timestamp = transaction.Timestamp.UTC().Truncate(time.Minute)
|
||||||
note = transaction.Note
|
note = transaction.Note
|
||||||
// accountId = transaction.AccountId.String()
|
if transaction.AccountId != nil {
|
||||||
// treasureChestId = transaction.TreasureChestId.String()
|
accountId = transaction.AccountId.String()
|
||||||
|
}
|
||||||
|
if transaction.TreasureChestId != nil {
|
||||||
|
treasureChestId = transaction.TreasureChestId.String()
|
||||||
|
}
|
||||||
value = displayBalance(transaction.Value)
|
value = displayBalance(transaction.Value)
|
||||||
|
|
||||||
id = transaction.Id.String()
|
id = transaction.Id.String()
|
||||||
@@ -96,7 +96,7 @@ templ EditTransaction(transaction *types.Transaction, accounts []*types.Account,
|
|||||||
>
|
>
|
||||||
<option value="">-</option>
|
<option value="">-</option>
|
||||||
for _, account := range accounts {
|
for _, account := range accounts {
|
||||||
<option value={ account.Id.String() }>{ account.Name }</option>
|
<option selected?={ account.Id.String() == accountId } value={ account.Id.String() }>{ account.Name }</option>
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
<label for="treasure-chest-id" class="text-sm text-gray-500">Treasure Chest</label>
|
<label for="treasure-chest-id" class="text-sm text-gray-500">Treasure Chest</label>
|
||||||
@@ -106,7 +106,7 @@ templ EditTransaction(transaction *types.Transaction, accounts []*types.Account,
|
|||||||
>
|
>
|
||||||
<option value="">-</option>
|
<option value="">-</option>
|
||||||
for _, treasureChest := range treasureChests {
|
for _, treasureChest := range treasureChests {
|
||||||
<option value={ treasureChest.Id.String() }>
|
<option selected?={ treasureChest.Id.String() == treasureChestId } value={ treasureChest.Id.String() }>
|
||||||
if treasureChest.ParentId != uuid.Nil {
|
if treasureChest.ParentId != uuid.Nil {
|
||||||
{ treasureChest.Name }
|
{ treasureChest.Name }
|
||||||
} else {
|
} else {
|
||||||
@@ -141,7 +141,7 @@ templ TransactionItem(transaction *types.Transaction) {
|
|||||||
<div id="transaction" class="border-1 border-gray-300 w-full my-4 p-4 bg-gray-50 rounded-lg">
|
<div id="transaction" class="border-1 border-gray-300 w-full my-4 p-4 bg-gray-50 rounded-lg">
|
||||||
<div class="text-xl flex justify-end gap-4">
|
<div class="text-xl flex justify-end gap-4">
|
||||||
<p class="mr-auto datetime">{ transaction.Timestamp.String() }</p>
|
<p class="mr-auto datetime">{ transaction.Timestamp.String() }</p>
|
||||||
<p class="mr-20 text-green-700">{ displayBalance(transaction.Value) }</p>
|
<p class="mr-20 text-green-700">{ displayBalance(transaction.Value)+" €" }</p>
|
||||||
<button
|
<button
|
||||||
hx-get={ "/transaction/" + transaction.Id.String() + "?edit=true" }
|
hx-get={ "/transaction/" + transaction.Id.String() + "?edit=true" }
|
||||||
hx-target="closest #transaction"
|
hx-target="closest #transaction"
|
||||||
|
|||||||
Reference in New Issue
Block a user