Ejemplo n.º 1
0
func (h associateUserHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	r := regexp.MustCompile(`^/v2/organizations/(.*)/users/(.*)$`)
	matches := r.FindStringSubmatch(req.URL.Path)

	org, ok := h.organizations.Get(matches[1])
	if !ok {
		common.NotFound(w)
		return
	}

	user, ok := h.users.Get(matches[2])
	if !ok {
		common.NotFound(w)
		return
	}

	org.Users.Add(user)

	response, err := json.Marshal(org)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusCreated)
	w.Write(response)
}
func (h associateDeveloperHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	r := regexp.MustCompile(`^/v2/spaces/(.*)/developers/(.*)$`)
	matches := r.FindStringSubmatch(req.URL.Path)

	space, ok := h.spaces.Get(matches[1])
	if !ok {
		common.NotFound(w)
		return
	}

	developer, ok := h.users.Get(matches[2])
	if !ok {
		common.NotFound(w)
		return
	}

	space.Developers.Add(developer)

	response, err := json.Marshal(space)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusCreated)
	w.Write(response)
}
Ejemplo n.º 3
0
func (h getHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	instanceGUID := strings.TrimPrefix(req.URL.Path, "/v2/service_instances/")

	instance, ok := h.serviceInstances.Get(instanceGUID)
	if !ok {
		common.NotFound(w)
	}

	response, err := json.Marshal(instance)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
}
Ejemplo n.º 4
0
func (h getHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	userGUID := strings.TrimPrefix(req.URL.Path, "/v2/users/")

	user, ok := h.users.Get(userGUID)
	if !ok {
		common.NotFound(w)
		return
	}

	response, err := json.Marshal(user)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
}
Ejemplo n.º 5
0
func (h getHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)

	app, ok := h.applications.Get(vars["guid"])
	if !ok {
		common.NotFound(w)
		return
	}

	response, err := json.Marshal(app)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
}
Ejemplo n.º 6
0
func (h getManagersHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	r := regexp.MustCompile(`^/v2/organizations/(.*)/managers$`)
	matches := r.FindStringSubmatch(req.URL.Path)

	query := req.URL.Query()
	pageNum := common.ParseInt(query.Get("page"), 1)
	perPage := common.ParseInt(query.Get("results-per-page"), 10)

	org, ok := h.organizations.Get(matches[1])
	if !ok {
		common.NotFound(w)
		return
	}

	page := domain.NewPage(org.Managers, req.URL.Path, pageNum, perPage)
	response, err := json.Marshal(page)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusOK)
	w.Write(response)
}
Ejemplo n.º 7
0
func (h createHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	var document documents.CreateSpaceRequest
	now := time.Now().UTC()
	err := json.NewDecoder(req.Body).Decode(&document)
	if err != nil {
		panic(err)
	}

	org, ok := h.orgs.Get(document.OrganizationGUID)
	if !ok {
		common.NotFound(w)
		return
	}

	space := domain.NewSpace(domain.NewGUID("space"))

	if document.GUID != "" {
		space.GUID = document.GUID
	}

	space.Name = document.Name
	space.OrganizationGUID = document.OrganizationGUID
	space.CreatedAt = now
	space.UpdatedAt = now

	h.spaces.Add(space)

	org.Spaces.Add(space)

	response, err := json.Marshal(space)
	if err != nil {
		panic(err)
	}

	w.WriteHeader(http.StatusCreated)
	w.Write(response)
}