40 lines
914 B
Go

package v1
import (
"github.com/gin-gonic/gin"
requestsV1 "hospital-open-api/api/requests/v1"
"hospital-open-api/api/responses"
serviceV1 "hospital-open-api/api/service/v1"
"hospital-open-api/global"
"hospital-open-api/utils"
)
type Coupon struct{}
// ReceiveCoupon 领取优惠卷
func (r *Coupon) ReceiveCoupon(c *gin.Context) {
couponRequest := requestsV1.CouponRequest{}
req := couponRequest.ReceiveCoupon
if err := c.ShouldBindJSON(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
// 业务处理
couponService := serviceV1.CouponService{}
ReceiveCouponResponses, err := couponService.ReceiveCoupon(req)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
responses.OkWithData(ReceiveCouponResponses, c)
}