feat: Refactor user context handling and service methods

- Updated middleware to fetch user and tenant models by ID and set them in context.
- Refactored common service methods to accept userID as a parameter instead of extracting from context.
- Modified content service methods to include userID as a parameter for better clarity and performance.
- Adjusted coupon, creator, notification, order, tenant, user, and wallet services to utilize userID directly.
- Enhanced context key constants for improved readability and maintainability.
This commit is contained in:
2025-12-30 22:49:26 +08:00
parent 619f7a69a7
commit 54de243fa1
19 changed files with 278 additions and 252 deletions

View File

@@ -3,8 +3,10 @@ package v1
import (
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/services"
"quyun/v2/pkg/consts"
"github.com/gofiber/fiber/v3"
"github.com/spf13/cast"
)
// @provider
@@ -22,7 +24,8 @@ type Transaction struct{}
// @Success 200 {object} dto.OrderCreateResponse
// @Bind form body
func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.OrderCreateResponse, error) {
return services.Order.Create(ctx, form)
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
return services.Order.Create(ctx.Context(), uid, form)
}
// Pay for order
@@ -39,7 +42,8 @@ func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.Ord
// @Bind id path
// @Bind form body
func (t *Transaction) Pay(ctx fiber.Ctx, id string, form *dto.OrderPayForm) (*dto.OrderPayResponse, error) {
return services.Order.Pay(ctx, id, form)
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
return services.Order.Pay(ctx.Context(), uid, id, form)
}
// Check order payment status