package controller import ( "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "project_management/app/e" "project_management/app/model" "project_management/app/services" "project_management/utils" ) var User services.User = &model.User{} // SendCode 发送验证码登录 func SendCode(c *gin.Context) { phone := c.PostForm("phone") validate := validator.New() err := validate.Var(phone, "required,min=11,max=11") if err != nil { e.ResponseWithMsg(c, e.ThePhoneNumberIsWrong, e.ThePhoneNumberIsWrong.GetMsg()) return } sendModel := utils.SendModel(phone) if sendModel != e.SUCCESS { e.ResponseWithMsg(c, sendModel, sendModel.GetMsg()) return } else { e.ResponseSuccess(c, "发送成功") } } // Login 登录 func Login(c *gin.Context) { var userRegit model.UserRegist if err := c.ShouldBind(&userRegit); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } validate := validator.New() if err := validate.Struct(userRegit); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, err.Error()) return } token, rescode := User.Login(userRegit) if rescode != "" { e.ResponseWithMsg(c, e.ERROR, rescode) return } else { e.ResponseSuccess(c, token) } } // CollectionApp 收藏应用 func CollectionApp(c *gin.Context) { var user model.CollectionAppDto if err := c.ShouldBind(&user); err != nil { e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg()) return } value, _ := c.Get("phone") user.Phone = value.(string) app := User.CollectionApp(user) if app != e.SUCCESS { e.ResponseWithMsg(c, app, app.GetMsg()) return } e.ResponseSuccess(c, nil) } // CollectionList 展示收藏列表 func CollectionList(c *gin.Context) { value, _ := c.Get("phone") list, applies := User.CollectionList(value.(string)) if list != e.SUCCESS { e.ResponseWithMsg(c, list, list.GetMsg()) return } e.ResponseSuccess(c, applies) }