コード例 #1
0
func (a *DataStreamGroupController) Add() revel.Result {
	var dataStreamGroup models.DataStreamGroup
	err := json.NewDecoder(a.Request.Body).Decode(&dataStreamGroup)
	if err != nil {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(err)
	}
	dataStreamGroup.Validate(a.Validation)
	if a.Validation.HasErrors() {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(a.Validation.Errors)
	}
	return a.RenderJson(a.DataStreamGroupService.Save(&dataStreamGroup))
}
コード例 #2
0
func (a *DataStreamGroupController) Update(id int64) revel.Result {
	var dataStreamGroup models.DataStreamGroup
	err := json.NewDecoder(a.Request.Body).Decode(&dataStreamGroup)
	if err != nil {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(err)
	}
	revel.INFO.Println(&dataStreamGroup)
	if dataStreamGroup.Id != id {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(&models.Error{Error: "Entity ID and URL ID don't match"})
	}
	dataStreamGroup.Validate(a.Validation)
	if a.Validation.HasErrors() {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(a.Validation.Errors)
	}
	err = a.DataStreamGroupService.Update(&dataStreamGroup)
	if err != nil {
		a.Response.Status = http.StatusConflict
		return a.RenderJson(err)
	}
	return a.RenderJson(&dataStreamGroup)
}