コード例 #1
0
ファイル: site.go プロジェクト: kpernyer/sphere-go-homecloud
// GetAll retrieves a list of all sites
func (lr *SiteRouter) GetAll(r *http.Request, w http.ResponseWriter, siteModel *models.SiteModel, stateManager state.StateManager, conn redis.Conn) {
	sites, err := siteModel.FetchAll(conn)

	if err != nil {
		WriteServerErrorResponse("Unable to retrieve sites", http.StatusInternalServerError, w)
		return
	}

	WriteServerResponse(sites, http.StatusOK, w)
}
コード例 #2
0
ファイル: site.go プロジェクト: kpernyer/sphere-go-homecloud
// DeleteSite removes a site using it's identifier
func (lr *SiteRouter) DeleteSite(params martini.Params, w http.ResponseWriter, siteModel *models.SiteModel, conn redis.Conn) {

	err := siteModel.Delete(params["id"], conn)

	if err == models.RecordNotFound {
		WriteServerErrorResponse(fmt.Sprintf("Unknown site id: %s", params["id"]), http.StatusNotFound, w)
		return
	}

	if err != nil {
		WriteServerErrorResponse("Unable to delete site", http.StatusInternalServerError, w)
		return
	}

	w.WriteHeader(http.StatusOK) // TODO: talk to theo about this response.
}
コード例 #3
0
ファイル: site.go プロジェクト: kpernyer/sphere-go-homecloud
// GetSite retrieves a site using it's identifier
func (lr *SiteRouter) GetSite(params martini.Params, w http.ResponseWriter, siteModel *models.SiteModel, stateManager state.StateManager, conn redis.Conn) {

	site, err := siteModel.Fetch(params["id"], conn)

	log.Infof(spew.Sprintf("site: %v", site))

	if err == models.RecordNotFound {
		WriteServerErrorResponse(fmt.Sprintf("Unknown site id: %s", params["id"]), http.StatusNotFound, w)
		return
	}

	if err != nil {
		WriteServerErrorResponse("Unable to retrieve site", http.StatusInternalServerError, w)
		return
	}

	WriteServerResponse(site, http.StatusOK, w)
}
コード例 #4
0
ファイル: site.go プロジェクト: kpernyer/sphere-go-homecloud
// GetAll updates a site using it's identifier, with the JSON payload containing name and type
func (lr *SiteRouter) PutSite(params martini.Params, r *http.Request, w http.ResponseWriter, siteModel *models.SiteModel, conn redis.Conn) {

	var site *model.Site

	err := json.NewDecoder(r.Body).Decode(&site)

	if err != nil {
		WriteServerErrorResponse("Unable to parse body", http.StatusInternalServerError, w)
		return
	}

	err = siteModel.Update(params["id"], site, conn)

	if err != nil {
		WriteServerErrorResponse("Unable to update site", http.StatusInternalServerError, w)
		return
	}

	w.WriteHeader(http.StatusOK)
}