// ListUserActivitiesHandler will list all activities (does NOT call the provider)
ListUserActivitiesHandler will list all activities (does NOT call the provider)
// ListUserActivitiesHandler will list all activities ( does NOT call the provider )
func ListUserActivitiesHandler(c buffalo.Context) error {
	tx, ok := c.Value("tx").(*pop.Connection)
	if !ok {
		return fmt.Errorf("no transaction found")
	}
	user := &models.User{}
	if err := tx.Find(user, c.Param("user_id")); err != nil {
		return c.Error(http.StatusNotFound, err)
	}
	activities := &models.Activities{}
	q := tx.PaginateFromParams(c.Params())
	if err := q.Where("user_id = ?", c.Param("user_id")).Order("activities.datetime DESC").All(activities); err != nil {
		c.Flash().Add("error", fmt.Sprintf("Could not fetch activities (%s)", err))
		c.Logger().Error(err)
		return c.Redirect(http.StatusSeeOther, "/users/"+c.Param("user_id"))
	}
	return responder.Wants("html", func(c buffalo.Context) error {
		c.Set("pagination", q.Paginator)
		c.Set("user", user)
		c.Set("activities", activities)
		return c.Render(http.StatusOK, r.HTML("/users/activities.plush.html"))
	}).Wants("json", func(c buffalo.Context) error {
		return c.Render(http.StatusOK, r.JSON(activities))
	}).Wants("xml", func(c buffalo.Context) error {
		return c.Render(http.StatusOK, r.XML(activities))
	}).Respond(c)
}
func ListUserActivitiesHandler ( c buffalo . Context ) error { tx , ok := c . Value ( " " ) . ( * pop . Connection ) if ! ok { return fmt . Errorf ( " " ) } user := & models . User { } if err := tx . Find ( user , c . Param ( " " ) ) ; err != nil { return c . Error ( http . StatusNotFound , err ) } activities := & models . Activities { } q := tx . PaginateFromParams ( c . Params ( ) ) if err := q . Where ( " " , c . Param ( " " ) ) . Order ( " " ) . All ( activities ) ; err != nil { c . Flash ( ) . Add ( " " , fmt . Sprintf ( " " , err ) ) c . Logger ( ) . Error ( err ) return c . Redirect ( http . StatusSeeOther , " " + c . Param ( " " ) ) } return responder . Wants ( " " , func ( c buffalo . Context ) error { c . Set ( " " , q . Paginator ) c . Set ( " " , user ) c . Set ( " " , activities ) return c . Render ( http . StatusOK , r . HTML ( " " ) ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusOK , r . JSON ( activities ) ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusOK , r . XML ( activities ) ) } ) . Respond ( c ) }
ListUserActivitiesHandler will list all activities (does NOT call the provider)
ListUserActivitiesHandler will list all activities ( does NOT call the provider )
// Get the DB connection from the context // To find the User the parameter user_id is used. // Paginate results. Params "page" and "per_page" control pagination. // Default values are "page=1" and "per_page=20". // To find the User the parameter user_id is used.