jiaojiao7 4 жил өмнө
parent
commit
80dc4c5639

+ 6 - 3
service/projectDetail.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"fmt"
+	"sfbase/core"
 	"sfbase/global"
 	"sfis/db"
 )
@@ -9,9 +10,11 @@ import (
 func ProjectDetailData(id string) map[string]interface{} {
 	global.Logger.Info("id " + id)
 	data := map[string]interface{}{}
-	query := `{"query":{"bool":{"must":[{"term":{"id":"%s"}}],"must_not":[],"should":[]}}}`
-	querys := fmt.Sprintf(query, id)
-	infos := db.Es.Get(INDEX, TYPE, querys)
+	_query := `{"query":{"bool":{"must":[{"term":{"id":"%s"}}],"must_not":[],"should":[]}}}`
+	query := fmt.Sprintf(_query, id)
+	INDEX := core.GetStringConf("es.project.index")
+	TYPE := core.GetStringConf("es.project.itype")
+	infos := db.Es.Get(INDEX, TYPE, query)
 	if infos != nil && len(*infos) > 0 {
 		data = (*infos)[0]
 	}

+ 0 - 40
test/api_v1/projects_test.go

@@ -1,40 +0,0 @@
-package api_v1
-
-import (
-	"encoding/json"
-	"io/ioutil"
-	"log"
-	"net/http"
-	"strings"
-	"testing"
-)
-
-func init() {
-	//todo init connection db operation
-}
-func Test_ProjectDetails(t *testing.T) {
-	data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
-		"id": "5f6b4e12499cb0822d39c68f",
-	})
-	res := map[string]interface{}{}
-	s, _ := json.Marshal(data)
-	json.Unmarshal(s, &res)
-	log.Println("数据:", res)
-}
-
-func post(url string, form map[string]string) (data map[string]interface{}) {
-	str := ""
-	for k, v := range form {
-		str += "&" + k + "=" + v
-	}
-	log.Println(str)
-	res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
-	if err != nil {
-		log.Println("post err:", err.Error())
-	} else if res.Body != nil {
-		defer res.Body.Close()
-		bs, _ := ioutil.ReadAll(res.Body)
-		json.Unmarshal(bs, &data)
-	}
-	return
-}

+ 11 - 0
test/project/project_test.go

@@ -26,6 +26,17 @@ func getData() {
 	log.Println(data)
 }
 
+//获取项目详情测试用例
+func Test_ProjectDetails(t *testing.T) {
+	data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
+		"id": "5f6b4e12499cb0822d39c68f",
+	})
+	res := map[string]interface{}{}
+	s, _ := json.Marshal(data)
+	json.Unmarshal(s, &res)
+	log.Println("数据:", res)
+}
+
 func post(url string, form map[string]string) (data map[string]interface{}) {
 	str := ""
 	for k, v := range form {