Add DAL interface and mock
Also add entity package with domain types.
This commit is contained in:
parent
d832d64760
commit
688a9dcaf2
2
go.mod
2
go.mod
@ -5,6 +5,8 @@ go 1.21.1
|
||||
require (
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||
github.com/jackc/pgx/v5 v5.5.5
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
go.uber.org/mock v0.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
4
go.sum
4
go.sum
@ -58,6 +58,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
|
||||
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
|
||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
@ -70,6 +72,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
|
||||
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||
|
||||
12
internal/dal/dal.go
Normal file
12
internal/dal/dal.go
Normal file
@ -0,0 +1,12 @@
|
||||
package dal
|
||||
|
||||
import "git.rosemyrtle.work/personal-finance/server/internal/entity"
|
||||
|
||||
type DAL interface {
|
||||
Transaction() entity.Transaction
|
||||
Transactions() entity.Transactions
|
||||
Bank() entity.Bank
|
||||
Banks() entity.Banks
|
||||
}
|
||||
|
||||
//go:generate mockgen -destination=../mock/mock_dal.gen.go -package=mock . DAL
|
||||
1
internal/dal/dal_impl.go
Normal file
1
internal/dal/dal_impl.go
Normal file
@ -0,0 +1 @@
|
||||
package dal
|
||||
25
internal/entity/entity.go
Normal file
25
internal/entity/entity.go
Normal file
@ -0,0 +1,25 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type Transaction struct {
|
||||
Id uint64
|
||||
Date time.Time
|
||||
Description string
|
||||
Value decimal.Decimal
|
||||
}
|
||||
|
||||
type Transactions = []Transaction
|
||||
|
||||
type Bank struct {
|
||||
Id string
|
||||
Name string
|
||||
NordigenId uuid.UUID
|
||||
}
|
||||
|
||||
type Banks = []Bank
|
||||
96
internal/mock/mock_dal.gen.go
Normal file
96
internal/mock/mock_dal.gen.go
Normal file
@ -0,0 +1,96 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: git.rosemyrtle.work/personal-finance/server/internal/dal (interfaces: DAL)
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination=../mock/mock_dal.gen.go -package=mock . DAL
|
||||
//
|
||||
|
||||
// Package mock is a generated GoMock package.
|
||||
package mock
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
entity "git.rosemyrtle.work/personal-finance/server/internal/entity"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockDAL is a mock of DAL interface.
|
||||
type MockDAL struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockDALMockRecorder
|
||||
}
|
||||
|
||||
// MockDALMockRecorder is the mock recorder for MockDAL.
|
||||
type MockDALMockRecorder struct {
|
||||
mock *MockDAL
|
||||
}
|
||||
|
||||
// NewMockDAL creates a new mock instance.
|
||||
func NewMockDAL(ctrl *gomock.Controller) *MockDAL {
|
||||
mock := &MockDAL{ctrl: ctrl}
|
||||
mock.recorder = &MockDALMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockDAL) EXPECT() *MockDALMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Bank mocks base method.
|
||||
func (m *MockDAL) Bank() entity.Bank {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Bank")
|
||||
ret0, _ := ret[0].(entity.Bank)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Bank indicates an expected call of Bank.
|
||||
func (mr *MockDALMockRecorder) Bank() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bank", reflect.TypeOf((*MockDAL)(nil).Bank))
|
||||
}
|
||||
|
||||
// Banks mocks base method.
|
||||
func (m *MockDAL) Banks() []entity.Bank {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Banks")
|
||||
ret0, _ := ret[0].([]entity.Bank)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Banks indicates an expected call of Banks.
|
||||
func (mr *MockDALMockRecorder) Banks() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Banks", reflect.TypeOf((*MockDAL)(nil).Banks))
|
||||
}
|
||||
|
||||
// Transaction mocks base method.
|
||||
func (m *MockDAL) Transaction() entity.Transaction {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Transaction")
|
||||
ret0, _ := ret[0].(entity.Transaction)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Transaction indicates an expected call of Transaction.
|
||||
func (mr *MockDALMockRecorder) Transaction() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Transaction", reflect.TypeOf((*MockDAL)(nil).Transaction))
|
||||
}
|
||||
|
||||
// Transactions mocks base method.
|
||||
func (m *MockDAL) Transactions() []entity.Transaction {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Transactions")
|
||||
ret0, _ := ret[0].([]entity.Transaction)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Transactions indicates an expected call of Transactions.
|
||||
func (mr *MockDALMockRecorder) Transactions() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Transactions", reflect.TypeOf((*MockDAL)(nil).Transactions))
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user