Example #1
0
func catalogueSubmit(w http.ResponseWriter, r *http.Request) {
	j := r.FormValue("json")
	var p SubmitJson
	err := json.Unmarshal([]byte(j), &p)
	if err != nil {
		w.Write(ToJson(err))
		return
	}
	//保存文档
	if p.Doc.Id > 0 {
		err = p.Doc.Update()
		if err == nil {
			//添加操作日志
			model.AddUpdateLog("修改文档【"+p.Doc.Name+":"+p.Doc.SerialNumber+"】", p.Doc.ProjectId, p.Doc.VersionId)
			err = model.DeleteParameters(p.Doc.Id)
		}
	} else {
		model.AddUpdateLog("增加文档【"+p.Doc.Name+":"+p.Doc.SerialNumber+"】", p.Doc.ProjectId, p.Doc.VersionId)
		err = p.Doc.Save()
	}

	if err != nil {
		w.Write(ToJson(err))
		return
	}
	var prm []model.Parameters = make([]model.Parameters, 0, len(p.ReqParameters)+len(p.RspParameters))
	for i := 0; i < len(p.RspParameters); i++ {
		p.RspParameters[i].Id = 0
		p.RspParameters[i].PrmType = 1
		p.RspParameters[i].DocId = p.Doc.Id
		p.RspParameters[i].ProjectId = p.Doc.ProjectId
		p.RspParameters[i].VersionId = p.Doc.VersionId
		prm = append(prm, p.RspParameters[i])
	}
	for i := 0; i < len(p.ReqParameters); i++ {
		p.ReqParameters[i].Id = 0
		p.ReqParameters[i].PrmType = 0
		p.ReqParameters[i].DocId = p.Doc.Id
		p.ReqParameters[i].ProjectId = p.Doc.ProjectId
		p.ReqParameters[i].VersionId = p.Doc.VersionId
		prm = append(prm, p.ReqParameters[i])
	}
	if len(prm) > 0 {
		err = model.SaveParameters(prm)
	}
	if err != nil {
		w.Write(ToJson(err))
		return
	}
	w.Write(ToJson("保存成功!"))
}
Example #2
0
//更新参数
func updateParameter(w http.ResponseWriter, r *http.Request) {
	var p model.Parameters
	j := r.FormValue("json")
	err := json.Unmarshal([]byte(j), &p)
	if err != nil {
		w.Write(ToJson(err))
		return
	}

	err = p.Update()
	if err != nil {
		w.Write(ToJson(err))
		return
	}
	doc, err := model.GetDocById(p.DocId)
	if err == nil {
		pt := "请求参数"
		if p.PrmType == 1 {
			pt = "响应参数"
		}
		model.AddUpdateLog(fmt.Sprintf("文档【%s】【%s】参数被修改,参数编号【%s】", doc.Name, pt, p.SerialNumber), doc.ProjectId, doc.VersionId)
	}
	w.Write(ToJson("success"))

}
Example #3
0
func deleteErrCode(w http.ResponseWriter, r *http.Request) {
	eid, _ := strconv.ParseInt(r.FormValue("eid"), 10, 64)
	ret, err := model.GetErrCodeById(eid)
	if err != nil {
		w.Write(ToJson(err))
		return
	}
	err = ret.Delete()
	model.AddUpdateLog(fmt.Sprintf("删除错误代码【%s】", ret.Code), ret.ProjectId, ret.VersionId)
	w.Write(ToJson(err))
}
Example #4
0
func explainDelete(w http.ResponseWriter, r *http.Request) {
	eid, _ := strconv.ParseInt(r.FormValue("eid"), 10, 64)
	ret, err := model.GetExplainById(eid)
	if err != nil {
		w.Write(ToJson(err))
		return
	}
	err = ret.Delete()
	if err == nil {
		model.AddUpdateLog(fmt.Sprintf("删除文章【%s】", ret.Title), ret.ProjectId, ret.VersionId)
	}
	w.Write(ToJson(err))
}
Example #5
0
func saveErrCode(w http.ResponseWriter, r *http.Request) {
	j := r.FormValue("json")
	var c model.ErrCode
	err := json.Unmarshal([]byte(j), &c)
	if err != nil {
		w.Write(ToJson(err))
		return
	}
	if c.Id > 0 {
		err = c.Update()
		if err == nil {
			model.AddUpdateLog(fmt.Sprintf("修改错误代码【%s:%s】", c.Code, c.DescriptionText), c.ProjectId, c.VersionId)
		}
	} else {
		err = c.Save()
		if err == nil {
			model.AddUpdateLog(fmt.Sprintf("增加错误代码【%s:%s】", c.Code, c.DescriptionText), c.ProjectId, c.VersionId)
		}
	}

	w.Write(ToJson(err))
}
Example #6
0
func explainSubmit(w http.ResponseWriter, r *http.Request) {
	j := r.FormValue("json")
	var e model.Explain
	err := json.Unmarshal([]byte(j), &e)
	if err != nil {
		w.Write(ToJson(err))
		return
	}
	if e.Id > 0 {
		err = e.Update()
		if err == nil {
			model.AddUpdateLog(fmt.Sprintf("修改文章【%s】", e.Title), e.ProjectId, e.VersionId)
		}
	} else {
		e.CreatedAt = time.Now().Local()
		err = e.Save()
		if err == nil {
			model.AddUpdateLog(fmt.Sprintf("增加文章【%s】", e.Title), e.ProjectId, e.VersionId)
		}
	}

	w.Write(ToJson(err))
}