Пример #1
0
func AddRepo(w http.ResponseWriter, r *http.Request) {
	action := r.URL.Query().Get("Action")
	db := liboct.GetDefaultDB()
	//Add and refresh
	if action == "Add" {
		var repo liboct.TestCaseRepo
		result, _ := ioutil.ReadAll(r.Body)
		r.Body.Close()
		err := json.Unmarshal([]byte(result), &repo)
		if err != nil {
			liboct.RenderError(w, err)
		} else {
			if err := repo.IsValid(); err == nil {
				if id, e := db.Add(liboct.DBRepo, repo); e != nil {
					liboct.RenderError(w, err)
				} else {
					RefreshRepo(id)
					liboct.RenderOK(w, "", nil)
				}
			} else {
				liboct.RenderError(w, err)
			}
		}
	} else if action == "Refresh" {
		ids := db.Lookup(liboct.DBRepo, liboct.DBQuery{})
		for index := 0; index < len(ids); index++ {
			RefreshRepo(ids[index])
		}
		liboct.RenderOK(w, "", nil)
	} else {
		liboct.RenderErrorf(w, "The action in AddRepo is limited to Add/Refresh")
	}
}
Пример #2
0
func CleanRepo(repo liboct.TestCaseRepo) {
	var query liboct.DBQuery
	db := liboct.GetDefaultDB()
	query.Params = make(map[string]string)
	query.Params["RepoID"] = repo.GetID()
	ids := db.Lookup(liboct.DBRepo, query)
	for index := 0; index < len(ids); index++ {
		db.Remove(liboct.DBCase, ids[index])
	}
}