34 lines
775 B
Go
34 lines
775 B
Go
|
|
package relation
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/pkg/ctxdata"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||
|
|
)
|
||
|
|
|
||
|
|
func GetFullGraphHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
roleKey := ctxdata.GetRoleKey(r.Context())
|
||
|
|
if roleKey != "admin" {
|
||
|
|
w.Header().Set("Content-Type", "application/json")
|
||
|
|
w.WriteHeader(http.StatusForbidden)
|
||
|
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||
|
|
"code": 1006,
|
||
|
|
"msg": "access denied: admin only",
|
||
|
|
})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
graph, err := svcCtx.CrmRepo.GetFullGraph(r.Context())
|
||
|
|
if err != nil {
|
||
|
|
httpx.ErrorCtx(r.Context(), w, err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
httpx.OkJsonCtx(r.Context(), w, graph)
|
||
|
|
}
|
||
|
|
}
|