diff options
Diffstat (limited to 'src/orchestrator/api')
-rw-r--r-- | src/orchestrator/api/api.go | 1 | ||||
-rw-r--r-- | src/orchestrator/api/projecthandler.go | 25 | ||||
-rw-r--r-- | src/orchestrator/api/projecthandler_test.go | 4 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go index 5abbb96d..9194419c 100644 --- a/src/orchestrator/api/api.go +++ b/src/orchestrator/api/api.go @@ -57,6 +57,7 @@ func NewRouter(projectClient moduleLib.ProjectManager, } router.HandleFunc("/projects", projHandler.createHandler).Methods("POST") router.HandleFunc("/projects/{project-name}", projHandler.getHandler).Methods("GET") + router.HandleFunc("/projects", projHandler.getHandler).Methods("GET") router.HandleFunc("/projects/{project-name}", projHandler.deleteHandler).Methods("DELETE") //setting routes for compositeApp diff --git a/src/orchestrator/api/projecthandler.go b/src/orchestrator/api/projecthandler.go index 1e78c676..09b24096 100644 --- a/src/orchestrator/api/projecthandler.go +++ b/src/orchestrator/api/projecthandler.go @@ -75,6 +75,31 @@ func (h projectHandler) getHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) name := vars["project-name"] + // handle for get all projects + if len(name) == 0 { + var pList []moduleLib.Project + + projects, err := h.client.GetAllProjects() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + for _, p := range projects { + pList = append(pList, moduleLib.Project{MetaData: p.MetaData}) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(pList) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + return + + } + ret, err := h.client.GetProject(name) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/src/orchestrator/api/projecthandler_test.go b/src/orchestrator/api/projecthandler_test.go index 0212e57a..dae87e2b 100644 --- a/src/orchestrator/api/projecthandler_test.go +++ b/src/orchestrator/api/projecthandler_test.go @@ -60,6 +60,10 @@ func (m *mockProjectManager) DeleteProject(name string) error { return m.Err } +func (m *mockProjectManager) GetAllProjects() ([]moduleLib.Project, error) { + return []moduleLib.Project{}, m.Err +} + func TestProjectCreateHandler(t *testing.T) { testCases := []struct { label string |