CampaignFlow.MockServer.Storage.Postgres (CampaignFlow Client v2.2.0)

View Source

PostgreSQL storage adapter for the mock server.

Uses Ecto.Multi for atomic multi-table inserts when creating referrals.

Summary

Functions

Builds the API-shaped response map for a %Campaign{} struct without going back to the database. Allows callers that already have the struct in hand (e.g. immediately after an update) to avoid an extra repo.get/2 round-trip.

Fetches a campaign by ID, returning the raw %Campaign{} struct (not the API-shaped response map). Used by orchestration code that needs to inspect schema fields like referrer_tenant_id.

Updates a campaign's status given the already-loaded struct, skipping the initial repo.get/2. Used by cascading operations that already have the campaign in hand.

Functions

campaign_response(campaign)

@spec campaign_response(struct()) :: map()

Builds the API-shaped response map for a %Campaign{} struct without going back to the database. Allows callers that already have the struct in hand (e.g. immediately after an update) to avoid an extra repo.get/2 round-trip.

get_campaign_struct(id)

@spec get_campaign_struct(integer()) :: {:ok, struct()} | :not_found

Fetches a campaign by ID, returning the raw %Campaign{} struct (not the API-shaped response map). Used by orchestration code that needs to inspect schema fields like referrer_tenant_id.

update_campaign_status_struct(campaign, new_status)

@spec update_campaign_status_struct(
  struct(),
  String.t()
) :: {:ok, struct(), String.t()} | {:error, term()}

Updates a campaign's status given the already-loaded struct, skipping the initial repo.get/2. Used by cascading operations that already have the campaign in hand.