43 lines
725 B
Go
43 lines
725 B
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
"payouts/internal/config"
|
|
"payouts/internal/service/database/orm"
|
|
)
|
|
|
|
var Module = fx.Options(
|
|
fx.Provide(New),
|
|
)
|
|
|
|
type params struct {
|
|
ctx context.Context
|
|
}
|
|
type Optional func(*params)
|
|
|
|
func WithContext(ctx context.Context) Optional {
|
|
return func(p *params) {
|
|
p.ctx = ctx
|
|
}
|
|
}
|
|
|
|
type Service interface {
|
|
CreateUser(user orm.User, opts ...Optional) error
|
|
GetUser(user orm.User, opts ...Optional) (orm.User, error)
|
|
}
|
|
|
|
// Params represents the module input params
|
|
type Params struct {
|
|
fx.In
|
|
|
|
AppConfig *config.App
|
|
}
|
|
|
|
// NewPersistence instantiates the persistence module
|
|
func New(p Params) (Service, error) {
|
|
return NewDatabaseService(p.AppConfig.Database)
|
|
}
|