BlogEngine.Blogs (blog_engine v0.1.0)

Copy Markdown View Source

Tenant-scoped blog configuration commands and reads.

Explicit nil attribute policy

Attribute maps distinguish an absent key from a key whose value is nil.

  • An absent key never reaches the changeset.
  • An explicit nil clears the column only for the nullable optional field :default_author_id.
  • An explicit nil for any other field — including the NOT NULL defaulted :navigation_label, :enabled, :route_params, :publication_policy, and :features — is ignored exactly as if the key had been omitted, so those fields fall back to the schema default on create and keep their stored value on update instead of raising a NOT NULL violation.

Summary

Functions

Creates one durable blog for a tenant publisher.

Disables a blog while preserving its durable identity and history.

Re-enables a disabled durable blog.

Returns the durable tenant publisher blog, creating it when absent.

Gets a blog by tenant-scoped ID.

Gets the durable blog for a tenant publisher identity.

Lists tenant blogs in stable publisher, name, and ID order.

Updates non-routing presentation and publication settings.

Atomically updates presentation settings and the blog's complete route set.

Functions

create(context, attrs)

@spec create(BlogEngine.Context.t(), map()) ::
  {:ok, BlogEngine.Schema.Blog.t()}
  | {:error, BlogEngine.Error.t() | Ecto.Changeset.t()}

Creates one durable blog for a tenant publisher.

Explicit nil values follow the module's nil policy: they clear only :default_author_id and are otherwise ignored.

disable(context, id)

Disables a blog while preserving its durable identity and history.

enable(context, id)

Re-enables a disabled durable blog.

ensure_for_publisher(context, publisher_type, publisher_key, attrs, opts)

@spec ensure_for_publisher(
  BlogEngine.Context.t(),
  String.t(),
  String.t(),
  map(),
  keyword()
) ::
  {:ok, BlogEngine.Schema.Blog.t()}
  | {:error, BlogEngine.Error.t() | Ecto.Changeset.t()}

Returns the durable tenant publisher blog, creating it when absent.

Publisher identity is supplied separately and cannot be overridden through attrs. The only accepted option is :id, which allows a host to provision a deterministic UUID. An already-existing publisher is returned unchanged. Concurrent callers converge on the publisher created by the winning call.

get(context, id)

Gets a blog by tenant-scoped ID.

get_for_publisher(context, publisher_type, publisher_key)

@spec get_for_publisher(BlogEngine.Context.t(), String.t(), String.t()) ::
  {:ok, BlogEngine.Schema.Blog.t()} | {:error, BlogEngine.Error.t()}

Gets the durable blog for a tenant publisher identity.

list(context, opts \\ [])

Lists tenant blogs in stable publisher, name, and ID order.

update(context, id, attrs)

Updates non-routing presentation and publication settings.

Explicit nil values follow the module's nil policy: they clear only :default_author_id and are otherwise ignored.

update_configuration(context, id, attrs)

@spec update_configuration(BlogEngine.Context.t(), Ecto.UUID.t(), map()) ::
  {:ok, BlogEngine.Schema.Blog.t()}
  | {:error, BlogEngine.Error.t() | Ecto.Changeset.t()}

Atomically updates presentation settings and the blog's complete route set.

Route changes use the routing lifecycle, so current and former post routes, audit records, and notifications are committed together with presentation changes. A failure in either half rolls the whole configuration update back.