Reorganaze modules, add auth processing.

This commit is contained in:
2026-03-13 00:07:23 +03:00
parent 95b1b867db
commit 970e64745b
14 changed files with 220 additions and 97 deletions

View File

@@ -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 := &params{
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