Linkhut.Links (linkhut v0.1.0)

View Source

The Links context.

Summary

Types

A Link struct.

Functions

Returns all non-private links

Returns all Links belonging to the given user.

Returns an %Ecto.Changeset{} for tracking link changes.

Creates a link.

Deletes a link.

Returns a Link for a given url and user id.

Returns a Link for a given url and user id.

Returns the most recent link modified (as in inserted or updated) by a user

Returns the most popular public links

Returns most recent public links

Returns the unread links for a user

Returns the number of unread links for a user

Updates a link.

Types

link()

@type link() :: %Linkhut.Links.Link{
  __meta__: term(),
  inserted_at: term(),
  is_private: term(),
  is_unread: term(),
  language: term(),
  notes: term(),
  notes_html: term(),
  savers: term(),
  saves: term(),
  score: term(),
  tags: term(),
  title: term(),
  updated_at: term(),
  url: term(),
  user: term(),
  user_id: term(),
  variants: term()
}

A Link struct.

Functions

all()

Returns all non-private links

all(params)

all(user, params \\ [])

Returns all Links belonging to the given user.

change_link(link, attrs \\ %{})

Returns an %Ecto.Changeset{} for tracking link changes.

Examples

iex> change_link(link)
%Ecto.Changeset{data: %Link{}}

create_link(user, attrs)

Creates a link.

Examples

iex> create_link(user, %{field: value})
{:ok, %Link{}}

iex> create_link(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}

delete_link(link)

Deletes a link.

Examples

iex> delete_link(link)
{:ok, %Link{}}

iex> delete_link(link)
{:error, %Ecto.Changeset{}}

get(url, user_id)

@spec get(String.t(), integer()) :: link()

Returns a Link for a given url and user id.

Returns nil if no result is found.

Examples

iex> get("http://example.com", 123)
%Link{}

iex> get("http://example.com", 456)
nil

get!(url, user_id)

@spec get!(String.t(), integer()) :: link()

Returns a Link for a given url and user id.

Raises Ecto.NoResultsError if the User does not exist.

Examples

iex> get!("http://example.com", 123)
%Link{}

iex> get!("http://example.com", 456)
** (Ecto.NoResultsError)

links(params \\ [])

most_recent(user)

Returns the most recent link modified (as in inserted or updated) by a user

ordering(query, opts)

popular(params, popularity \\ 3)

Returns the most popular public links

recent(params, days \\ 30)

Returns most recent public links

unread(user_id, params)

Returns the unread links for a user

unread_count(user_id)

Returns the number of unread links for a user

update_link(link, attrs)

Updates a link.

Examples

iex> update_link(link, %{field: new_value})
{:ok, %Link{}}

iex> update_link(link, %{field: bad_value})
{:error, %Ecto.Changeset{}}