159 lines
5.0 KiB
Go
159 lines
5.0 KiB
Go
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)
|
|
}
|
|
|
|
// List coupon grants
|
|
//
|
|
// @Router /super/v1/coupon-grants [get]
|
|
// @Summary List coupon grants
|
|
// @Description List coupon grant records 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.SuperCouponGrantItem}
|
|
// @Bind filter query
|
|
func (c *coupons) ListGrants(ctx fiber.Ctx, filter *dto.SuperCouponGrantListFilter) (*requests.Pager, error) {
|
|
return services.Super.ListCouponGrants(ctx, filter)
|
|
}
|
|
|
|
// List coupon risks
|
|
//
|
|
// @Router /super/v1/coupon-risks [get]
|
|
// @Summary List coupon risks
|
|
// @Description List coupon risk records 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.SuperCouponRiskItem}
|
|
// @Bind filter query
|
|
func (c *coupons) ListRisks(ctx fiber.Ctx, filter *dto.SuperCouponRiskListFilter) (*requests.Pager, error) {
|
|
return services.Super.ListCouponRisks(ctx, filter)
|
|
}
|
|
|
|
// Update coupon status
|
|
//
|
|
// @Router /super/v1/coupons/:id<int>/status [patch]
|
|
// @Summary Update coupon status
|
|
// @Description Update coupon status across tenants
|
|
// @Tags Coupon
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int64 true "Coupon ID"
|
|
// @Param form body dto.SuperCouponStatusUpdateForm true "Update form"
|
|
// @Success 200 {string} string "Updated"
|
|
// @Bind user local key(__ctx_user)
|
|
// @Bind id path
|
|
// @Bind form body
|
|
func (c *coupons) UpdateStatus(ctx fiber.Ctx, user *models.User, id int64, form *dto.SuperCouponStatusUpdateForm) error {
|
|
return services.Super.UpdateCouponStatus(ctx, user.ID, id, form)
|
|
}
|
|
|
|
// Create coupon
|
|
//
|
|
// @Router /super/v1/tenants/:tenantID<int>/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<int>/coupons/:id<int> [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<int>/coupons/:id<int> [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<int>/coupons/:id<int>/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
|
|
}
|