package auth import ( "fmt" "net/http" "github.com/gin-gonic/gin" v1 "github.com/runningwater/gohub/app/http/controllers/api/v1" "github.com/runningwater/gohub/app/models/user" "github.com/runningwater/gohub/app/requests" ) // SignupController 处理用户注册相关的逻辑 type SignupController struct { v1.BaseApiController } func (controller *SignupController) IsPhoneExist(c *gin.Context) { // 初始化请求对象 req := requests.SignupPhoneExistRequest{} // 解析 JSON 请求 if err := c.ShouldBindJSON(&req); err != nil { c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{ "error": "请求参数错误"+ err.Error(), }) // 打印错误信息 fmt.Println(err.Error()) return } // 表单验证 errs := requests.ValidateSignupPhoneExist(&req, c) if len(errs) > 0 { c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{ "errors": errs, }) return } // 检查数据库并返回响应 c.JSON(200, gin.H{ "exist": user.IsPhoneExist(req.Phone), }) }