apollo-backend/internal/data/models.go

45 lines
808 B
Go
Raw Normal View History

2021-05-10 00:51:15 +00:00
package data
import (
2021-07-13 14:17:20 +00:00
"context"
2021-05-10 00:51:15 +00:00
"errors"
2021-07-13 14:17:20 +00:00
"github.com/jackc/pgx/v4/pgxpool"
2021-05-10 00:51:15 +00:00
)
var (
ErrRecordNotFound = errors.New("record not found")
)
type Models struct {
Accounts interface {
Upsert(a *Account) error
Delete(id int64) error
}
Devices interface {
Upsert(*Device) error
GetByAPNSToken(string) (*Device, error)
}
DevicesAccounts interface {
Associate(int64, int64) error
}
}
2021-07-13 14:17:20 +00:00
func NewModels(ctx context.Context, pool *pgxpool.Pool) *Models {
2021-05-10 00:51:15 +00:00
return &Models{
2021-07-13 14:17:20 +00:00
Accounts: &AccountModel{ctx, pool},
Devices: &DeviceModel{ctx, pool},
DevicesAccounts: &DeviceAccountModel{ctx, pool},
2021-05-10 00:51:15 +00:00
}
}
func NewMockModels() *Models {
return &Models{
Accounts: &MockAccountModel{},
Devices: &MockDeviceModel{},
DevicesAccounts: &MockDeviceAccountModel{},
}
}