Commit c964f7df authored by Jacob Priddy's avatar Jacob Priddy 👌

Order doors by location

- Cache requests query as it is used several times
- Add more help example text for creating an access request
parent 9f0cfc11
Pipeline #12516 canceled with stages
in 42 seconds
<?php
use Source\Exceptions\EntityNotFoundException;
use Source\UseCases\Doors\GetDoor\APIPresenter as GetDoorPresenter;
use Source\UseCases\Doors\GetDoor\GetDoorUseCase;
use Source\UseCases\Requests\GetRequests\GetRequestsUseCase;
use Source\UseCases\Users\GetUser\APIPresenter as GetUserPresenter;
use Source\UseCases\Users\GetUser\GetUserUseCase;
use Source\Gateways\Users\DatabaseUsersRepository;
use Source\UseCases\Requests\GetRequests\GetRequestsCached;
use Source\UseCases\Requests\GetRequests\GetRequestsUseCase;
use Source\UseCases\Requests\GetRequests\MessageHotbarPresenter;
use Source\UseCases\Doors\GetDoor\APIPresenter as GetDoorPresenter;
use Source\UseCases\Users\GetUser\APIPresenter as GetUserPresenter;
if (! function_exists('user')) {
/**
......@@ -55,7 +56,7 @@ if (! function_exists('door')) {
try {
$getDoor->get($id, $presenter);
} catch (EntityNotFoundException $e) {
return null;
return [];
}
return $presenter->getViewModel()['door'];
......@@ -71,7 +72,7 @@ if (! function_exists('unread_access_requests')) {
$presenter = new MessageHotbarPresenter();
/** @var GetRequestsUseCase $useCase */
$useCase = app(GetRequestsUseCase::class);
$useCase = app(GetRequestsCached::class);
$useCase->filter([
'resolved' => false,
......
......@@ -53,6 +53,9 @@
Each line defines a property: RRULE, EXRULE, RDATE, EXDATE and DTSTART (there can be only one DTSTART).
It is the iCal specification for recurring events<br>
<br>
Example Every Day <br>
RRULE:FREQ=DAILY<br>
<br>
Example (Schedules every day at 8AM except Saturday starting June 29, 2020):<br>
DTSTART;TZID=America/Los_Angeles:20200629T080000<br>
RRULE:FREQ=WEEKLY;BYDAY=SU,MO,TU,WE,TH,FR;INTERVAL=1<br>
......
......@@ -78,8 +78,14 @@
<li class="nav-item {{ Nav::hasSegment('requests', 2) }}">
<a class="nav-link" href="{{ route('web.admin.requests.index') }}">
<i class="fas fa-fw fa-comment"></i>
<span>Requests</span>
<i class="fas fa-fw fa-comment">
</i>
<span>
Requests
</span>
@if (unread_access_requests()->getUnreadCount() > 0)
<span class="badge badge-danger">{{ unread_access_requests()->getUnreadCount() }}</span>
@endif
</a>
</li>
@endcan
......@@ -184,7 +190,9 @@
<a class="nav-link dropdown-toggle" href="#" id="messagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-envelope fa-fw"></i>
<!-- Counter - Messages -->
<span class="badge badge-danger badge-counter">{{ unread_access_requests()->getUnreadCount() }}</span>
@if (unread_access_requests()->getUnreadCount() > 0)
<span class="badge badge-danger badge-counter">{{ unread_access_requests()->getUnreadCount() }}</span>
@endif
</a>
<!-- Dropdown - Messages -->
<div class="dropdown-list dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="messagesDropdown">
......
......@@ -8,36 +8,37 @@
@include('partials.form-errors')
@if(request()->route()->named('*.build'))
<form method="POST" action="{{ route('web.requests.create') }}">
@else
<form method="POST" action="{{ route('web.requests.update', ['requestId' => $id]) }}">
@method('PUT')
@endif
@csrf
<div class="form-group">
<label for="name">
Request Summary
</label>
<input type="text" name="title" class="form-control" id="name"
value="{{ old('title') }}"
placeholder="Short Summary">
</div>
<div class="form-group">
<label for="body">
Request Body
</label>
<textarea class="form-control" name="request" id="body">{{ old('request') }}</textarea>
</div>
<div class="row">
<div class="col-sm-6 text-md-left text-center mb-2 mb-md-0">
<button type="submit" class="btn btn-success">Submit Request</button>
</div>
<div class="col-sm-6 text-md-right text-center">
<a class="btn btn-secondary" href="javascript:history.back()">
Cancel
</a>
</div>
</div>
</form>
@else
<form method="POST" action="{{ route('web.requests.update', ['requestId' => $id]) }}">
@method('PUT')
@endif
@csrf
<div class="form-group">
<label for="name">
Request Summary
</label>
<input type="text" name="title" class="form-control" id="name"
value="{{ old('title') }}"
placeholder="CSP318 Student Request for Lab Access">
</div>
<div class="form-group">
<label for="body">
Request Body
</label>
<textarea class="form-control" name="request" id="body"
placeholder="Hello, I am a third year EE student and need access to the EE Projects lab (CSP318) to work on my project.">{{ old('request') }}</textarea>
</div>
<div class="row">
<div class="col-sm-6 text-md-left text-center mb-2 mb-md-0">
<button type="submit" class="btn btn-success">Submit Request</button>
</div>
<div class="col-sm-6 text-md-right text-center">
<a class="btn btn-secondary" href="javascript:history.back()">
Cancel
</a>
</div>
</div>
</form>
</div>
</div>
@endsection
......@@ -125,7 +125,7 @@ class DatabaseDoorsRepository implements DoorsRepository
*/
public function search(?string $query = null, ?int $seenSinceSeconds = null, ?int $awolForSeconds = null): array
{
$doors = \App\Door::query()->orderByDesc('created_at');
$doors = \App\Door::query()->orderBy('location');
if ($seenSinceSeconds > 0) {
$doors->whereNotNull('last_seen_at')
......
<?php
namespace Source\UseCases\Requests\GetRequests;
use Source\Gateways\Requests\RequestsRepository;
class GetRequestsCached implements GetRequestsUseCase
{
/**
* @var \Source\Gateways\Requests\RequestsRepository
*/
protected RequestsRepository $requests;
protected ?array $cache = null;
public function __construct(RequestsRepository $requests)
{
$this->requests = $requests;
}
/**
* @inheritDoc
*/
public function filter(array $filters, Presenter $presenter): void
{
if ($this->cache === null) {
$this->cache = $this->requests->filter(
$filters['query'] ?? null,
$filters['user_id'] ?? null,
$filters['resolved'] ?? null,
$filters['replied'] ?? null
);
}
$response = new ResponseModel();
foreach ($this->cache as $request) {
$response->addRequest($request);
}
$presenter->present($response);
}
}
......@@ -5,6 +5,7 @@ namespace Source\UseCases\Requests\GetRequests;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;
use Source\Gateways\Requests\RequestsRepository;
use Illuminate\Contracts\Support\DeferrableProvider;
/**
......@@ -22,6 +23,11 @@ class GetRequestsUseCaseServiceProvider extends ServiceProvider implements Defer
$this->app->bind(GetRequestsUseCase::class, static function (Application $app) {
return $app->make(GetRequests::class);
});
$this->app->singleton(
GetRequestsCached::class,
fn(Application $app) => new GetRequestsCached($app->make(RequestsRepository::class))
);
}
/**
......@@ -29,6 +35,6 @@ class GetRequestsUseCaseServiceProvider extends ServiceProvider implements Defer
*/
public function provides(): array
{
return [GetRequestsUseCase::class];
return [GetRequestsUseCase::class, GetRequestsCached::class];
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment