Пример #1
0
func UpdateMilestone(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	milestoneID := parser.Int(r.FormValue("milestoneID"))
	date := parser.Time(r.FormValue("date"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	if !user.IsAuthor(projectID) {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	title := r.FormValue("title")
	description := r.FormValue("description")

	if err := store.UpdateMilestone(store.UpdateMilestoneParams{
		MilestoneID: milestoneID,
		Title:       title,
		Description: description,
		Date:        date,
	}); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, nil)
}
Пример #2
0
func CreateTask(w http.ResponseWriter, r *http.Request) {
	var parser store.Parser

	projectID := parser.Int(r.FormValue("projectID"))
	startDate := parser.Time(r.FormValue("startDate"))
	endDate := parser.Time(r.FormValue("endDate"))
	if parser.Err != nil {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	if startDate.After(endDate) {
		response.ClientError(w, http.StatusBadRequest)
		return
	}

	user := context.Get(r, "user").(store.User)
	if !user.IsMember(projectID) {
		response.ClientError(w, http.StatusForbidden)
		return
	}

	var taskID int64
	var err error

	if taskID, err = store.CreateTask(store.CreateTaskParams{
		AuthorID:    user.ID(),
		ProjectID:   projectID,
		Title:       r.FormValue("title"),
		Description: r.FormValue("description"),
		Done:        false,
		Tags:        strings.Split(r.FormValue("tags"), ","),
		StartDate:   startDate,
		EndDate:     endDate,
	}); err != nil {
		response.ServerError(w, err)
		return
	}

	response.OK(w, taskID)
}