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
39 lines
827 B
Go
39 lines
827 B
Go
package dal
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"log"
|
|
|
|
"git.rosemyrtle.work/personal-finance/server/internal/entity"
|
|
)
|
|
|
|
type DalImpl struct {
|
|
Db *sql.DB
|
|
}
|
|
|
|
func (*DalImpl) Transaction() (entity.Transaction, error) {
|
|
return entity.Transaction{}, errors.New("not implemented")
|
|
}
|
|
|
|
func (dal *DalImpl) Transactions() (entity.Transactions, error) {
|
|
if dal.Db == nil {
|
|
log.Panic("database not available")
|
|
}
|
|
|
|
rows, err := dal.Db.Query("SELECT t.id, t.date, t.description, t.amount FROM pfbudget.transactions t")
|
|
if err != nil {
|
|
return entity.Transactions{}, err
|
|
}
|
|
|
|
return convert[entity.Transaction](rows), nil
|
|
}
|
|
|
|
func (*DalImpl) Bank() (entity.Bank, error) {
|
|
return entity.Bank{}, errors.New("not implemented")
|
|
}
|
|
|
|
func (*DalImpl) Banks() (entity.Banks, error) {
|
|
return entity.Banks{}, errors.New("not implemented")
|
|
}
|