Commit e2ee052c authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Doors api docs and refesh application repositories on api doc generation

parent 2192d7ca
<?php
namespace App\Documentation\Strategies;
use ReflectionClass;
use ReflectionMethod;
use Illuminate\Routing\Route;
use Source\Gateways\Users\UsersRepository;
use Source\Gateways\Doors\DoorsRepository;
use Source\Gateways\Groups\GroupsRepository;
use Source\Gateways\Tokens\TokensRepository;
use Mpociot\ApiDoc\Tools\DocumentationConfig;
use Source\Gateways\Users\LocalUsersRepository;
use Source\Gateways\Doors\LocalDoorsRepository;
use Illuminate\Contracts\Foundation\Application;
use Source\Gateways\Attempts\AttemptsRepository;
use Source\Gateways\DoorUser\DoorUserRepository;
use Source\Gateways\Groups\LocalGroupsRepository;
use Source\Gateways\Tokens\LocalTokensRepository;
use Mpociot\ApiDoc\Extracting\Strategies\Strategy;
use Source\Gateways\Schedules\SchedulesRepository;
use Source\Gateways\DoorGroup\DoorGroupRepository;
use Source\Gateways\GroupUser\GroupUserRepository;
use Source\Gateways\Attempts\LocalAttemptsRepository;
use Source\Gateways\DoorUser\LocalDoorUserRepository;
use Source\Gateways\Schedules\LocalSchedulesRepository;
use Source\Gateways\DoorGroup\LocalDoorGroupRepository;
use Source\Gateways\GroupUser\LocalGroupUserRepository;
use Source\Gateways\DoorSchedule\DoorScheduleRepository;
use Source\Gateways\DoorSchedule\LocalDoorScheduleRepository;
class ApplicationRepositoryResetStrategy extends Strategy
{
/**
* @var \Illuminate\Contracts\Foundation\Application
*/
protected Application $app;
public function __construct(string $stage, DocumentationConfig $config)
{
$this->app = app();
parent::__construct($stage, $config);
}
/**
* @inheritDoc
*/
public function __invoke(Route $route, ReflectionClass $controller, ReflectionMethod $method, array $routeRules, array $context = [])
{
$users = new LocalUsersRepository();
$doors = new LocalDoorsRepository();
$groups = new LocalGroupsRepository();
$schedules = new LocalSchedulesRepository();
$groupUser = new LocalGroupUserRepository($users, $groups);
$doorGroups = new LocalDoorGroupRepository($doors, $groups);
$this->app->instance(DoorGroupRepository::class, $doorGroups);
$this->app->instance(DoorsRepository::class, $doors);
$this->app->instance(DoorScheduleRepository::class, new LocalDoorScheduleRepository($doors, $doorGroups, $schedules));
$this->app->instance(DoorUserRepository::class, new LocalDoorUserRepository($users, $doors, $groupUser, $doorGroups));
$this->app->instance(GroupsRepository::class, $groups);
$this->app->instance(GroupUserRepository::class, $groupUser);
$this->app->instance(SchedulesRepository::class, $schedules);
$this->app->instance(TokensRepository::class, new LocalTokensRepository());
return null;
}
}
......@@ -19,6 +19,7 @@ use Source\UseCases\Door\StatusResponse\StatusResponseUseCase;
*
* Set of routes for door clients wanting to protect access to doors.
* Includes routes for verifying a doorcode as well as getting open mode times from schedules and overrides
* A header of Door-Controller-Version can be set with the the door client version.
*/
class DoorController extends ApiController
{
......@@ -56,7 +57,7 @@ class DoorController extends ApiController
$this->response->getStatusForDoor(
$this->doorGuard->id(),
Carbon::now(),
Carbon::now()->addMinutes($foresight),
Carbon::now()->addMinutes((int)$foresight),
$presenter
);
......@@ -72,7 +73,7 @@ class DoorController extends ApiController
*
* @authenticated
* @urlParam doorcode required The doorcode to query. Example: 123456*00110
* @queryParam Number of minutes ahead of now to get the open mode times for
* @queryParam foresight Number of minutes ahead of now to get the open mode times for. Example: 720
*
* @response 422 {"message":"The given data was invalid.","errors":{"foresight":["The foresight must be an
* integer."]}}
......@@ -101,7 +102,7 @@ class DoorController extends ApiController
* schedules as well as overrides. The door to get the times for is based off of the authenticated door.
*
* @authenticated
* @queryParam Number of minutes ahead of now to get the open mode times for
* @queryParam foresight Number of minutes ahead of now to get the open mode times for. Example: 720
*
* @response 422 {"message":"The given data was invalid.","errors":{"foresight":["The foresight must be an
* integer."]}}
......
......@@ -22,9 +22,24 @@ use Source\UseCases\DoorGroup\GetDoorGroups\APIPresenter as GetDoorGroupsAPIPres
use Source\UseCases\DoorGroup\AddDoorToGroup\APIPresenter as AddDoorToGroupAPIPresenter;
use Source\UseCases\DoorGroup\RemoveDoorFromGroup\APIPresenter as RemoveDoorFromGroupAPIPresenter;
/**
* @group Door Management
*
* This set of endpoints deals with the management of doors in the system. These route require the
* manage doors permission.
*/
class DoorsController extends ApiController
{
/**
* List/Search Doors
*
* This endpoint can list/search/query the list of doors. If the parameter is not given, it returns all doors
* paginated.
*
* @authenticated
* @paginated
* @queryParam query Searches doors for location, name, and version.
*
* @param \Source\UseCases\Doors\GetDoors\GetDoorsUseCase $getDoors
* @return \Illuminate\Http\JsonResponse
* @throws \Source\Exceptions\AuthorizationException
......@@ -36,7 +51,7 @@ class DoorsController extends ApiController
$this->authorizer->protect(Permissions::MANAGE_DOORS);
$this->validate($this->request, [
'query' => 'string'
'query' => 'string',
]);
$presenter = new GetAllDoorsAPIPresenter();
......@@ -49,6 +64,12 @@ class DoorsController extends ApiController
}
/**
* Get Door
*
* This endpoint gets a specific door and returns information relating directly to the door.
*
* @authenticated
*
* @param \Source\UseCases\Doors\GetDoor\GetDoorUseCase $getDoor
* @param string $doorId
* @return \Illuminate\Http\JsonResponse
......@@ -67,6 +88,14 @@ class DoorsController extends ApiController
}
/**
* Create Door
*
* This endpoint creates a new door in the system.
*
* @authenticated
* @bodyParam location required Door Number or location describing where it is such as `CSP165`. Example: CSP165
* @bodyParam name required The unique name for the door. Must be unique. Example: Engineering Lecture Hall
*
* @param \Source\UseCases\Doors\CreateDoor\CreateDoorUseCase $createDoor
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
......@@ -91,6 +120,15 @@ class DoorsController extends ApiController
}
/**
* Update Door
*
* This route updaets a door in the system. It does not modify the associated door token.
*
* @authenticated
* @urlParam doorId required The application ID of the door to update. Example: 2
* @bodyParam location Door Number or location describing where it is such as `CSP165`. Example: CSP166
* @bodyParam name The unique name for the door. Must be unique. Example: Not the Engineering Lecture Hall
*
* @param \Source\UseCases\Doors\UpdateDoor\UpdateDoorUseCase $updateDoor
* @param string $doorId
* @return \Illuminate\Http\JsonResponse
......@@ -117,6 +155,15 @@ class DoorsController extends ApiController
}
/**
* Regenerate Door Token
*
* This endpoint regenerates the door token as it is stored hashed in the database and cannot be retrieved once
* generated. If for some reason it gets lost, or compromised, this endpoint can be used to regenerate the
* associated door token.
*
* @authenticated
* @urlParam doorId required The application ID of the door to update. Example: 2
*
* @param \Source\UseCases\Doors\GenerateDoorToken\GenerateDoorTokenUseCase $tokenGenerator
* @param string $doorId
* @return \Illuminate\Http\JsonResponse
......@@ -136,6 +183,14 @@ class DoorsController extends ApiController
}
/**
* Delete Door
*
* This endpoint deletes a door in the system. Once deleted it cannot be recovered and the door
* will no longer be able to make requests.
*
* @authenticated
* @urlParam doorId required The application ID of the door to update. Example: 2
*
* @param \Source\UseCases\Doors\DeleteDoor\DeleteDoorUseCase $doorDelyeeter
* @param string $doorId
* @return \Illuminate\Http\JsonResponse
......
......@@ -245,7 +245,7 @@ return [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer door_1_api_token',
// 'Api-Version' => 'v2',
'Door-Controller-Version' => 'Api Doc Generator Client'
],
/*
......@@ -391,6 +391,7 @@ return [
\App\Documentation\Strategies\BodyAuthenticationStrategy::class,
],
'responses' => [
\App\Documentation\Strategies\ApplicationRepositoryResetStrategy::class,
\Mpociot\ApiDoc\Extracting\Strategies\Responses\UseTransformerTags::class,
\Mpociot\ApiDoc\Extracting\Strategies\Responses\UseResponseTag::class,
\Mpociot\ApiDoc\Extracting\Strategies\Responses\UseResponseFileTag::class,
......
......@@ -6,6 +6,7 @@ namespace Source\UseCases\Door\Commands;
use Carbon\Carbon;
use Source\Entities\User;
use Source\Entities\Override;
use Source\Gateways\Doors\DoorsRepository;
use Source\Exceptions\EntityNotFoundException;
use Source\Gateways\Overrides\OverridesRepository;
......
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