Esempio n. 1
0
func DeleteTopo(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)
	var topo dbconn.Topo
	var cpe dbconn.Cpe
	var err error

	topo.Id, err = strconv.ParseInt(vars["Topoid"], 10, 64)

	// Need to clear the TopoID on the associated CPE - set it to Topoid = 0
	if err = topo.Get(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	cpe.Id = topo.Cpeid
	cpe.Topoid = 0
	if err = cpe.Update(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	//Delete the topo from Topos Table
	if err = topo.Delete(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

}
Esempio n. 2
0
func UpdateCpe(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	cid, _ := strconv.ParseInt(vars["Cpeid"], 10, 64)

	var cpe dbconn.Cpe

	if err := cpe.Parse(w, r); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if cid != cpe.Id {
		err := fmt.Errorf("Cpeid mismatch")
		http.Error(w, err.Error(), 500)
		return
	}

	if err := cpe.Update(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	if err := json.NewEncoder(w).Encode(cpe); err != nil {
		panic(err)
	}
}
Esempio n. 3
0
func GetCpeTopo(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)

	var cpe dbconn.Cpe
	var topo dbconn.Topo
	var err error

	cpe.Id, err = strconv.ParseInt(vars["Cpeid"], 10, 64)

	if err = cpe.Get(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	topo.Id = cpe.Topoid
	if err = topo.Get(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	if err := json.NewEncoder(w).Encode(topo); err != nil {
		panic(err)
	}

}
Esempio n. 4
0
func DeleteCpe(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)
	var cpe dbconn.Cpe
	var err error

	cpe.Id, err = strconv.ParseInt(vars["Cpeid"], 10, 64)
	err = cpe.Delete()
	if err != nil {
		return
	}
}
Esempio n. 5
0
func AddTopo(w http.ResponseWriter, r *http.Request) {

	var topo dbconn.Topo
	var cpe dbconn.Cpe

	if err := topo.Parse(w, r); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if err := topo.Add(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	cpe.Id = topo.Cpeid
	if err := cpe.Get(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	cpe.Topoid = topo.Id
	if err := cpe.Update(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	if err := json.NewEncoder(w).Encode(topo); err != nil {
		panic(err)
	}

}
Esempio n. 6
0
func AddCpe(w http.ResponseWriter, r *http.Request) {

	var cpe dbconn.Cpe

	if err := cpe.Parse(w, r); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if err := cpe.Add(); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	if err := json.NewEncoder(w).Encode(cpe); err != nil {
		panic(err)
	}
}
Esempio n. 7
0
func GetUserCpe(w http.ResponseWriter, r *http.Request) {

	vars := mux.Vars(r)
	var cpes []dbconn.Cpe
	var cpe dbconn.Cpe
	var err error

	cpe.Userid, err = strconv.ParseInt(vars["Userid"], 10, 64)

	cpes, err = cpe.Gets()
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	if err := json.NewEncoder(w).Encode(cpes); err != nil {
		panic(err)
	}

}