Skip to content

Commit

Permalink
Added scrivener
Browse files Browse the repository at this point in the history
  • Loading branch information
MICHAELMUNAVU83 committed Jan 24, 2024
1 parent 0bbc804 commit 61a238f
Show file tree
Hide file tree
Showing 14 changed files with 325 additions and 168 deletions.
11 changes: 5 additions & 6 deletions lib/elixir_conf_africa/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
19 changes: 11 additions & 8 deletions lib/elixir_conf_africa/paystack.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule ElixirConfAfrica.Paystack do
alias ElixirConfAfrica.Repo

Check warning on line 2 in lib/elixir_conf_africa/paystack.ex

View workflow job for this annotation

GitHub Actions / Test

unused alias Repo

Check warning on line 2 in lib/elixir_conf_africa/paystack.ex

View workflow job for this annotation

GitHub Actions / Test

unused alias Repo

Check warning on line 2 in lib/elixir_conf_africa/paystack.ex

View workflow job for this annotation

GitHub Actions / Test

unused alias Repo

Check warning on line 2 in lib/elixir_conf_africa/paystack.ex

View workflow job for this annotation

GitHub Actions / Test

unused alias Repo
alias ElixirConfAfrica.Transaction

@moduledoc """
The Paystack module is responsible for all the interactions with the Paystack API
"""
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/elixir_conf_africa/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 32 additions & 12 deletions lib/elixir_conf_africa/tickets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,52 @@ 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 """
List refunded tickets.
"""
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 """
Expand Down
3 changes: 3 additions & 0 deletions lib/elixir_conf_africa/transaction.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule ElixirConfAfrica.Transaction do
defstruct [:reference, :amount, :status, :currency, :paid_at, :email, :bank]
end
11 changes: 9 additions & 2 deletions lib/elixir_conf_africa_web/live/paid_ticket_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
111 changes: 75 additions & 36 deletions lib/elixir_conf_africa_web/live/paid_ticket_live/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,41 +1,80 @@
<div class="flex justify-between items-center">
<h1 class="text-2xl font-bold">Listing Paid Tickets</h1>
</div>

<table class="w-[100%] mt-4">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Ticket id</th>
<th>Quantity</th>
<th>Amount</th>
<th>Type</th>
<th>Email Action</th>
</tr>
</thead>
<tbody class="p-2 text-center " id="ticket">
<%= for ticket <- @ticket_collection do %>
<tr id={"ticket-#{ticket.id}"}>
<td><%= ticket.name %></td>
<td><%= ticket.email %></td>
<td><%= ticket.ticketid %></td>
<td><%= ticket.quantity %></td>
<td><%= ticket.cost %> KSH /=</td>
<td><%= ticket.ticket_type.name %></td>
<td>
<div class="flex justify-center items-center p-2 rounded-md ">
<button
class="bg-green-500 text-white p-2 rounded-md"
phx-click="send_email"
phx-value-ticketid={ticket.ticketid}
id={"send-email-#{ticket.id}"}
>
Send Email
</button>
</div>
</td>
<div class="h-[80vh]">
<table class="w-[100%] mt-4">
<thead class="w-[100%]">
<tr>
<th>Name</th>
<th>Email</th>
<th>Ticket id</th>
<th>Quantity</th>
<th>Amount</th>
<th>Type</th>
<th>Email Action</th>
</tr>
</thead>
<tbody class="p-2 text-center " id="ticket">
<%= for ticket <- @ticket_collection do %>
<tr id={"ticket-#{ticket.id}"}>
<td><%= ticket.name %></td>
<td><%= ticket.email %></td>
<td><%= ticket.ticketid %></td>
<td><%= ticket.quantity %></td>
<td><%= ticket.cost %> KSH /=</td>
<td><%= ticket.ticket_type.name %></td>
<td>
<div class="flex justify-center items-center p-2 rounded-md ">
<button
class="bg-green-500 text-white p-2 rounded-md"
phx-click="send_email"
phx-value-ticketid={ticket.ticketid}
id={"send-email-#{ticket.id}"}
>
Send Email
</button>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>

<div class="flex items-center mt-4">
<div>
<%= if @page_number > 1 do %>
<.link navigate={~p"/tickets/paid?page=#{@page_number - 1}"}>
<div class="flex gap-2 items-center ">
Previous
</div>
</.link>
<% end %>
</div>

<div style="display: flex; flex-direction: row; padding: 2px;">
<%= for idx <- Enum.to_list(1..@total_pages) do %>
<.link navigate={~p"/tickets/paid?page=#{idx}"}>
<%= if @page_number == idx do %>
<p style="border: 1px solid black; padding-left: 5px; padding-right: 5px;">
<%= idx %>
</p>
<% else %>
<p style="padding-left: 5px; padding-right: 5px;">
<%= idx %>
</p>
<% end %>
</.link>
<% end %>
</div>

<div>
<%= if @page_number < @total_pages do %>
<.link navigate={~p"/tickets/paid?page=#{@page_number + 1}"}>
<div class="flex gap-2 items-center ">
Next
</div>
</.link>
<% end %>
</tbody>
</table>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,72 @@
<div class="flex justify-between items-center">
<h1 class="text-2xl font-bold">Listing Refunded Tickets</h1>
</div>

<table class="w-[100%] mt-4">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Ticket id</th>
<th>Quantity</th>
<th>Amount</th>
<th>Type</th>
</tr>
</thead>
<tbody class="p-2 text-center
<div class="h-[80vh]">
<table class="w-[100%] mt-4">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Ticket id</th>
<th>Quantity</th>
<th>Amount</th>
<th>Type</th>
</tr>
</thead>
<tbody class="p-2 text-center
" id="ticket">
<%= for ticket <- @ticket_collection do %>
<tr id={"ticket-#{ticket.id}"}>
<td><%= ticket.name %></td>
<td><%= ticket.email %></td>
<td><%= ticket.ticketid %></td>
<td><%= ticket.quantity %></td>
<td><%= ticket.cost %> KSH /=</td>
<td><%= ticket.ticket_type.name %></td>
</tr>
<%= for ticket <- @ticket_collection do %>
<tr id={"ticket-#{ticket.id}"}>
<td><%= ticket.name %></td>
<td><%= ticket.email %></td>
<td><%= ticket.ticketid %></td>
<td><%= ticket.quantity %></td>
<td><%= ticket.cost %> KSH /=</td>
<td><%= ticket.ticket_type.name %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

<div class="flex items-center mt-4">
<div>
<%= if @page_number > 1 do %>
<.link navigate={~p"/tickets/refunded?page=#{@page_number - 1}"}>
<div class="flex gap-2 items-center ">
Previous
</div>
</.link>
<% end %>
</tbody>
</table>
</div>

<div style="display: flex; flex-direction: row; padding: 2px;">
<%= for idx <- Enum.to_list(1..@total_pages) do %>
<.link navigate={~p"/tickets/refunded?page=#{idx}"}>
<%= if @page_number == idx do %>
<p style="border: 1px solid black; padding-left: 5px; padding-right: 5px;">
<%= idx %>
</p>
<% else %>
<p style="padding-left: 5px; padding-right: 5px;">
<%= idx %>
</p>
<% end %>
</.link>
<% end %>
</div>

<div>
<%= if @page_number < @total_pages do %>
<.link navigate={~p"/tickets/refunded?page=#{@page_number + 1}"}>
<div class="flex gap-2 items-center ">
Next
</div>
</.link>
<% end %>
</div>
</div>
Loading

0 comments on commit 61a238f

Please sign in to comment.