diff --git a/lib/elixir_conf_africa/accounts.ex b/lib/elixir_conf_africa/accounts.ex
index cbc2b77..c1f7b98 100644
--- a/lib/elixir_conf_africa/accounts.ex
+++ b/lib/elixir_conf_africa/accounts.ex
@@ -31,13 +31,12 @@ defmodule ElixirConfAfrica.Accounts do
"""
def list_users_apart_from_current_user(current_user) do
- Repo.all(
- from(u in User,
- where: u.id != ^current_user.id,
- order_by: u.email,
- select: u
- )
+ from(u in User,
+ where: u.id != ^current_user.id,
+ order_by: u.email,
+ select: u
)
+ |> Repo.paginate()
end
@doc """
diff --git a/lib/elixir_conf_africa/paystack.ex b/lib/elixir_conf_africa/paystack.ex
index 6b7a870..3d25763 100644
--- a/lib/elixir_conf_africa/paystack.ex
+++ b/lib/elixir_conf_africa/paystack.ex
@@ -1,4 +1,7 @@
defmodule ElixirConfAfrica.Paystack do
+ alias ElixirConfAfrica.Repo
+ alias ElixirConfAfrica.Transaction
+
@moduledoc """
The Paystack module is responsible for all the interactions with the Paystack API
"""
@@ -71,14 +74,14 @@ defmodule ElixirConfAfrica.Paystack do
def list_transactions do
get_transactions()
|> Enum.map(fn transaction ->
- %{
- "reference" => transaction["reference"],
- "amount" => transaction["amount"],
- "status" => transaction["status"],
- "currency" => transaction["currency"],
- "paid_at" => transaction["paid_at"],
- "email" => transaction["customer"]["email"],
- "bank" => transaction["authorization"]["bank"]
+ %Transaction{
+ amount: transaction["amount"],
+ status: transaction["status"],
+ currency: transaction["currency"],
+ paid_at: transaction["paid_at"],
+ email: transaction["customer"]["email"],
+ bank: transaction["authorization"]["bank"],
+ reference: transaction["reference"]
}
end)
end
diff --git a/lib/elixir_conf_africa/repo.ex b/lib/elixir_conf_africa/repo.ex
index f288b17..0656b65 100644
--- a/lib/elixir_conf_africa/repo.ex
+++ b/lib/elixir_conf_africa/repo.ex
@@ -2,4 +2,6 @@ defmodule ElixirConfAfrica.Repo do
use Ecto.Repo,
otp_app: :elixir_conf_africa,
adapter: Ecto.Adapters.Postgres
+
+ use Scrivener, page_size: 10
end
diff --git a/lib/elixir_conf_africa/tickets.ex b/lib/elixir_conf_africa/tickets.ex
index 492983a..b9f15ca 100644
--- a/lib/elixir_conf_africa/tickets.ex
+++ b/lib/elixir_conf_africa/tickets.ex
@@ -37,10 +37,12 @@ defmodule ElixirConfAfrica.Tickets do
"""
def list_paid_tickets do
- Ticket
- |> where([t], t.is_paid == true and t.is_refunded == false)
- |> Repo.all()
- |> Repo.preload(:ticket_type)
+ from(t in Ticket,
+ where: t.is_paid and t.is_refunded == false,
+ select: t,
+ preload: [:ticket_type]
+ )
+ |> Repo.paginate()
end
@doc """
@@ -48,21 +50,39 @@ defmodule ElixirConfAfrica.Tickets do
"""
def list_refunded_tickets do
- Ticket
- |> where([t], t.is_refunded == true)
- |> Repo.all()
- |> Repo.preload(:ticket_type)
+ from(t in Ticket,
+ where: t.is_refunded,
+ select: t,
+ preload: [:ticket_type]
+ )
+ |> Repo.paginate()
end
@doc """
List unpaid tickets.
"""
+
def list_unpaid_tickets do
- Ticket
- |> where([t], t.is_paid == false and t.is_refunded == false)
- |> Repo.all()
- |> Repo.preload(:ticket_type)
+ from(t in Ticket,
+ where: t.is_paid == false and t.is_refunded == false,
+ left_join: type in assoc(t, :ticket_type),
+ on: type.id == t.ticket_type_id,
+ select: %{
+ id: t.id,
+ name: t.name,
+ email: t.email,
+ quantity: t.quantity,
+ phone_number: t.phone_number,
+ cost: t.cost,
+ ticketid: t.ticketid,
+ ticket_type_id: t.ticket_type_id,
+ is_paid: t.is_paid,
+ is_refunded: t.is_refunded,
+ ticket_type: type
+ }
+ )
+ |> Repo.paginate()
end
@doc """
diff --git a/lib/elixir_conf_africa/transaction.ex b/lib/elixir_conf_africa/transaction.ex
new file mode 100644
index 0000000..cdf47e7
--- /dev/null
+++ b/lib/elixir_conf_africa/transaction.ex
@@ -0,0 +1,3 @@
+defmodule ElixirConfAfrica.Transaction do
+ defstruct [:reference, :amount, :status, :currency, :paid_at, :email, :bank]
+end
diff --git a/lib/elixir_conf_africa_web/live/paid_ticket_live/index.ex b/lib/elixir_conf_africa_web/live/paid_ticket_live/index.ex
index ca7f5bd..2369ffb 100644
--- a/lib/elixir_conf_africa_web/live/paid_ticket_live/index.ex
+++ b/lib/elixir_conf_africa_web/live/paid_ticket_live/index.ex
@@ -6,7 +6,13 @@ defmodule ElixirConfAfricaWeb.PaidTicketLive.Index do
@impl true
def mount(_params, _session, socket) do
- {:ok, assign(socket, :ticket_collection, list_paid_tickets())}
+ {:ok,
+ socket
+ |> assign(:page_number, list_paid_tickets().page_number)
+ |> assign(:page_size, list_paid_tickets().page_size)
+ |> assign(:total_entries, list_paid_tickets().total_entries)
+ |> assign(:total_pages, list_paid_tickets().total_pages)
+ |> assign(:ticket_collection, list_paid_tickets().entries)}
end
@impl true
@@ -30,7 +36,8 @@ defmodule ElixirConfAfricaWeb.PaidTicketLive.Index do
|> put_flash(:info, "Ticket sent successfully")}
end
- defp list_paid_tickets do
+ defp list_paid_tickets() do
Tickets.list_paid_tickets()
+ |> IO.inspect()
end
end
diff --git a/lib/elixir_conf_africa_web/live/paid_ticket_live/index.html.heex b/lib/elixir_conf_africa_web/live/paid_ticket_live/index.html.heex
index 04ec952..26db34b 100644
--- a/lib/elixir_conf_africa_web/live/paid_ticket_live/index.html.heex
+++ b/lib/elixir_conf_africa_web/live/paid_ticket_live/index.html.heex
@@ -1,41 +1,80 @@
Listing Paid Tickets
-
-
-
-
- Name |
- Email |
- Ticket id |
- Quantity |
- Amount |
- Type |
- Email Action |
-
-
-
- <%= for ticket <- @ticket_collection do %>
-
- <%= ticket.name %> |
- <%= ticket.email %> |
- <%= ticket.ticketid %> |
- <%= ticket.quantity %> |
- <%= ticket.cost %> KSH /= |
- <%= ticket.ticket_type.name %> |
-
-
-
-
- |
+
+
+
+
+ Name |
+ Email |
+ Ticket id |
+ Quantity |
+ Amount |
+ Type |
+ Email Action |
+
+
+ <%= for ticket <- @ticket_collection do %>
+
+ <%= ticket.name %> |
+ <%= ticket.email %> |
+ <%= ticket.ticketid %> |
+ <%= ticket.quantity %> |
+ <%= ticket.cost %> KSH /= |
+ <%= ticket.ticket_type.name %> |
+
+
+
+
+ |
+
+ <% end %>
+
+
+
+
+
+
+ <%= if @page_number > 1 do %>
+ <.link navigate={~p"/tickets/paid?page=#{@page_number - 1}"}>
+
+ Previous
+
+
+ <% end %>
+
+
+
+ <%= for idx <- Enum.to_list(1..@total_pages) do %>
+ <.link navigate={~p"/tickets/paid?page=#{idx}"}>
+ <%= if @page_number == idx do %>
+
+ <%= idx %>
+
+ <% else %>
+
+ <%= idx %>
+
+ <% end %>
+
+ <% end %>
+
+
+
+ <%= if @page_number < @total_pages do %>
+ <.link navigate={~p"/tickets/paid?page=#{@page_number + 1}"}>
+
+ Next
+
+
<% end %>
-
-
+
+
diff --git a/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.ex b/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.ex
index 6c639e7..aea80c8 100644
--- a/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.ex
+++ b/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.ex
@@ -5,7 +5,13 @@ defmodule ElixirConfAfricaWeb.RefundedTicketLive.Index do
@impl true
def mount(_params, _session, socket) do
- {:ok, assign(socket, :ticket_collection, list_refunded_tickets())}
+ {:ok,
+ socket
+ |> assign(:page_number, list_refunded_tickets().page_number)
+ |> assign(:page_size, list_refunded_tickets().page_size)
+ |> assign(:total_entries, list_refunded_tickets().total_entries)
+ |> assign(:total_pages, list_refunded_tickets().total_pages)
+ |> assign(:ticket_collection, list_refunded_tickets().entries)}
end
@impl true
diff --git a/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.html.heex b/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.html.heex
index 199f01d..81a5d9b 100644
--- a/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.html.heex
+++ b/lib/elixir_conf_africa_web/live/refunded_ticket_live/index.html.heex
@@ -1,33 +1,72 @@
Listing Refunded Tickets
-
-
-
-
- Name |
- Email |
- Ticket id |
- Quantity |
- Amount |
- Type |
-
-
-
+
+
+
+ Name |
+ Email |
+ Ticket id |
+ Quantity |
+ Amount |
+ Type |
+
+
+
- <%= for ticket <- @ticket_collection do %>
-
- <%= ticket.name %> |
- <%= ticket.email %> |
- <%= ticket.ticketid %> |
- <%= ticket.quantity %> |
- <%= ticket.cost %> KSH /= |
- <%= ticket.ticket_type.name %> |
-
+ <%= for ticket <- @ticket_collection do %>
+
+ <%= ticket.name %> |
+ <%= ticket.email %> |
+ <%= ticket.ticketid %> |
+ <%= ticket.quantity %> |
+ <%= ticket.cost %> KSH /= |
+ <%= ticket.ticket_type.name %> |
+
+ <% end %>
+
+
+
+
+
+
+ <%= if @page_number > 1 do %>
+ <.link navigate={~p"/tickets/refunded?page=#{@page_number - 1}"}>
+
+ Previous
+
+
<% end %>
-
-
+
+
+
+ <%= for idx <- Enum.to_list(1..@total_pages) do %>
+ <.link navigate={~p"/tickets/refunded?page=#{idx}"}>
+ <%= if @page_number == idx do %>
+
+ <%= idx %>
+
+ <% else %>
+
+ <%= idx %>
+
+ <% end %>
+
+ <% end %>
+
+
+
+ <%= if @page_number < @total_pages do %>
+ <.link navigate={~p"/tickets/refunded?page=#{@page_number + 1}"}>
+
+ Next
+
+
+ <% end %>
+
+
diff --git a/lib/elixir_conf_africa_web/live/transaction_live/index.html.heex b/lib/elixir_conf_africa_web/live/transaction_live/index.html.heex
index c0ac271..0a1884a 100644
--- a/lib/elixir_conf_africa_web/live/transaction_live/index.html.heex
+++ b/lib/elixir_conf_africa_web/live/transaction_live/index.html.heex
@@ -20,14 +20,14 @@
<%= for transaction <- @transactions do %>
- <%= transaction["reference"] %> |
- <%= transaction["amount"] %> |
- <%= transaction["status"] %> |
- <%= transaction["currency"] %> |
+ <%= transaction.reference %> |
+ <%= transaction.amount %> |
+ <%= transaction.status %> |
+ <%= transaction.currency %> |
- <%= transaction["email"] %> |
- <%= transaction["bank"] %> |
- <%= transaction["paid_at"] %> |
+ <%= transaction.email %> |
+ <%= transaction.bank %> |
+ <%= transaction.paid_at %> |
<% end %>
diff --git a/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.ex b/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.ex
index 8fcab0c..fba28ce 100644
--- a/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.ex
+++ b/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.ex
@@ -7,7 +7,15 @@ defmodule ElixirConfAfricaWeb.UnPaidTicketLive.Index do
alias ElixirConfAfrica.Paystack
@impl true
def mount(_params, _session, socket) do
- {:ok, assign(socket, :ticket_collection, list_unpaid_tickets())}
+ unpaid_tickets = Tickets.list_unpaid_tickets()
+
+ {:ok,
+ socket
+ |> assign(:page_number, unpaid_tickets.page_number)
+ |> assign(:page_size, unpaid_tickets.page_size)
+ |> assign(:total_entries, unpaid_tickets.total_entries)
+ |> assign(:total_pages, unpaid_tickets.total_pages)
+ |> assign(:ticket_collection, list_unpaid_tickets())}
end
@impl true
@@ -33,23 +41,12 @@ defmodule ElixirConfAfricaWeb.UnPaidTicketLive.Index do
end
defp list_unpaid_tickets do
- Tickets.list_unpaid_tickets()
+ Tickets.list_unpaid_tickets().entries
|> Enum.map(fn ticket ->
- %{
- id: ticket.id,
- name: ticket.name,
- email: ticket.email,
- quantity: ticket.quantity,
- phone_number: ticket.phone_number,
- cost: ticket.cost,
- ticketid: ticket.ticketid,
- ticket_type_id: ticket.ticket_type_id,
- is_paid: ticket.is_paid,
- is_refunded: ticket.is_refunded,
- ticket_type: ticket.ticket_type,
- payment_status: check_payment_status(ticket.ticketid)
- }
+ ticket
+ |> Map.put(:payment_status, check_payment_status(ticket.ticketid))
end)
+ |> IO.inspect()
end
defp check_payment_status(ticketid) do
diff --git a/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.html.heex b/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.html.heex
index 9489184..0bcce3e 100644
--- a/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.html.heex
+++ b/lib/elixir_conf_africa_web/live/unpaid_ticket_live/index.html.heex
@@ -1,63 +1,102 @@
Listing Unpaid Tickets
-
-
-
-
- Name |
- Email |
- Ticket id |
- Quantity |
- Amount |
- Type |
- Status |
-
- Action
- |
-
-
-
- <%= for ticket <- @ticket_collection do %>
-
+
+
+
+ Name |
+ Email |
+ Ticket id |
+ Quantity |
+ Amount |
+ Type |
+ Status |
+
+ Action
+ |
+
+
+
+ <%= for ticket <- @ticket_collection do %>
+
- <%= ticket.name %> |
- <%= ticket.email %> |
- <%= ticket.ticketid %> |
- <%= ticket.quantity %> |
- <%= ticket.cost %> KSH /= |
- <%= ticket.ticket_type.name %> |
+ >
+ <%= ticket.name %> |
+ <%= ticket.email %> |
+ <%= ticket.ticketid %> |
+ <%= ticket.quantity %> |
+ <%= ticket.cost %> KSH /= |
+ <%= ticket.ticket_type.name %> |
-
- <%= if ticket.payment_status == "correct" do %>
-
- Correct
-
- <% else %>
-
- Incorrect
-
- <% end %>
- |
+
+ <%= if ticket.payment_status == "correct" do %>
+
+ Correct
+
+ <% else %>
+
+ Incorrect
+
+ <% end %>
+ |
-
- <%= if ticket.payment_status == "incorrect" do %>
-
-
-
- <% end %>
- |
-
+
+ <%= if ticket.payment_status == "incorrect" do %>
+
+
+
+ <% end %>
+ |
+
+ <% end %>
+
+
+
+
+
+
+ <%= if @page_number > 1 do %>
+ <.link navigate={~p"/tickets/unpaid?page=#{@page_number - 1}"}>
+
+ Previous
+
+
<% end %>
-
-
+
+
+
+ <%= for idx <- Enum.to_list(1..@total_pages) do %>
+ <.link navigate={~p"/tickets/unpaid?page=#{idx}"}>
+ <%= if @page_number == idx do %>
+
+ <%= idx %>
+
+ <% else %>
+
+ <%= idx %>
+
+ <% end %>
+
+ <% end %>
+
+
+
+ <%= if @page_number < @total_pages do %>
+ <.link navigate={~p"/tickets/unpaid?page=#{@page_number + 1}"}>
+
+ Next
+
+
+ <% end %>
+
+
diff --git a/mix.exs b/mix.exs
index bb2f687..be60c63 100644
--- a/mix.exs
+++ b/mix.exs
@@ -69,7 +69,8 @@ defmodule ElixirConfAfrica.MixProject do
{:typed_ecto_schema, "~> 0.4.1"},
{:ex_machina, "~> 2.7.0"},
{:httpoison, "~> 2.1"},
- {:styler, "~> 0.11", only: [:dev, :test], runtime: false}
+ {:styler, "~> 0.11", only: [:dev, :test], runtime: false},
+ {:scrivener_ecto, "~> 2.7"}
]
end
diff --git a/mix.lock b/mix.lock
index 46b7965..e419940 100644
--- a/mix.lock
+++ b/mix.lock
@@ -49,6 +49,8 @@
"plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"},
"postgrex": {:hex, :postgrex, "0.17.3", "c92cda8de2033a7585dae8c61b1d420a1a1322421df84da9a82a6764580c503d", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "946cf46935a4fdca7a81448be76ba3503cff082df42c6ec1ff16a4bdfbfb098d"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
+ "scrivener": {:hex, :scrivener, "2.7.2", "1d913c965ec352650a7f864ad7fd8d80462f76a32f33d57d1e48bc5e9d40aba2", [:mix], [], "hexpm", "7866a0ec4d40274efbee1db8bead13a995ea4926ecd8203345af8f90d2b620d9"},
+ "scrivener_ecto": {:hex, :scrivener_ecto, "2.7.0", "cf64b8cb8a96cd131cdbcecf64e7fd395e21aaa1cb0236c42a7c2e34b0dca580", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:scrivener, "~> 2.4", [hex: :scrivener, repo: "hexpm", optional: false]}], "hexpm", "e809f171687806b0031129034352f5ae44849720c48dd839200adeaf0ac3e260"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"styler": {:hex, :styler, "0.11.6", "ad4c5fc1ff72b93107ecb251f595b316c6d97604b742f3473aa036888592b270", [:mix], [], "hexpm", "0b0b9936e91b01a7a9fd7239902581ed1cb5515254357126429a37d1bb3d0078"},
"swoosh": {:hex, :swoosh, "1.14.1", "d8813699ba410509008dd3dfdb2df057e3fce367d45d5e6d76b146a7c9d559cd", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.4 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "87da72260b4351678f96aec61db5c2acc8a88cda2cf2c4f534eb4c9c461350c7"},