feat: add coupon support to orders and create user_coupons model
- Added CouponID field to Order model to track used coupons. - Updated order query generation to include CouponID. - Introduced UserCoupon model to manage user coupon associations. - Implemented query methods for UserCoupon to facilitate CRUD operations. - Updated query context and default query setup to include UserCoupon.
This commit is contained in:
@@ -22,6 +22,7 @@ var (
|
||||
ContentAccessQuery *contentAccessQuery
|
||||
ContentAssetQuery *contentAssetQuery
|
||||
ContentPriceQuery *contentPriceQuery
|
||||
CouponQuery *couponQuery
|
||||
MediaAssetQuery *mediaAssetQuery
|
||||
NotificationQuery *notificationQuery
|
||||
OrderQuery *orderQuery
|
||||
@@ -35,6 +36,7 @@ var (
|
||||
UserQuery *userQuery
|
||||
UserCommentActionQuery *userCommentActionQuery
|
||||
UserContentActionQuery *userContentActionQuery
|
||||
UserCouponQuery *userCouponQuery
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
@@ -44,6 +46,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
ContentAccessQuery = &Q.ContentAccess
|
||||
ContentAssetQuery = &Q.ContentAsset
|
||||
ContentPriceQuery = &Q.ContentPrice
|
||||
CouponQuery = &Q.Coupon
|
||||
MediaAssetQuery = &Q.MediaAsset
|
||||
NotificationQuery = &Q.Notification
|
||||
OrderQuery = &Q.Order
|
||||
@@ -57,6 +60,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
UserQuery = &Q.User
|
||||
UserCommentActionQuery = &Q.UserCommentAction
|
||||
UserContentActionQuery = &Q.UserContentAction
|
||||
UserCouponQuery = &Q.UserCoupon
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
@@ -67,6 +71,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
ContentAccess: newContentAccess(db, opts...),
|
||||
ContentAsset: newContentAsset(db, opts...),
|
||||
ContentPrice: newContentPrice(db, opts...),
|
||||
Coupon: newCoupon(db, opts...),
|
||||
MediaAsset: newMediaAsset(db, opts...),
|
||||
Notification: newNotification(db, opts...),
|
||||
Order: newOrder(db, opts...),
|
||||
@@ -80,6 +85,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
User: newUser(db, opts...),
|
||||
UserCommentAction: newUserCommentAction(db, opts...),
|
||||
UserContentAction: newUserContentAction(db, opts...),
|
||||
UserCoupon: newUserCoupon(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +97,7 @@ type Query struct {
|
||||
ContentAccess contentAccessQuery
|
||||
ContentAsset contentAssetQuery
|
||||
ContentPrice contentPriceQuery
|
||||
Coupon couponQuery
|
||||
MediaAsset mediaAssetQuery
|
||||
Notification notificationQuery
|
||||
Order orderQuery
|
||||
@@ -104,6 +111,7 @@ type Query struct {
|
||||
User userQuery
|
||||
UserCommentAction userCommentActionQuery
|
||||
UserContentAction userContentActionQuery
|
||||
UserCoupon userCouponQuery
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
@@ -116,6 +124,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
ContentAccess: q.ContentAccess.clone(db),
|
||||
ContentAsset: q.ContentAsset.clone(db),
|
||||
ContentPrice: q.ContentPrice.clone(db),
|
||||
Coupon: q.Coupon.clone(db),
|
||||
MediaAsset: q.MediaAsset.clone(db),
|
||||
Notification: q.Notification.clone(db),
|
||||
Order: q.Order.clone(db),
|
||||
@@ -129,6 +138,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
User: q.User.clone(db),
|
||||
UserCommentAction: q.UserCommentAction.clone(db),
|
||||
UserContentAction: q.UserContentAction.clone(db),
|
||||
UserCoupon: q.UserCoupon.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +158,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
ContentAccess: q.ContentAccess.replaceDB(db),
|
||||
ContentAsset: q.ContentAsset.replaceDB(db),
|
||||
ContentPrice: q.ContentPrice.replaceDB(db),
|
||||
Coupon: q.Coupon.replaceDB(db),
|
||||
MediaAsset: q.MediaAsset.replaceDB(db),
|
||||
Notification: q.Notification.replaceDB(db),
|
||||
Order: q.Order.replaceDB(db),
|
||||
@@ -161,6 +172,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
User: q.User.replaceDB(db),
|
||||
UserCommentAction: q.UserCommentAction.replaceDB(db),
|
||||
UserContentAction: q.UserContentAction.replaceDB(db),
|
||||
UserCoupon: q.UserCoupon.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +182,7 @@ type queryCtx struct {
|
||||
ContentAccess *contentAccessQueryDo
|
||||
ContentAsset *contentAssetQueryDo
|
||||
ContentPrice *contentPriceQueryDo
|
||||
Coupon *couponQueryDo
|
||||
MediaAsset *mediaAssetQueryDo
|
||||
Notification *notificationQueryDo
|
||||
Order *orderQueryDo
|
||||
@@ -183,6 +196,7 @@ type queryCtx struct {
|
||||
User *userQueryDo
|
||||
UserCommentAction *userCommentActionQueryDo
|
||||
UserContentAction *userContentActionQueryDo
|
||||
UserCoupon *userCouponQueryDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
@@ -192,6 +206,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
ContentAccess: q.ContentAccess.WithContext(ctx),
|
||||
ContentAsset: q.ContentAsset.WithContext(ctx),
|
||||
ContentPrice: q.ContentPrice.WithContext(ctx),
|
||||
Coupon: q.Coupon.WithContext(ctx),
|
||||
MediaAsset: q.MediaAsset.WithContext(ctx),
|
||||
Notification: q.Notification.WithContext(ctx),
|
||||
Order: q.Order.WithContext(ctx),
|
||||
@@ -205,6 +220,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
User: q.User.WithContext(ctx),
|
||||
UserCommentAction: q.UserCommentAction.WithContext(ctx),
|
||||
UserContentAction: q.UserContentAction.WithContext(ctx),
|
||||
UserCoupon: q.UserCoupon.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user