コード例 #1
0
func ProjectUpdate(db gorm.DB, r render.Render, params martini.Params, updatedProject models.Project) {
	var project models.Project
	if err := db.First(&project, params["id"]).Error; err != nil {
		r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Project not found"})
		return
	}

	project.Name = updatedProject.Name
	project.UpdatedAt = time.Now()

	db.Save(&project)
	r.JSON(http.StatusOK, project)
}
コード例 #2
0
func ProjectCreate(db gorm.DB, r render.Render, project models.Project) {
	project.CreatedAt = time.Now()
	project.UpdatedAt = time.Now()
	db.Save(&project)
	r.JSON(http.StatusCreated, project)
}