func ListCases(w http.ResponseWriter, r *http.Request) { //Need better explaination of 'status', currently, only hasReport/isUpdated db := liboct.GetDefaultDB() var query liboct.DBQuery page_string := r.URL.Query().Get("Page") page, err := strconv.Atoi(page_string) if err == nil { query.Page = page } pageSizeString := r.URL.Query().Get("PageSize") pageSize, err := strconv.Atoi(pageSizeString) if err != nil { query.PageSize = pageSize } status := r.URL.Query().Get("Status") if len(status) > 0 { query.Params = make(map[string]string) query.Params["Status"] = status } ids := db.Lookup(liboct.DBCase, query) var caseList []liboct.TestCase for index := 0; index < len(ids); index++ { if val, err := db.Get(liboct.DBCase, ids[index]); err == nil { tc, _ := liboct.CaseFromString(val.String()) caseList = append(caseList, tc) } } liboct.RenderOK(w, fmt.Sprintf("%d cases founded", len(caseList)), caseList) }
func ListRepos(w http.ResponseWriter, r *http.Request) { var query liboct.DBQuery page_string := r.URL.Query().Get("Page") page, err := strconv.Atoi(page_string) if err == nil { query.Page = page } pageSizeString := r.URL.Query().Get("PageSize") pageSize, err := strconv.Atoi(pageSizeString) if err == nil { query.PageSize = pageSize } var rl []liboct.DBInterface db := liboct.GetDefaultDB() ids := db.Lookup(liboct.DBRepo, query) for index := 0; index < len(ids); index++ { repo, _ := db.Get(liboct.DBRepo, ids[index]) rl = append(rl, repo) } liboct.RenderOK(w, fmt.Sprintf("%d repos founded", len(rl)), rl) }
func GetResourceQuery(r *http.Request) liboct.DBQuery { var query liboct.DBQuery page_string := r.URL.Query().Get("Page") page, err := strconv.Atoi(page_string) if err == nil { query.Page = page } pageSizeString := r.URL.Query().Get("PageSize") pageSize, err := strconv.Atoi(pageSizeString) if err == nil { query.PageSize = pageSize } //TODO: use a list , also add the list to the lib query.Params = make(map[string]string) query.Params["Class"] = r.URL.Query().Get("Class") query.Params["Distribution"] = r.URL.Query().Get("Distribution") query.Params["Version"] = r.URL.Query().Get("Version") query.Params["Arch"] = r.URL.Query().Get("Arch") query.Params["CPU"] = r.URL.Query().Get("CPU") query.Params["Memory"] = r.URL.Query().Get("Memory") return query }
func ListTasks(w http.ResponseWriter, r *http.Request) { //TODO status var query liboct.DBQuery db := liboct.GetDefaultDB() pageStr := r.URL.Query().Get("Page") page, err := strconv.Atoi(pageStr) if err == nil { query.Page = page } pageSizeStr := r.URL.Query().Get("PageSize") pageSize, err := strconv.Atoi(pageSizeStr) if err == nil { query.PageSize = pageSize } ids := db.Lookup(liboct.DBTask, query) var tl []liboct.DBInterface for index := 0; index < len(ids); index++ { task, _ := db.Get(liboct.DBTask, ids[index]) tl = append(tl, task) } liboct.RenderOK(w, fmt.Sprintf("%d tasks founded", len(tl)), tl) }