Ejemplo n.º 1
0
func (a *DataStreamService) Update(dataStream *models.DataStream) error {
	revel.INFO.Println("updating data stream", dataStream.ToString())
	count, err := persistence.Dbm.Update(dataStream)
	checkErr(err, "data stream not updated "+dataStream.ToString())
	if count == 1 {
		return nil
	}
	return err
}
Ejemplo n.º 2
0
func (a *DataStreamController) Add() revel.Result {
	var dataStream models.DataStream
	err := json.NewDecoder(a.Request.Body).Decode(&dataStream)
	if err != nil {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(err)
	}
	dataStream.Validate(a.Validation)
	if a.Validation.HasErrors() {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(a.Validation.Errors)
	}
	return a.RenderJson(a.DataStreamService.Save(&dataStream))
}
Ejemplo n.º 3
0
func (a *DataStreamController) Update(id int64) revel.Result {
	var dataStream models.DataStream
	err := json.NewDecoder(a.Request.Body).Decode(&dataStream)
	if err != nil {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(err)
	}
	revel.INFO.Println(&dataStream)
	if dataStream.Id != id {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(&models.Error{Error: "Entity ID and URL ID don't match"})
	}
	dataStream.Validate(a.Validation)
	if a.Validation.HasErrors() {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(a.Validation.Errors)
	}
	err = a.DataStreamService.Update(&dataStream)
	if err != nil {
		a.Response.Status = http.StatusConflict
		return a.RenderJson(err)
	}
	return a.RenderJson(&dataStream)
}
Ejemplo n.º 4
0
func (a *DataStreamService) Save(dataStream *models.DataStream) *models.DataStream {
	revel.INFO.Println("saving data stream", dataStream.ToString())
	persistence.Dbm.Insert(dataStream)
	return dataStream
}