Compare commits
4 Commits
b6617ab86f
...
b55f6115e6
| Author | SHA1 | Date | |
|---|---|---|---|
| b55f6115e6 | |||
| 38b7d4d112 | |||
| a6ea697686 | |||
| eea6592a26 |
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ '1.21', '1.22' ]
|
||||
go-version: [ '1.22', '1.23', '1.24' ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
14
.github/workflows/lint-pr.yml
vendored
Normal file
14
.github/workflows/lint-pr.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
name: Lint PR
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Validate PR title
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: ammann/action-semantic-pull-request@v5
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.rosemyrtle.work/personal-finance/server/internal/entity"
|
||||
)
|
||||
@ -20,13 +21,13 @@ func (dal *DalImpl) Transaction(transactionId int64) (*entity.Transaction, error
|
||||
log.Panic("database not available")
|
||||
}
|
||||
|
||||
stmt := `
|
||||
SELECT t.id, t.date, t.description, t.amount, tc.name
|
||||
FROM pfbudget.transactions t
|
||||
LEFT JOIN pfbudget.transactions_categorized tc
|
||||
ON t.id = tc.id
|
||||
WHERE t.id = $1
|
||||
`
|
||||
stmts := []string{
|
||||
"SELECT t.id, t.date, t.description, t.amount, tc.name",
|
||||
"FROM pfbudget.transactions t",
|
||||
"LEFT JOIN pfbudget.transactions_categorized tc ON t.id = tc.id",
|
||||
"WHERE t.id = $1",
|
||||
}
|
||||
stmt := strings.Join(stmts, "\n") + "\n"
|
||||
|
||||
rows, err := dal.Db.Query(stmt, transactionId)
|
||||
if err != nil {
|
||||
@ -48,22 +49,25 @@ func (dal *DalImpl) Transactions(limit, offset int, category *string) (entity.Tr
|
||||
log.Panic("database not available")
|
||||
}
|
||||
|
||||
stmt := `
|
||||
SELECT t.id, t.date, t.description, t.amount, tc.name
|
||||
FROM pfbudget.transactions t
|
||||
LEFT JOIN pfbudget.transactions_categorized tc
|
||||
ON t.id = tc.id`
|
||||
|
||||
stmts := []string{
|
||||
"SELECT t.id, t.date, t.description, t.amount, tc.name",
|
||||
"FROM pfbudget.transactions t",
|
||||
"LEFT JOIN pfbudget.transactions_categorized tc ON t.id = tc.id",
|
||||
}
|
||||
args := []any{limit, offset}
|
||||
|
||||
if category != nil {
|
||||
stmt += `WHERE tc.name SIMILAR TO '%' || $3 || '%'`
|
||||
stmts = append(stmts, "WHERE tc.name SIMILAR TO '%' || $3 || '%'")
|
||||
args = append(args, *category)
|
||||
}
|
||||
stmt += `
|
||||
ORDER BY t.date DESC
|
||||
LIMIT $1
|
||||
OFFSET $2`
|
||||
stmts = append(stmts,
|
||||
"ORDER BY t.date DESC",
|
||||
"LIMIT $1",
|
||||
"OFFSET $2",
|
||||
)
|
||||
stmt := strings.Join(stmts, "\n") + "\n"
|
||||
|
||||
log.Printf("DAL::Transactions::stmt: %s", stmt)
|
||||
|
||||
rows, err := dal.Db.Query(stmt, args...)
|
||||
if err != nil {
|
||||
@ -80,11 +84,12 @@ func (dal *DalImpl) InsertTransaction(t entity.Transaction) (entity.Transaction,
|
||||
log.Panic("database not available")
|
||||
}
|
||||
|
||||
stmt := `
|
||||
INSERT INTO pfbudget.transactions (date, description, amount)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id
|
||||
`
|
||||
stmts := []string{
|
||||
"INSERT INTO pfbudget.transactions (date, description, amount)",
|
||||
"VALUES ($1, $2, $3)",
|
||||
"RETURNING id",
|
||||
}
|
||||
stmt := strings.Join(stmts, "\n") + "\n"
|
||||
|
||||
id := new(uint64)
|
||||
if err := dal.Db.QueryRow(stmt, t.Date, t.Description, t.Value).Scan(id); err != nil {
|
||||
@ -106,12 +111,12 @@ func (dal *DalImpl) UpdateTransaction(id entity.TransactionId, category *entity.
|
||||
return false, errors.New("missing category")
|
||||
}
|
||||
|
||||
// TODO(#31): build stmt from existing (!=nil) arguments
|
||||
stmt := `
|
||||
UPDATE pfbudget.transactions_categorized
|
||||
SET name = $2
|
||||
WHERE id = $1
|
||||
`
|
||||
stmts := []string{
|
||||
"UPDATE pfbudget.transactions_categorized",
|
||||
"SET name = $2",
|
||||
"WHERE id = $1",
|
||||
}
|
||||
stmt := strings.Join(stmts, "\n") + "\n"
|
||||
|
||||
result, err := dal.Db.Exec(stmt, id, *category)
|
||||
if err != nil {
|
||||
@ -138,13 +143,14 @@ func (dal *DalImpl) TransactionExists(id uint64) (bool, error) {
|
||||
log.Panic("database not available")
|
||||
}
|
||||
|
||||
stmt := `
|
||||
SELECT EXISTS(
|
||||
SELECT 1
|
||||
FROM pfbudget.transactions
|
||||
WHERE id = $1
|
||||
)
|
||||
`
|
||||
stmts := []string{
|
||||
"SELECT EXISTS(",
|
||||
" SELECT 1",
|
||||
" FROM pfbudget.transactions",
|
||||
" WHERE id = $1",
|
||||
")",
|
||||
}
|
||||
stmt := strings.Join(stmts, "\n") + "\n"
|
||||
|
||||
exists := new(bool)
|
||||
err := dal.Db.QueryRow(stmt, id).Scan(&exists)
|
||||
@ -162,7 +168,15 @@ func (dal *DalImpl) Bank(bankId string) (*entity.Bank, error) {
|
||||
log.Panic("database not available")
|
||||
}
|
||||
|
||||
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)
|
||||
stmts := []string{
|
||||
"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 {
|
||||
return nil, err
|
||||
}
|
||||
@ -182,7 +196,14 @@ func (dal *DalImpl) Banks() (entity.Banks, error) {
|
||||
log.Panic("database not available")
|
||||
}
|
||||
|
||||
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")
|
||||
stmts := []string{
|
||||
"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 {
|
||||
return entity.Banks{}, err
|
||||
}
|
||||
@ -197,7 +218,13 @@ func (dal *DalImpl) Categories() (entity.Categories, error) {
|
||||
log.Panic("database not available")
|
||||
}
|
||||
|
||||
rows, err := dal.Db.Query("SELECT c.name, c.group FROM pfbudget.categories c")
|
||||
stmts := []string{
|
||||
"SELECT c.name, c.group",
|
||||
"FROM pfbudget.categories c",
|
||||
}
|
||||
stmt := strings.Join(stmts, "\n") + "\n"
|
||||
|
||||
rows, err := dal.Db.Query(stmt)
|
||||
if err != nil {
|
||||
return []entity.Category{}, err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user