func (h createHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var document documents.CreateOrganizationRequest now := time.Now().UTC() err := json.NewDecoder(req.Body).Decode(&document) if err != nil { panic(err) } organization := domain.NewOrganization(domain.NewGUID("org")) if document.GUID != "" { organization.GUID = document.GUID } organization.Name = document.Name organization.CreatedAt = now organization.UpdatedAt = now h.organizations.Add(organization) response, err := json.Marshal(organization) if err != nil { panic(err) } w.WriteHeader(http.StatusCreated) w.Write(response) }
func (h createHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var document documents.CreateServiceInstanceRequest err := json.NewDecoder(req.Body).Decode(&document) if err != nil { panic(err) } now := time.Now().UTC() instance := domain.NewServiceInstance(domain.NewGUID("service-instance")) instance.Name = document.Name instance.PlanGUID = document.PlanGUID instance.SpaceGUID = document.SpaceGUID instance.CreatedAt = now instance.UpdatedAt = now h.serviceInstances.Add(instance) response, err := json.Marshal(instance) if err != nil { panic(err) } w.WriteHeader(http.StatusCreated) w.Write(response) }
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) }
func (h createHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var document documents.CreateApplicationRequest err := json.NewDecoder(req.Body).Decode(&document) if err != nil { panic(err) } application := domain.NewApplication(domain.NewGUID("app")) application.Name = document.Name application.SpaceGUID = document.SpaceGUID application.Diego = document.Diego h.applications.Add(application) response, err := json.Marshal(application) if err != nil { panic(err) } w.WriteHeader(http.StatusCreated) w.Write(response) }
func (h createHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var document documents.CreateUserRequest now := time.Now().UTC() err := json.NewDecoder(req.Body).Decode(&document) if err != nil { panic(err) } user := domain.NewUser(domain.NewGUID("user")) user.GUID = document.GUID user.DefaultSpaceGUID = document.DefaultSpaceGUID user.CreatedAt = now user.UpdatedAt = now h.users.Add(user) response, err := json.Marshal(user) if err != nil { panic(err) } w.WriteHeader(http.StatusCreated) w.Write(response) }