예제 #1
0
func ShowController(w http.ResponseWriter, r *http.Request) {
	// TODO if the job doesn't exist, return 404
	id := getId(r)
	d := make(map[string]interface{})
	d["job"] = job.Find(id, helpers.CurrentUser(r).Id)
	w.Write(util.JSON(d))
}
예제 #2
0
func IndexController(w http.ResponseWriter, r *http.Request) {
	d := make(map[string]interface{})
	jobs := job.FindByUserId(helpers.CurrentUser(r).Id)

	c := make(chan *user.User)
	for _, j := range jobs {
		go func(userId int) {
			c <- user.Find(userId)
		}(j.UserId)
	}

	// TODO Dirty as all hell.  Probably want to clean up.
	// Right now, it works.
	users := make([]*user.User, 0)
	for _ = range jobs {
		u := <-c
		if u == nil {
			continue
		}
		var b bool
		for _, v := range users {
			if u.Id == v.Id {
				b = true
				break
			}
		}
		if !b {
			users = append(users, u)
		}
	}

	d["jobs"] = jobs
	d["users"] = users
	w.Write(util.JSON(d))
}
예제 #3
0
func ShowController(w http.ResponseWriter, r *http.Request) {
	// TODO some kind of validation that the plan belongs to the user.
	// TODO if the plan doesn't exist, return 404
	id := getId(r)
	d := make(map[string]interface{})
	d["plan"] = plan.Find(id)
	w.Write(util.JSON(d))
}
예제 #4
0
func UpdateController(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	p := plan.Find(getId(r))
	updateAttributes(p, r)
	p.Save()
	d := make(map[string]interface{})
	if p.Save() {
		d["job"] = p
	}
	w.Write(util.JSON(d))
}
예제 #5
0
func UpdateController(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	j := job.Find(getId(r), helpers.CurrentUser(r).Id)
	updateAttributes(j, r)
	j.Save()
	d := make(map[string]interface{})
	if j.Save() {
		d["job"] = j
	}
	w.Write(util.JSON(d))
}
예제 #6
0
func CreateController(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	j := job.Job{
		Name:   r.PostForm.Get("job[name]"),
		UserId: helpers.CurrentUser(r).Id,
	}
	d := make(map[string]interface{})
	if j.Save() {
		d["job"] = j
	}
	w.Write(util.JSON(d))
}
예제 #7
0
func CreateController(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	p := plan.Plan{
		Name:  r.PostForm.Get("plan[name]"),
		Num:   getFormInt("plan[num]", r),
		JobId: getFormInt("plan[job_id]", r),
	}
	d := make(map[string]interface{})
	if p.Save() {
		d["plan"] = p
	}
	w.Write(util.JSON(d))
}
예제 #8
0
func DeleteController(w http.ResponseWriter, r *http.Request) {
	// TODO 404 if no job
	p := plan.Find(getId(r))
	p.Delete()
	w.Write(util.JSON(make(map[string]interface{})))
}
예제 #9
0
func DeleteController(w http.ResponseWriter, r *http.Request) {
	// TODO 404 if no job
	j := job.Find(getId(r), helpers.CurrentUser(r).Id)
	j.Delete()
	w.Write(util.JSON(make(map[string]interface{})))
}