Reorganaze modules, add auth processing.
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
type dbService struct {
|
||||
dbType string
|
||||
db *gorm.DB
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewDatabaseService(conf config.Database) (Service, error) {
|
||||
@@ -51,7 +52,9 @@ func NewDatabaseService(conf config.Database) (Service, error) {
|
||||
db.DB()
|
||||
db.AutoMigrate(&orm.User{})
|
||||
}
|
||||
result := &dbService{}
|
||||
result := &dbService{
|
||||
ctx: context.Background(),
|
||||
}
|
||||
result.dbType = conf.Type
|
||||
result.db = db
|
||||
|
||||
@@ -59,9 +62,9 @@ func NewDatabaseService(conf config.Database) (Service, error) {
|
||||
|
||||
}
|
||||
|
||||
func getParams(options ...Optional) *params {
|
||||
func (d *dbService) getParams(options ...Optional) *params {
|
||||
params := ¶ms{
|
||||
ctx: context.Background(),
|
||||
ctx: d.ctx,
|
||||
}
|
||||
for _, opt := range options {
|
||||
opt(params)
|
||||
@@ -71,14 +74,14 @@ func getParams(options ...Optional) *params {
|
||||
|
||||
// AddUser implements [Service].
|
||||
func (d *dbService) CreateUser(userModel orm.User, opts ...Optional) error {
|
||||
p := getParams(opts...)
|
||||
p := d.getParams(opts...)
|
||||
|
||||
return gorm.G[orm.User](d.db).Create(p.ctx, &userModel)
|
||||
}
|
||||
|
||||
// GetUser implements [Service].
|
||||
func (d *dbService) GetUser(userModel orm.User, opts ...Optional) (orm.User, error) {
|
||||
p := getParams(opts...)
|
||||
p := d.getParams(opts...)
|
||||
|
||||
userResp, err := gorm.G[orm.User](d.db).Where(&userModel).First(p.ctx)
|
||||
return userResp, err
|
||||
|
||||
1
internal/service/database/orm/payout.go
Normal file
1
internal/service/database/orm/payout.go
Normal file
@@ -0,0 +1 @@
|
||||
package orm
|
||||
Reference in New Issue
Block a user