// @Title Post // @Description 添加一个新的车队 // @Param body body models.Group true "车队信息" // @Success 200 {int} models.Group.Id // @Failure 403 body is empty // @router / [post] func (this *GroupController) Post() { var group models.Group err := json.Unmarshal(this.Ctx.Input.RequestBody, &group) if err != nil { this.ResponseErrorJSON(400, errorFormat(ErrorBadJson_400, err.Error())) } else { group.Password = tools.MD5(group.Password) if id, err := models.AddGroup(group); err != nil { this.ResponseErrorJSON(400, errorFormat(ErrorBadParam_400, err.Error())) } else { this.Data["json"] = map[string]interface{}{ "code": 0, "data": id, } } } this.ServeJson() }
// @Title update // @Description 更新车队信息 // @Param id path int true "车队唯一ID" // @Param body body models.Group true "车队信息" // @Success 200 {object} models.Group // @Failure 400 请求的参数不正确 // @router /:id [put] func (this *GroupController) Put() { id, _ := this.GetInt64(":id") var group models.Group if err := json.Unmarshal(this.Ctx.Input.RequestBody, &group); err != nil { this.ResponseErrorJSON(400, errorFormat(ErrorBadJson_400, err.Error())) } else { if group.Password != "" { group.Password = tools.MD5(group.Password) } update, err := models.UpdateGroup(id, &group) if err != nil { this.ResponseErrorJSON(400, errorFormat(ErrorBadParam_400, err.Error())) } else { this.Data["json"] = map[string]interface{}{ "code": 0, "data": update, } } } this.ServeJson() }