Exemplo n.º 1
0
func AddMission(w http.ResponseWriter, r *http.Request) {
	mission_name := strings.Join(r.Form["mission_name"], "")
	mission_type := strings.Join(r.Form["mission_type"], "")
	project_code := strings.Join(r.Form["project_code"], "")
	parent_code := strings.Join(r.Form["parent_code"], "")
	has_child := 1
	child_index := 0
	status := 0

	mission_code := ut.GenerateCode(mission_name)

	fmt.Println("Add mission", mission_name)

	stmt, err := mydb.DBConn.Prepare("INSERT INTO mission(mission_code, mission_name, mission_type, project_code, has_child, parent_code, child_index, status) VALUES(?,?,?,?,?,?,?,?)")
	if err != nil {
		panic(err.Error())
	}
	defer stmt.Close()

	_, err = stmt.Exec(mission_code, mission_name, mission_type, project_code, has_child, parent_code, child_index, status)
	if err != nil {
		panic(err.Error())
	}

	mission := QueryMissionByCode(mission_code)
	res, _ := json.Marshal(mission)

	fmt.Fprintf(w, string(res))
}
Exemplo n.º 2
0
func AddMetadata(w http.ResponseWriter, r *http.Request) {
	mission_code := strings.Join(r.Form["mission_code"], "")
	metadata_name := strings.Join(r.Form["metadata_name"], "")
	metadata_value := strings.Join(r.Form["metadata_value"], "")

	metadata_code := ut.GenerateCode(metadata_name + metadata_value)

	fmt.Println("Add Metadata for mission ", metadata_name)

	stmt, err := mydb.DBConn.Prepare("INSERT INTO mission_metadata(metadata_code, mission_code, metadata_name, metadata_value) VALUES(?,?,?,?)")
	if err != nil {
		panic(err.Error())
	}
	defer stmt.Close()

	_, err = stmt.Exec(metadata_code, mission_code, metadata_name, metadata_value)
	if err != nil {
		panic(err.Error())
	}

	metadata := QueryMetadataByCode(metadata_code)
	res, _ := json.Marshal(metadata)

	fmt.Fprintf(w, string(res))
}
Exemplo n.º 3
0
func AddTarget(w http.ResponseWriter, r *http.Request) {
	mission_code := strings.Join(r.Form["mission_code"], "")
	target_name := strings.Join(r.Form["target_name"], "")
	type_str := strings.Join(r.Form["target_type"], "")
	target_type, _ := strconv.Atoi(type_str)
	comment := strings.Join(r.Form["comment"], "")

	target_code := ut.GenerateCode(target_name + comment)

	fmt.Println("Add Require for mission ", target_name)

	stmt, err := mydb.DBConn.Prepare("INSERT INTO mission_target(target_code, mission_code, target_name, target_type, comment) VALUES(?,?,?,?,?)")
	if err != nil {
		panic(err.Error())
	}
	defer stmt.Close()

	_, err = stmt.Exec(target_code, mission_code, target_name, target_type, comment)
	if err != nil {
		panic(err.Error())
	}

	target := QueryTargetByCode(target_code)
	res, _ := json.Marshal(target)

	fmt.Fprintf(w, string(res))
}
Exemplo n.º 4
0
func AddProject(w http.ResponseWriter, r *http.Request) {
	project_name := strings.Join(r.Form["project_name"], "")
	project_detail := strings.Join(r.Form["project_detail"], "")
	project_code := ut.GenerateCode(project_name)

	fmt.Println("Add project", project_name)

	stmt, err := mydb.DBConn.Prepare("INSERT INTO project(project_code, project_name, project_detail) VALUES(?, ?, ?)")
	if err != nil {
		panic(err.Error())
	}
	defer stmt.Close()

	_, err = stmt.Exec(project_code, project_name, project_detail)
	if err != nil {
		panic(err.Error())
	}

	proj := QueryProjectByCode(project_code)
	res, _ := json.Marshal(proj)

	fmt.Fprintf(w, string(res))
}