Example #1
0
File: util.go Project: joshlf/todo
func tasksToJSONFile(t graph.Tasks, fname string) error {
	b, err := json.Marshal(t.Values())
	if err != nil {
		return err
	}
	return ioutil.WriteFile(fname, b, 0)
}
Example #2
0
func (api *APIHandler) create(request *restful.Request, response *restful.Response) {
	var err error
	var tasks graph.Tasks
	t := graph.Task{
		End:          math.MaxInt64,
		Dependencies: graph.MakeTaskIDSet(),
	}
	request.ReadEntity(&t)
	t.Id, err = api.todo.AddTask(t)

	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}

	tasks, err = api.todo.GetUnblockedDependencies(t.Id)
	if err != nil {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
	} else {
		response.WriteEntity(json.Response{
			Info:  t,
			Tasks: tasks.Values(),
		})
	}
}