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