Added a ticket view route

This commit is contained in:
Gregory Ballantine 2022-11-20 23:38:16 -05:00
parent 830a950bf4
commit 95bf9250e7
4 changed files with 33 additions and 1 deletions

View File

@ -9,6 +9,15 @@ use BitGoblin\Goliath\Models\Ticket;
class TicketController extends Controller {
public function getView(Request $request, Response $response, array $args): Response {
$ticket = Ticket::where('id', $args['ticket_id'])->get();
$view = Twig::fromRequest($request);
return $view->render($response, 'ticket/view.twig', [
'ticket' => $ticket[0],
]);
}
public function getCreate(Request $request, Response $response): Response {
$view = Twig::fromRequest($request);
return $view->render($response, 'ticket/create.twig');

View File

@ -10,3 +10,6 @@ $app->get('/', '\\BitGoblin\\Goliath\\Controllers\\HomeController:getIndex')->se
// /ticket/create GET route - allows a user to fill out a form to create a ticket
$app->get('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getCreate')->setName('ticket.create');
$app->post('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postCreate');
// /ticket/id route - displays ticket info to user
$app->get('/ticket/{ticket_id}', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getView')->setName('ticket.view');

View File

@ -19,7 +19,7 @@
</thead>
<tbody>
{% for ticket in tickets %}
<td>{{ ticket.title }}</td>
<td><a href="{{ url_for('ticket.view', {ticket_id: ticket.id}) }}">{{ ticket.title }}</a></td>
<td>{{ ticket.severity }}</td>
<td>{{ ticket.due_at }}</td>
{% endfor %}

20
views/ticket/view.twig Normal file
View File

@ -0,0 +1,20 @@
{% extends 'layout.twig' %}
{% block title %}Home{% endblock %}
{% block content %}
<div class="row">
<div class="columns twelve">
<h1>{{ ticket.title }}</h1>
<h5 class="ticket-created">Created at {{ ticket.created_at }} | Last updated at {{ ticket.updated_at }}</h5>
</div>
</div>
<hr>
<div class="row">
<div class="columns twelve">
<p>{{ ticket.body }}</p>
</div>
</div>
{% endblock %}