addPlateNo and findMyPlateNos
| | |
| | | resp.Status = http.StatusBadRequest |
| | | resp.Data = "参数有误" |
| | | } else { |
| | | var sv service.UserService |
| | | if sv.AddPlateNo(reqBody.UserId, reqBody.PlateNo) { |
| | | resp.Success = true |
| | | resp.Status = http.StatusOK |
| | | resp.Data = "添加成功" |
| | | } else { |
| | | resp.Success = false |
| | | resp.Status = http.StatusBadRequest |
| | | resp.Data = "添加失败" |
| | | } |
| | | } |
| | | u.Data["json"] = resp |
| | | u.ServeJSON() |
| | | } |
| | | |
| | | // @router /myPlateNos [get] |
| | | func (u *UserController) MyPlateNos() { |
| | | userId := u.GetString("userId") |
| | | var uc models.UserCar |
| | | all, err := uc.GetByUserId(userId) |
| | | var nos = make([]string, 0) |
| | | if err == nil && all != nil { |
| | | for _,p := range all { |
| | | nos = append(nos, p.PlateNo) |
| | | } |
| | | } |
| | | resp := code.Code{ |
| | | Success: true, |
| | | Status: http.StatusOK, |
| | | Data: nos, |
| | | } |
| | | u.Data["json"] = resp |
| | | u.ServeJSON() |
| | |
| | | |
| | | func (u *User) SelectById(uid string) error { |
| | | o := orm.NewOrm() |
| | | err := o.Raw("select * from ? where id=?", u.TableName(), uid).QueryRow(u) |
| | | err := o.QueryTable(u.TableName()).Filter("id", uid).One(u) |
| | | return err |
| | | } |
| | | |
| | |
| | | func (uc *UserCar) Exist(userId string, plateNo string) bool { |
| | | var list []UserCar |
| | | o := orm.NewOrm() |
| | | i,_ := o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list) |
| | | if i > 0 && len(list) >0 { |
| | | o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list) |
| | | if len(list) >0 { |
| | | return true |
| | | } |
| | | return false |
| | |
| | | beego.Router(preApi+"/code/new", &controllers.CodeController{}, "*:New") |
| | | beego.Router(preApi+"/user/login", &controllers.UserController{}, "*:Login") |
| | | beego.Router(preApi+"/user/logout", &controllers.UserController{}, "*:Logout") |
| | | beego.Router(preApi+"/user/addPlateNo", &controllers.UserController{}, "*:AddPlateNo") |
| | | beego.Router(preApi+"/user/myPlateNos", &controllers.UserController{}, "*:MyPlateNos") |
| | | } |
| | |
| | | } |
| | | |
| | | func (sv *UserService) AddPlateNo(userId, plateNo string) bool { |
| | | var uc models.UserCar |
| | | if uc.Exist(userId, plateNo) { |
| | | return true |
| | | } |
| | | tmp := models.UserCar{ |
| | | Id: uuid.NewV4().String(), |
| | | UserId: userId, |
| | | PlateNo: plateNo, |
| | | } |
| | | _, err := tmp.Insert() |
| | | if err == nil { |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |