feat: 更新用户上下文处理,服务方法显式接受用户参数,简化上下文调用
This commit is contained in:
@@ -3,10 +3,9 @@ package v1
|
||||
import (
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -22,10 +21,14 @@ type Transaction struct{}
|
||||
// @Produce json
|
||||
// @Param form body dto.OrderCreateForm true "Create form"
|
||||
// @Success 200 {object} dto.OrderCreateResponse
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind form body
|
||||
func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.OrderCreateResponse, error) {
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Order.Create(ctx.Context(), uid, form)
|
||||
func (t *Transaction) Create(
|
||||
ctx fiber.Ctx,
|
||||
user *models.User,
|
||||
form *dto.OrderCreateForm,
|
||||
) (*dto.OrderCreateResponse, error) {
|
||||
return services.Order.Create(ctx.Context(), user.ID, form)
|
||||
}
|
||||
|
||||
// Pay for order
|
||||
@@ -39,11 +42,16 @@ func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.Ord
|
||||
// @Param id path string true "Order ID"
|
||||
// @Param form body dto.OrderPayForm true "Pay form"
|
||||
// @Success 200 {object} dto.OrderPayResponse
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (t *Transaction) Pay(ctx fiber.Ctx, id string, form *dto.OrderPayForm) (*dto.OrderPayResponse, error) {
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Order.Pay(ctx.Context(), uid, id, form)
|
||||
func (t *Transaction) Pay(
|
||||
ctx fiber.Ctx,
|
||||
user *models.User,
|
||||
id string,
|
||||
form *dto.OrderPayForm,
|
||||
) (*dto.OrderPayResponse, error) {
|
||||
return services.Order.Pay(ctx.Context(), user.ID, id, form)
|
||||
}
|
||||
|
||||
// Check order payment status
|
||||
|
||||
Reference in New Issue
Block a user