Пример #1
0
// ========================================================================================================================
// Procedure: createConnections
//
// Does:
// - Create all connections in DB for a particular user in order to use all applications
// ========================================================================================================================
func GetConnections(c *echo.Context) error {
	userList, err := users.FindUsers()
	if err != nil {
		return c.JSON(http.StatusInternalServerError, hash{
			"error": "Unable to retrieve users",
		})
	}
	user := c.Get("user").(*users.User)
	connections, err := apps.RetrieveConnections(user, userList)
	if err == apps.AppsListUnavailable {
		return c.JSON(http.StatusInternalServerError, hash{
			"error": "Unable to retrieve applications list",
		})
	}

	var response = make([]hash, len(connections))
	for i, val := range connections {
		res := hash{
			"id":         i,
			"type":       "application",
			"attributes": val,
		}
		response[i] = res
	}
	return c.JSON(http.StatusOK, hash{"data": response})
}
Пример #2
0
func Get(c *echo.Context) error {
	user := c.Get("user").(*users.User)
	if c.Query("me") == "true" {
		return utils.JSON(c, http.StatusOK, user)
	}

	if !user.IsAdmin {
		return apiErrors.AdminLevelRequired
	}

	users, err := users.FindUsers()
	if err != nil {
		log.Error(err)
		return apiErrors.InternalError.Detail("Unable to retreive the user list")
	}

	return utils.JSON(c, http.StatusOK, users)
}
Пример #3
0
func Get(c *echo.Context) error {
	users, err := users.FindUsers()
	if err != nil {
		return errors.New(
			fmt.Sprintf("unable to get user lists: %s", err.Error()),
		)
	}

	var response = make([]hash, len(*users))
	for i, val := range *users {
		res := hash{
			"id":         val.Id,
			"type":       "user",
			"attributes": val,
		}
		response[i] = res
	}
	return c.JSON(http.StatusOK, hash{"data": response})
}