Compare commits

..

1 Commits

Author SHA1 Message Date
b6617ab86f
ci: add action-semantic-pull-request
Some checks failed
Lint PR / Validate PR title (pull_request) Failing after 4s
Go / build (1.21) (pull_request) Successful in 14s
Go / build (1.22) (pull_request) Successful in 13s
2025-06-01 20:36:51 +01:00
3 changed files with 41 additions and 70 deletions

View File

@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
go-version: [ '1.22', '1.23', '1.24' ] go-version: [ '1.21', '1.22' ]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -25,4 +25,4 @@ jobs:
run: go build -v ./... run: go build -v ./...
- name: Test - name: Test
run: go test -v ./... run: go test -v ./...

View File

@ -8,7 +8,5 @@ jobs:
lint: lint:
name: Validate PR title name: Validate PR title
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
pull-requests: read
steps: steps:
- uses: ammann/action-semantic-pull-request@v5 - uses: ammann/action-semantic-pull-request@v5

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"log" "log"
"strings"
"git.rosemyrtle.work/personal-finance/server/internal/entity" "git.rosemyrtle.work/personal-finance/server/internal/entity"
) )
@ -21,13 +20,13 @@ func (dal *DalImpl) Transaction(transactionId int64) (*entity.Transaction, error
log.Panic("database not available") log.Panic("database not available")
} }
stmts := []string{ stmt := `
"SELECT t.id, t.date, t.description, t.amount, tc.name", SELECT t.id, t.date, t.description, t.amount, tc.name
"FROM pfbudget.transactions t", FROM pfbudget.transactions t
"LEFT JOIN pfbudget.transactions_categorized tc ON t.id = tc.id", LEFT JOIN pfbudget.transactions_categorized tc
"WHERE t.id = $1", ON t.id = tc.id
} WHERE t.id = $1
stmt := strings.Join(stmts, "\n") + "\n" `
rows, err := dal.Db.Query(stmt, transactionId) rows, err := dal.Db.Query(stmt, transactionId)
if err != nil { if err != nil {
@ -49,25 +48,22 @@ func (dal *DalImpl) Transactions(limit, offset int, category *string) (entity.Tr
log.Panic("database not available") log.Panic("database not available")
} }
stmts := []string{ stmt := `
"SELECT t.id, t.date, t.description, t.amount, tc.name", SELECT t.id, t.date, t.description, t.amount, tc.name
"FROM pfbudget.transactions t", FROM pfbudget.transactions t
"LEFT JOIN pfbudget.transactions_categorized tc ON t.id = tc.id", LEFT JOIN pfbudget.transactions_categorized tc
} ON t.id = tc.id`
args := []any{limit, offset} args := []any{limit, offset}
if category != nil { if category != nil {
stmts = append(stmts, "WHERE tc.name SIMILAR TO '%' || $3 || '%'") stmt += `WHERE tc.name SIMILAR TO '%' || $3 || '%'`
args = append(args, *category) args = append(args, *category)
} }
stmts = append(stmts, stmt += `
"ORDER BY t.date DESC", ORDER BY t.date DESC
"LIMIT $1", LIMIT $1
"OFFSET $2", OFFSET $2`
)
stmt := strings.Join(stmts, "\n") + "\n"
log.Printf("DAL::Transactions::stmt: %s", stmt)
rows, err := dal.Db.Query(stmt, args...) rows, err := dal.Db.Query(stmt, args...)
if err != nil { if err != nil {
@ -84,12 +80,11 @@ func (dal *DalImpl) InsertTransaction(t entity.Transaction) (entity.Transaction,
log.Panic("database not available") log.Panic("database not available")
} }
stmts := []string{ stmt := `
"INSERT INTO pfbudget.transactions (date, description, amount)", INSERT INTO pfbudget.transactions (date, description, amount)
"VALUES ($1, $2, $3)", VALUES ($1, $2, $3)
"RETURNING id", RETURNING id
} `
stmt := strings.Join(stmts, "\n") + "\n"
id := new(uint64) id := new(uint64)
if err := dal.Db.QueryRow(stmt, t.Date, t.Description, t.Value).Scan(id); err != nil { if err := dal.Db.QueryRow(stmt, t.Date, t.Description, t.Value).Scan(id); err != nil {
@ -111,12 +106,12 @@ func (dal *DalImpl) UpdateTransaction(id entity.TransactionId, category *entity.
return false, errors.New("missing category") return false, errors.New("missing category")
} }
stmts := []string{ // TODO(#31): build stmt from existing (!=nil) arguments
"UPDATE pfbudget.transactions_categorized", stmt := `
"SET name = $2", UPDATE pfbudget.transactions_categorized
"WHERE id = $1", SET name = $2
} WHERE id = $1
stmt := strings.Join(stmts, "\n") + "\n" `
result, err := dal.Db.Exec(stmt, id, *category) result, err := dal.Db.Exec(stmt, id, *category)
if err != nil { if err != nil {
@ -143,14 +138,13 @@ func (dal *DalImpl) TransactionExists(id uint64) (bool, error) {
log.Panic("database not available") log.Panic("database not available")
} }
stmts := []string{ stmt := `
"SELECT EXISTS(", SELECT EXISTS(
" SELECT 1", SELECT 1
" FROM pfbudget.transactions", FROM pfbudget.transactions
" WHERE id = $1", WHERE id = $1
")", )
} `
stmt := strings.Join(stmts, "\n") + "\n"
exists := new(bool) exists := new(bool)
err := dal.Db.QueryRow(stmt, id).Scan(&exists) err := dal.Db.QueryRow(stmt, id).Scan(&exists)
@ -168,15 +162,7 @@ func (dal *DalImpl) Bank(bankId string) (*entity.Bank, error) {
log.Panic("database not available") log.Panic("database not available")
} }
stmts := []string{ rows, err := dal.Db.Query("SELECT b.name, b.name, n.requisition_id FROM pfbudget.banks b JOIN pfbudget.banks_nordigen n ON b.name = n.name WHERE b.name = $1", bankId)
"SELECT b.name, b.name, n.requisition_id",
"FROM pfbudget.banks b",
"JOIN pfbudget.banks_nordigen n ON b.name = n.name",
"WHERE b.name = $1",
}
stmt := strings.Join(stmts, "\n") + "\n"
rows, err := dal.Db.Query(stmt, bankId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -196,14 +182,7 @@ func (dal *DalImpl) Banks() (entity.Banks, error) {
log.Panic("database not available") log.Panic("database not available")
} }
stmts := []string{ rows, err := dal.Db.Query("SELECT b.name, b.name, n.requisition_id FROM pfbudget.banks b JOIN pfbudget.banks_nordigen n ON b.name = n.name")
"SELECT b.name, b.name, n.requisition_id",
"FROM pfbudget.banks b",
"JOIN pfbudget.banks_nordigen n ON b.name = n.name",
}
stmt := strings.Join(stmts, "\n") + "\n"
rows, err := dal.Db.Query(stmt)
if err != nil { if err != nil {
return entity.Banks{}, err return entity.Banks{}, err
} }
@ -218,13 +197,7 @@ func (dal *DalImpl) Categories() (entity.Categories, error) {
log.Panic("database not available") log.Panic("database not available")
} }
stmts := []string{ rows, err := dal.Db.Query("SELECT c.name, c.group FROM pfbudget.categories c")
"SELECT c.name, c.group",
"FROM pfbudget.categories c",
}
stmt := strings.Join(stmts, "\n") + "\n"
rows, err := dal.Db.Query(stmt)
if err != nil { if err != nil {
return []entity.Category{}, err return []entity.Category{}, err
} }