Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Guardians of the Kretschmar Elock System
Doorcode
Commits
0980239d
Commit
0980239d
authored
May 17, 2020
by
Jacob Priddy
👌
Browse files
Add response to door access endponit
parent
d32f7c4b
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/web/backend/app/Http/Controllers/DoorController.php
View file @
0980239d
...
...
@@ -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
(
$
g
uard
->
id
(),
$doorcode
);
$access
->
protectUserDoorAccess
(
$
this
->
doorG
uard
->
id
(),
$doorcode
);
return
$this
->
respondS
ucces
s
();
return
$this
->
respondS
tatu
s
();
}
}
src/web/backend/config/app.php
View file @
0980239d
...
...
@@ -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
,
/*
|--------------------------------------------------------------------------
...
...
src/web/backend/src/Gateways/Schedules/LocalSchedulesRepository.php
View file @
0980239d
...
...
@@ -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'
,
...
...
src/web/backend/src/Gateways/Schedules/SchedulesRepositoryServiceProvider.php
View file @
0980239d
...
...
@@ -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
();
}
...
...
src/web/backend/src/UseCases/Door/StatusResponse/JsonPresenter.php
View file @
0980239d
...
...
@@ -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
()),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment