View Source Mobilizon.Resources (Mobilizon v4.1.0-alpha.1)

The Resources context.

Summary

Functions

Link to this function

create_resource(attrs \\ %{})

View Source
@spec create_resource(map()) ::
  {:ok, Mobilizon.Resources.Resource.t()} | {:error, Ecto.Changeset.t()}

Creates a resource.

Link to this function

delete_resource(resource)

View Source
@spec delete_resource(Mobilizon.Resources.Resource.t()) ::
  {:ok, Mobilizon.Resources.Resource.t()} | {:error, Ecto.Changeset.t()}

Deletes a resource

@spec get_resource(integer() | String.t()) :: Mobilizon.Resources.Resource.t() | nil

Get a resource by it's ID

Link to this function

get_resource_by_group_and_path_with_preloads(group_id, path)

View Source
@spec get_resource_by_group_and_path_with_preloads(String.t() | integer(), String.t()) ::
  Mobilizon.Resources.Resource.t() | nil
Link to this function

get_resource_by_url(url)

View Source
@spec get_resource_by_url(String.t()) :: Mobilizon.Resources.Resource.t() | nil

Get a resource by it's URL

Link to this function

get_resource_by_url_with_preloads(url)

View Source
@spec get_resource_by_url_with_preloads(String.t()) ::
  Mobilizon.Resources.Resource.t() | nil
Link to this function

get_resource_with_preloads(id)

View Source
@spec get_resource_with_preloads(integer() | String.t()) ::
  Mobilizon.Resources.Resource.t() | nil
Link to this function

get_resources_for_folder(resource, page \\ nil, limit \\ nil)

View Source
@spec get_resources_for_folder(
  Mobilizon.Resources.Resource.t(),
  integer() | nil,
  integer() | nil
) ::
  Mobilizon.Storage.Page.t(Mobilizon.Resources.Resource.t())

Returns the list of resources for a resource folder.

Link to this function

get_resources_for_group(actor, page \\ nil, limit \\ nil)

View Source
@spec get_resources_for_group(
  Mobilizon.Actors.Actor.t(),
  integer() | nil,
  integer() | nil
) ::
  Mobilizon.Storage.Page.t(Mobilizon.Resources.Resource.t())

Returns the list of recent resources for a group

Link to this function

update_resource(resource, attrs)

View Source
@spec update_resource(Mobilizon.Resources.Resource.t(), map()) ::
  {:ok, Mobilizon.Resources.Resource.t()} | {:error, Ecto.Changeset.t()}

Updates a resource.

Since a resource can be a folder and hold children, we do the following in a transaction:

  • Get the parent path so that we can reconstruct the path for current resource (if moved or simply renamed)
  • Update all children with the new parent path
  • Update the resource path itself