示例#1
0
func TestAggregation(t *testing.T) {
	fm, _, db := setupAgg(t)
	defer teardownAgg(t, db)

	t.Log("Given the need to aggregate submissions.")
	{
		t.Log("\tWhen starting from a form and submission fixtures")
		{
			//----------------------------------------------------------------------
			// Aggregate the submissions.

			aggs, err := form.AggregateFormSubmissions(tests.Context, db, fm.ID.Hex())
			if err != nil {
				t.Fatalf("\t%s\tShould be able to aggregate submissions : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to aggregate submissions.", tests.Success)

			//----------------------------------------------------------------------
			// Check the aggregations.

			if len(aggs) != 11 {
				t.Fatalf("\t%s\tShould be able to get 11 aggregations : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to get 11 aggregations.", tests.Success)
		}
	}
}
示例#2
0
// Aggregate performs all aggregations across a form's submissions.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (aggregationHandle) Aggregate(c *web.Context) error {
	id := c.Params["form_id"]

	// Aggregations can be based on Queries or Filters.
	opts := submission.SearchOpts{
		Query:    c.Request.URL.Query().Get("search"),
		FilterBy: c.Request.URL.Query().Get("filterby"),
	}

	aggregations, err := form.AggregateFormSubmissions(c.SessionID, c.Ctx["DB"].(*db.DB), id, opts)
	if err == mgo.ErrNotFound {
		c.Respond(nil, http.StatusBadRequest)
	}
	if err != nil {
		return err
	}

	ak := AggregationKeys{
		Aggregations: aggregations,
	}

	c.Respond(ak, http.StatusOK)

	return nil
}
示例#3
0
// AggregateGroup performs all aggregations across a form's submissions and returns a single group.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (aggregationHandle) AggregateGroup(c *web.Context) error {
	id := c.Params["form_id"]

	// Aggregations can be based on Queries or Filters.
	opts := submission.SearchOpts{
		Query:    c.Request.URL.Query().Get("search"),
		FilterBy: c.Request.URL.Query().Get("filterby"),
	}

	aggregations, err := form.AggregateFormSubmissions(c.SessionID, c.Ctx["DB"].(*db.DB), id, opts)
	if err != nil {
		return err
	}

	aggregation, ok := aggregations[c.Params["group_id"]]
	if !ok {
		c.Respond(nil, http.StatusNotFound)
	}

	c.Respond(aggregation, http.StatusOK)

	return nil
}