Commit 0980239d authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add response to door access endponit

parent d32f7c4b
......@@ -2,24 +2,62 @@
namespace App\Http\Controllers;
use Carbon\Carbon;
use App\Guards\DoorGuard;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Source\Authorization\Authorizer;
use Source\UseCases\Door\Access\AccessUseCase;
use Source\UseCases\Door\StatusResponse\JsonPresenter;
use Source\UseCases\Door\StatusResponse\StatusResponseUseCase;
class DoorController extends ApiController
{
/**
* @var \App\Guards\DoorGuard
*/
protected DoorGuard $doorGuard;
/**
* @var \Source\UseCases\Door\StatusResponse\StatusResponseUseCase
*/
protected StatusResponseUseCase $response;
public function __construct(Request $request, Authorizer $authorizer, DoorGuard $doorGuard, StatusResponseUseCase $response)
{
parent::__construct($request, $authorizer);
$this->doorGuard = $doorGuard;
$this->response = $response;
}
/**
* @return \Illuminate\Http\JsonResponse
*/
protected function respondStatus(): JsonResponse
{
$presenter = new JsonPresenter();
$this->response->getStatusForDoor(
$this->doorGuard->id(),
Carbon::now(),
Carbon::now()->addMinutes(config('app.status_foresight')),
$presenter
);
return $this->respondWithData($presenter->getViewModel());
}
/**
* @param string $doorcode
* @param \App\Guards\DoorGuard $guard
* @param \Source\UseCases\Door\Access\AccessUseCase $access
* @return \Illuminate\Http\JsonResponse
* @throws \Source\Exceptions\AuthenticationException
* @throws \Source\Exceptions\AuthorizationException
*/
public function access(string $doorcode, DoorGuard $guard, AccessUseCase $access): JsonResponse
public function access(string $doorcode, AccessUseCase $access): JsonResponse
{
$access->protectUserDoorAccess($guard->id(), $doorcode);
$access->protectUserDoorAccess($this->doorGuard->id(), $doorcode);
return $this->respondSuccess();
return $this->respondStatus();
}
}
......@@ -67,7 +67,18 @@ return [
|
*/
'timezone' => 'UTC',
'timezone' => 'America/Los_Angeles',
/*
|--------------------------------------------------------------------------
| Status Response Range
|--------------------------------------------------------------------------
|
| Specify the response range for events when doors make a request to
| the doors api. Units are in minutes.
|
*/
'status_foresight' => 60 * 12,
/*
|--------------------------------------------------------------------------
......
......@@ -9,11 +9,11 @@ use Source\Gateways\Groups\LocalGroupsRepository;
class LocalSchedulesRepository extends InMemorySchedulesRepository
{
public function __construct(LocalGroupsRepository $groups)
public function __construct()
{
$this->create(new Schedule(
1,
$groups::getEngineeringLabAccessGroup()->getId(),
LocalGroupsRepository::getEngineeringLabAccessGroup()->getId(),
Schedule::TYPE_USER_ACCESS,
// Allowed for a minute, not allowed for the next minute
'RRULE:FREQ=MINUTELY;INTERVAL=2',
......@@ -24,7 +24,7 @@ class LocalSchedulesRepository extends InMemorySchedulesRepository
$this->create(new Schedule(
1,
$groups::getComputerScienceMajorGroup()->getId(),
LocalGroupsRepository::getComputerScienceMajorGroup()->getId(),
Schedule::TYPE_OPEN_MODE,
// Open mode for 10 mintes, not open mode for 10 minutes
'RRULE:FREQ=MINUTELY;INTERVAL=20',
......
......@@ -4,7 +4,6 @@
namespace Source\Gateways\Schedules;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;
/**
......@@ -19,7 +18,7 @@ class SchedulesRepositoryServiceProvider extends ServiceProvider implements Defe
*/
public function register()
{
$this->app->singleton(SchedulesRepository::class, static function (Application $app) {
$this->app->singleton(SchedulesRepository::class, static function () {
if (env('APP_ENV') === 'memory') {
return new LocalSchedulesRepository();
}
......
......@@ -11,7 +11,7 @@ class JsonPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel = array_map(function (OpenEvent $event) {
$this->viewModel['events'] = array_map(function (OpenEvent $event) {
return [
'begins_at' => $this->formatDateTime($event->getBegin()),
'ends_at' => $this->formatDateTime($event->getEnd()),
......
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