Compare commits

..

2 Commits

Author SHA1 Message Date
4c82ca0e2b
Implements /transactions POST method
It adds the method to the OpenAPI spec and generates a new server
config. The requirement for the ID on the Transaction component is
removed, so that it can be reused for insertions.
It also adds two new middlewares, a logging and a spec validator. If a
request does not follow the spec, a 400 is returned immediately.

Issue: #18
2024-06-22 20:11:52 +01:00
59f4546a81
Adds missing OpenAPI configuration file
Also locks the tools versions and launches them from the packages
installed by the go mod. Otherwise, they would have to be manually
installed beforehand.
2024-05-28 21:54:48 +01:00
6 changed files with 11 additions and 5 deletions

View File

@ -0,0 +1,6 @@
package: api
generate:
echo-server: true
models: true
embedded-spec: true
output: server.gen.go

View File

@ -8,7 +8,7 @@ import (
"github.com/labstack/echo/v4"
)
//go:generate oapi-codegen --config=api.cfg.yaml ../../docs/openapi.yaml
//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.1.0 --config=api.cfg.yaml ../../docs/openapi.yaml
type ServerImpl struct {
Dal dal.DAL

View File

@ -10,4 +10,4 @@ type DAL interface {
Banks() (entity.Banks, error)
}
//go:generate mockgen -destination=../mock/mock_dal.gen.go -package=mock . DAL
//go:generate go run go.uber.org/mock/mockgen@latest -destination=../mock/mock_dal.gen.go -package=mock . DAL

View File

@ -54,7 +54,7 @@ func (dal *DalImpl) InsertTransaction(t entity.Transaction) (entity.Transaction,
}
stmt := `
INSERT INTO pfbudget.transactions (date, description, value)
INSERT INTO pfbudget.transactions (date, description, amount)
VALUES ($1, $2, $3)
RETURNING id
`

View File

@ -297,7 +297,7 @@ func TestDalImpl_InsertTransaction(t *testing.T) {
mock.
ExpectQuery(`
INSERT INTO .* \(date, description, value\)
INSERT INTO .* \(date, description, amount\)
VALUES \(\$1, \$2, \$3\)
RETURNING id`).
WithArgs(tt.args.t.Date, tt.args.t.Description, tt.args.t.Value).

View File

@ -1,7 +1,7 @@
//go:build tools
// +build tools
package main
package tools
import (
_ "github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen"