示例#1
0
文件: task.go 项目: pbochis/api
func Tasks(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
	if r.Method != "GET" {
		return http.StatusMethodNotAllowed, nil
	}

	p, ok := passenger.FromContext(ctx)
	if !ok {
		return http.StatusUnauthorized, nil
	}

	var u model.User
	if err = datastore.Get(ctx, p.User, &u); err != nil {
		return http.StatusInternalServerError, nil
	}

	// User is a coder
	if u.Company == nil {
		return http.StatusUnauthorized, nil
	}

	var tasks model.Tasks
	taskKeys, err := model.NewQueryForTask().
		GetAll(ctx, &tasks)

	if err != nil {
		return http.StatusInternalServerError, err
	}

	json.NewEncoder(w).Encode(tasks.Key(taskKeys))
	return http.StatusOK, nil
}
示例#2
0
文件: task.go 项目: flowlo/coduno-api
func getAllTasks(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
	var tasks model.Tasks
	taskKeys, err := model.NewQueryForTask().
		GetAll(ctx, &tasks)

	if err != nil {
		return http.StatusInternalServerError, err
	}

	json.NewEncoder(w).Encode(tasks.Key(taskKeys))
	return http.StatusOK, nil
}