// ShowUsersHandler gets the data for one User. This function is mapped to
// the path GET /users/{user_id}
ShowUsersHandler gets the data for one User. This function is mapped to
the path GET /users/{user_id}
// ShowUsersHandler gets the data for one User . This function is mapped to // the path GET / users / { user_id }
func ShowUsersHandler(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)
	}
	allActivitiesStats, validActivitiesStats, err := user.GetStats(tx)
	if err != nil {
		c.Logger().Errorf("Error fetching user stats. %+v", err)
	}
	return responder.Wants("html", func(c buffalo.Context) error {
		c.Set("user", user)
		c.Set("allActivitiesStats", allActivitiesStats)
		c.Set("validActivitiesStats", validActivitiesStats)
		return c.Render(http.StatusOK, r.HTML("/users/show.plush.html"))
	}).Wants("json", func(c buffalo.Context) error {
		return c.Render(http.StatusOK, r.JSON(user))
	}).Wants("xml", func(c buffalo.Context) error {
		return c.Render(http.StatusOK, r.XML(user))
	}).Respond(c)
}
func ShowUsersHandler ( 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 ) } allActivitiesStats , validActivitiesStats , err := user . GetStats ( tx ) if err != nil { c . Logger ( ) . Errorf ( " " , err ) } return responder . Wants ( " " , func ( c buffalo . Context ) error { c . Set ( " " , user ) c . Set ( " " , allActivitiesStats ) c . Set ( " " , validActivitiesStats ) return c . Render ( http . StatusOK , r . HTML ( " " ) ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusOK , r . JSON ( user ) ) } ) . Wants ( " " , func ( c buffalo . Context ) error { return c . Render ( http . StatusOK , r . XML ( user ) ) } ) . Respond ( c ) }
ShowUsersHandler gets the data for one User.
ShowUsersHandler gets the data for one User .
// Get the DB connection from the context // Allocate an empty User // To find the User the parameter user_id is used.