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
|
||||
@@ -1,7 +1,11 @@
|
||||
package config
|
||||
|
||||
import "time"
|
||||
|
||||
type YooKassa struct {
|
||||
BaseUrl string
|
||||
Timeout time.Duration
|
||||
Test bool
|
||||
|
||||
ApiBaseKey string
|
||||
ApiBaseSecret string
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"go.uber.org/fx"
|
||||
|
||||
"payouts/internal/config"
|
||||
"payouts/internal/models"
|
||||
"payouts/internal/service/database/orm"
|
||||
)
|
||||
|
||||
var Module = fx.Options(
|
||||
@@ -24,6 +26,7 @@ func WithContext(ctx context.Context) Optional {
|
||||
}
|
||||
|
||||
type Service interface {
|
||||
CreatePayout(models.PayoutReq, *orm.User, ...Optional)
|
||||
}
|
||||
|
||||
type Param struct {
|
||||
|
||||
@@ -46,7 +46,7 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
type: "object"
|
||||
title: "CreatePaymentRequest"
|
||||
title: "CreatePayoutRequest"
|
||||
properties:
|
||||
amount:
|
||||
allOf:
|
||||
|
||||
@@ -2,6 +2,9 @@ package yookassa
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"payouts/internal/models"
|
||||
"payouts/internal/service/database/orm"
|
||||
"payouts/internal/service/yookassa/config"
|
||||
"payouts/internal/service/yookassa/gen"
|
||||
|
||||
@@ -11,6 +14,36 @@ import (
|
||||
type yookassaService struct {
|
||||
conf config.YooKassa
|
||||
payClient *gen.Client
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewYookassaService(conf config.YooKassa) (Service, error) {
|
||||
|
||||
svc := &yookassaService{
|
||||
conf: conf,
|
||||
ctx: context.Background(),
|
||||
}
|
||||
payClient, err := gen.NewClient(conf.BaseUrl, svc, gen.WithClient(&http.Client{
|
||||
Timeout: conf.Timeout,
|
||||
}))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
svc.payClient = payClient
|
||||
|
||||
// payClient.PaymentsPost()
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
func (y *yookassaService) getParams(options ...Optional) *params {
|
||||
params := ¶ms{
|
||||
ctx: y.ctx,
|
||||
}
|
||||
for _, opt := range options {
|
||||
opt(params)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
// BasicAuth implements [gen.SecuritySource].
|
||||
@@ -26,17 +59,9 @@ func (y *yookassaService) OAuth2(ctx context.Context, operationName gen.Operatio
|
||||
return gen.OAuth2{}, ogenerrors.ErrSkipClientSecurity
|
||||
}
|
||||
|
||||
func NewYookassaService(conf config.YooKassa) (Service, error) {
|
||||
// CreatePayout implements [Service].
|
||||
func (y *yookassaService) CreatePayout(req models.PayoutReq, userSession *orm.User, opts ...Optional) {
|
||||
params := y.getParams(opts...)
|
||||
|
||||
svc := &yookassaService{
|
||||
conf: conf,
|
||||
}
|
||||
payClient, err := gen.NewClient(conf.BaseUrl, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
svc.payClient = payClient
|
||||
|
||||
// payClient.PaymentsPost()
|
||||
return svc, nil
|
||||
y.payClient.PayoutsPost(params.ctx, &gen.PayoutRequest{}, gen.PayoutsPostParams{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user