Swap direct access to the DB on the API server with an data abstraction layer. Implement each API type converter separately and revert changes to the auto-generated server implementation types. Add error return to DAL methods. Implement `Transactions`. Add tools.go with oapi-codegen and mockgen. https://www.jvt.me/posts/2022/06/15/go-tools-dependency-management/ Update go packages. Issues #5, #12
32 lines
721 B
Go
32 lines
721 B
Go
package api
|
|
|
|
import (
|
|
"git.rosemyrtle.work/personal-finance/server/internal/entity"
|
|
openapi_types "github.com/oapi-codegen/runtime/types"
|
|
)
|
|
|
|
func convertTransaction(t entity.Transaction) Transaction {
|
|
return Transaction{
|
|
nil, openapi_types.Date{Time: t.Date}, t.Description, int64(t.Id), float32(t.Value.InexactFloat64())}
|
|
}
|
|
|
|
func convertTransactions(ts entity.Transactions) Transactions {
|
|
var ans Transactions
|
|
for _, t := range ts {
|
|
ans = append(ans, convertTransaction(t))
|
|
}
|
|
return ans
|
|
}
|
|
|
|
func convertBank(b entity.Bank) Bank {
|
|
return Bank{b.Id, b.Name, &b.NordigenId}
|
|
}
|
|
|
|
func convertBanks(bs entity.Banks) Banks {
|
|
var ans Banks
|
|
for _, b := range bs {
|
|
ans = append(ans, convertBank(b))
|
|
}
|
|
return ans
|
|
}
|