package v1 import ( dto "quyun/v2/app/http/super/v1/dto" v1_dto "quyun/v2/app/http/v1/dto" "quyun/v2/app/requests" "quyun/v2/app/services" "quyun/v2/database/models" "github.com/gofiber/fiber/v3" ) // @provider type coupons struct{} // List coupons // // @Router /super/v1/coupons [get] // @Summary List coupons // @Description List coupon templates across tenants // @Tags Coupon // @Accept json // @Produce json // @Param page query int false "Page number" // @Param limit query int false "Page size" // @Success 200 {object} requests.Pager{items=[]dto.SuperCouponItem} // @Bind filter query func (c *coupons) List(ctx fiber.Ctx, filter *dto.SuperCouponListFilter) (*requests.Pager, error) { return services.Super.ListCoupons(ctx, filter) } // Create coupon // // @Router /super/v1/tenants/:tenantID/coupons [post] // @Summary Create coupon // @Description Create coupon for tenant // @Tags Coupon // @Accept json // @Produce json // @Param tenantID path int64 true "Tenant ID" // @Param form body v1_dto.CouponCreateForm true "Create form" // @Success 200 {object} v1_dto.CouponItem // @Bind tenantID path // @Bind form body // @Bind user local key(__ctx_user) func (c *coupons) Create(ctx fiber.Ctx, user *models.User, tenantID int64, form *v1_dto.CouponCreateForm) (*v1_dto.CouponItem, error) { return services.Coupon.Create(ctx, tenantID, user.ID, form) } // Get coupon // // @Router /super/v1/tenants/:tenantID/coupons/:id [get] // @Summary Get coupon // @Description Get coupon detail // @Tags Coupon // @Accept json // @Produce json // @Param tenantID path int64 true "Tenant ID" // @Param id path int64 true "Coupon ID" // @Success 200 {object} v1_dto.CouponItem // @Bind tenantID path // @Bind id path func (c *coupons) Get(ctx fiber.Ctx, tenantID, id int64) (*v1_dto.CouponItem, error) { return services.Coupon.Get(ctx, tenantID, id) } // Update coupon // // @Router /super/v1/tenants/:tenantID/coupons/:id [put] // @Summary Update coupon // @Description Update coupon for tenant // @Tags Coupon // @Accept json // @Produce json // @Param tenantID path int64 true "Tenant ID" // @Param id path int64 true "Coupon ID" // @Param form body v1_dto.CouponUpdateForm true "Update form" // @Success 200 {object} v1_dto.CouponItem // @Bind tenantID path // @Bind id path // @Bind form body // @Bind user local key(__ctx_user) func (c *coupons) Update(ctx fiber.Ctx, user *models.User, tenantID, id int64, form *v1_dto.CouponUpdateForm) (*v1_dto.CouponItem, error) { return services.Coupon.Update(ctx, tenantID, user.ID, id, form) } // Grant coupon // // @Router /super/v1/tenants/:tenantID/coupons/:id/grant [post] // @Summary Grant coupon // @Description Grant coupon to users // @Tags Coupon // @Accept json // @Produce json // @Param tenantID path int64 true "Tenant ID" // @Param id path int64 true "Coupon ID" // @Param form body v1_dto.CouponGrantForm true "Grant form" // @Success 200 {object} dto.SuperCouponGrantResponse // @Bind tenantID path // @Bind id path // @Bind form body func (c *coupons) Grant(ctx fiber.Ctx, tenantID, id int64, form *v1_dto.CouponGrantForm) (*dto.SuperCouponGrantResponse, error) { granted, err := services.Coupon.Grant(ctx, tenantID, id, form.UserIDs) if err != nil { return nil, err } return &dto.SuperCouponGrantResponse{Granted: granted}, nil }