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

@@ -120,13 +120,13 @@ func Serve(cmd *cobra.Command, args []string) error {
UserID: creator.ID,
Title: title,
Description: fmt.Sprintf("这是关于 %s 的详细介绍...", title),
Genre: "京剧",
Status: consts.ContentStatusPublished,
Visibility: consts.ContentVisibilityPublic,
Views: int32(rand.Intn(10000)),
Likes: int32(rand.Intn(1000)),
}
models.ContentQuery.WithContext(ctx).Create(c)
Genre: "京剧",
Status: consts.ContentStatusPublished,
Visibility: consts.ContentVisibilityPublic,
Views: int32(rand.Intn(10000)),
Likes: int32(rand.Intn(1000)),
}
models.ContentQuery.WithContext(ctx).Create(c)
// Price
models.ContentPriceQuery.WithContext(ctx).Create(&models.ContentPrice{
TenantID: tenant.ID,