Commit 9a893292 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add response to door routes

parent 0980239d
......@@ -3,12 +3,16 @@
namespace App\Exceptions;
use Throwable;
use Carbon\Carbon;
use App\Guards\DoorGuard;
use Illuminate\Http\JsonResponse;
use Illuminate\Auth\AuthenticationException;
use Source\Exceptions\EntityExistsException;
use Source\Exceptions\AuthorizationException;
use Illuminate\Validation\ValidationException;
use Source\Exceptions\EntityNotFoundException;
use Source\UseCases\Door\StatusResponse\JsonPresenter;
use Source\UseCases\Door\StatusResponse\StatusResponseUseCase;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Source\Exceptions\AuthenticationException as SourceAuthenticationException;
......@@ -57,6 +61,22 @@ class Handler extends ExceptionHandler
}
if ($e instanceof AuthorizationException) {
if ($request->is('api/door/*')) {
/** @var DoorGuard $doorGuard */
$doorGuard = app()->make(DoorGuard::class);
if (!$doorGuard->id()) {
// Should not be authenticated
return response()->json(['message' => $e->getMessage()], 401);
}
$presenter = new JsonPresenter();
/** @var StatusResponseUseCase $useCase */
$useCase = app()->make(StatusResponseUseCase::class);
$useCase->getStatusForDoor($doorGuard->id(), Carbon::now(), Carbon::now()->addMinutes(config('app.status_foresight')), $presenter);
return new JsonResponse($presenter->getViewModel(), 401);
}
return response()->json(['message' => $e->getMessage()], 403);
}
......
......@@ -12,17 +12,17 @@ class LocalOverridesRepository extends InMemoryOverridesRepository
{
public function __construct()
{
$now = Carbon::now();
$date = Carbon::now()->addMinute();
$this->addOverride(new Override(
1,
'Override amazon door cause idk why just for some reason.',
LocalUsersRepository::getAdminUser()->getId(),
LocalDoorsRepository::getAmazonDoor()->getId(),
Override::TYPE_OPEN,
$now,
Carbon::now()->addMinutes(20),
$now,
$now
$date,
$date->clone()->addMinutes(20),
$date,
$date
));
$this->addOverride(new Override(
......@@ -31,10 +31,10 @@ class LocalOverridesRepository extends InMemoryOverridesRepository
LocalUsersRepository::getAdminUser()->getId(),
LocalDoorsRepository::getTheBatCave()->getId(),
Override::TYPE_LOCKED,
$now->clone()->subDay(),
Carbon::now()->subHours(15),
$now,
$now
$date->clone()->subDay(),
$date->clone()->subHours(15),
$date,
$date
));
}
}
......@@ -16,7 +16,7 @@ class LocalSchedulesRepository extends InMemorySchedulesRepository
LocalGroupsRepository::getEngineeringLabAccessGroup()->getId(),
Schedule::TYPE_USER_ACCESS,
// Allowed for a minute, not allowed for the next minute
'RRULE:FREQ=MINUTELY;INTERVAL=2',
'RRULE:FREQ=MINUTELY;INTERVAL=50',
1000 * 60,
'Engineering lab user access schedule, every other minute for a minute',
Carbon::now()
......
......@@ -3,9 +3,9 @@
namespace Source\UseCases\Door\StatusResponse;
use Carbon\Carbon;
use InvalidArgumentException;
use Source\Entities\Override;
use Source\Entities\Schedule;
use InvalidArgumentException;
use Source\Gateways\Overrides\OverridesRepository;
use Source\Gateways\DoorSchedule\DoorScheduleRepository;
use Source\Gateways\RecurrenceSet\RecurrenceSetRepository;
......
......@@ -3,7 +3,6 @@
namespace Tests\Unit\Source\UseCases\Door\StatusResponse;
use Source\UseCases\Door\StatusResponse\Presenter;
use Source\UseCases\Door\StatusResponse\ResponseModel;
......
......@@ -3,7 +3,6 @@
namespace Tests\Unit\Source\UseCases\Door\StatusResponse;
use Carbon\Carbon;
use Source\Entities\Override;
use Source\Entities\Schedule;
......
Supports Markdown
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