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
d7db4aba
Commit
d7db4aba
authored
Apr 09, 2020
by
Jacob Priddy
👌
Browse files
Add use cases for entries read
parent
5763737f
Changes
13
Hide whitespace changes
Inline
Side-by-side
src/web/backend/app/Providers/AppServiceProvider.php
View file @
d7db4aba
...
...
@@ -45,10 +45,13 @@ use Source\UseCases\TokenUser\GetUserTokens\GetUserTokensUseCaseServiceProvider;
use
Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupUseCaseServiceProvider
;
use
Source\UseCases\GroupUser\AddUserToGroup\AddUserToGroupUseCaseServiceProvider
;
use
Source\UseCases\Doors\GenerateDoorToken\GenerateDoorTokenUseCaseServiceProvider
;
use
Source\UseCases\Entries\GetEntriesForDoor\GetEntriesForDoorUseCaseServiceProvider
;
use
Source\UseCases\Entries\GetEntriesForUser\GetEntriesForUserUseCaseServiceProvider
;
use
Source\UseCases\Attempts\GetAttemptsForDoor\GetAttemptsForDoorUseCaseServiceProvider
;
use
Source\UseCases\DoorGroup\RemoveDoorFromGroup\RemoveDoorFromGroupUseCaseServiceProvider
;
use
Source\UseCases\GroupUser\RemoveUserFromGroup\RemoveUserFromGroupUseCaseServiceProvider
;
use
Source\UseCases\Attempts\GetAttemptCountForDoor\GetAttemptCountForDoorUseCaseServiceProvider
;
use
Source\UseCases\Entries\GetEntriesForDoorAndUser\GetEntriesForDoorAndUserUseCaseServiceProvider
;
use
Source\UseCases\Door\Authenticate\AuthenticateUseCaseServiceProvider
as
DoorAuthenticateUseCaseServiceProvider
;
use
Source\UseCases\Users\Authenticate\AuthenticateUseCaseServiceProvider
as
UserAuthenticateUseCaseServiceProvider
;
...
...
@@ -129,6 +132,12 @@ class AppServiceProvider extends ServiceProvider
GetAttemptsUseCaseServiceProvider
::
class
,
GetAttemptsForDoorUseCaseServiceProvider
::
class
,
GetAttemptCountForDoorUseCaseServiceProvider
::
class
,
// Entries
GetEntriesForDoorUseCaseServiceProvider
::
class
,
GetEntriesForUserUseCaseServiceProvider
::
class
,
GetEntriesForDoorAndUserUseCaseServiceProvider
::
class
,
];
/**
...
...
src/web/backend/src/UseCases/Entries/APIPresenter.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries
;
use
Source\Entities\Entry
;
use
Source\UseCases\BasePresenter
;
class
APIPresenter
extends
BasePresenter
implements
Presenter
{
protected
array
$viewModel
=
[];
/** @inheritDoc */
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
viewModel
[
'entries'
]
=
array_map
(
function
(
Entry
$entry
)
{
return
$this
->
formatEntry
(
$entry
);
},
$responseModel
->
getEntries
());
}
/** @inheritDoc */
public
function
getViewModel
():
array
{
return
$this
->
viewModel
;
}
}
src/web/backend/src/UseCases/Entries/GetEntriesForDoor/GetEntriesForDoor.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForDoor
;
use
Carbon\Carbon
;
use
Source\UseCases\Entries\Presenter
;
use
Source\UseCases\Entries\ResponseModel
;
use
Source\Gateways\Entries\EntriesRepository
;
class
GetEntriesForDoor
implements
GetEntriesForDoorUseCase
{
/**
* @var \Source\Gateways\Entries\EntriesRepository
*/
protected
EntriesRepository
$entries
;
public
function
__construct
(
EntriesRepository
$entries
)
{
$this
->
entries
=
$entries
;
}
/**
* @inheritDoc
*/
public
function
getEntriesForDoorBetween
(
string
$door
,
string
$begin
,
string
$end
,
Presenter
$presenter
):
void
{
$entries
=
$this
->
entries
->
getForDoorBetween
(
$door
,
new
Carbon
(
$begin
),
new
Carbon
(
$end
));
$response
=
new
ResponseModel
(
$entries
);
$presenter
->
present
(
$response
);
}
}
src/web/backend/src/UseCases/Entries/GetEntriesForDoor/GetEntriesForDoorUseCase.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForDoor
;
use
Source\UseCases\Entries\Presenter
;
interface
GetEntriesForDoorUseCase
{
/**
* Begin and end must be parsable by datetime
*
* @param string $door
* @param string $begin
* @param string $end
* @param \Source\UseCases\Entries\Presenter $presenter
* @throws \Exception
*/
public
function
getEntriesForDoorBetween
(
string
$door
,
string
$begin
,
string
$end
,
Presenter
$presenter
):
void
;
}
src/web/backend/src/UseCases/Entries/GetEntriesForDoor/GetEntriesForDoorUseCaseServiceProvider.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForDoor
;
use
Illuminate\Support\ServiceProvider
;
use
Source\Gateways\Entries\EntriesRepository
;
use
Illuminate\Contracts\Foundation\Application
;
use
Illuminate\Contracts\Support\DeferrableProvider
;
/**
* Service provider must be registered in AppServiceProvider
*/
class
GetEntriesForDoorUseCaseServiceProvider
extends
ServiceProvider
implements
DeferrableProvider
{
/**
* Register any application services.
*
* @return void
*/
public
function
register
()
{
$this
->
app
->
bind
(
GetEntriesForDoorUseCase
::
class
,
static
function
(
Application
$app
)
{
return
new
GetEntriesForDoor
(
$app
->
make
(
EntriesRepository
::
class
));
});
}
/**
* Bootstrap any application services.
*
* @return void
*/
public
function
boot
():
void
{
}
/**
* @return array
*/
public
function
provides
()
{
return
[
GetEntriesForDoorUseCase
::
class
];
}
}
src/web/backend/src/UseCases/Entries/GetEntriesForDoorAndUser/GetEntriesForDoorAndUser.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForDoorAndUser
;
use
Carbon\Carbon
;
use
Source\UseCases\Entries\Presenter
;
use
Source\UseCases\Entries\ResponseModel
;
use
Source\Gateways\Entries\EntriesRepository
;
class
GetEntriesForDoorAndUser
implements
GetEntriesForDoorAndUserUseCase
{
/**
* @var \Source\Gateways\Entries\EntriesRepository
*/
protected
EntriesRepository
$entries
;
public
function
__construct
(
EntriesRepository
$entries
)
{
$this
->
entries
=
$entries
;
}
/**
* @inheritDoc
*/
public
function
getEntriesForDoorAndUserBetween
(
string
$doorId
,
string
$userId
,
string
$begin
,
string
$end
,
Presenter
$presenter
):
void
{
$entries
=
$this
->
entries
->
getForUserAndDoorBetween
(
$userId
,
$doorId
,
new
Carbon
(
$begin
),
new
Carbon
(
$end
)
);
$response
=
new
ResponseModel
(
$entries
);
$presenter
->
present
(
$response
);
}
}
src/web/backend/src/UseCases/Entries/GetEntriesForDoorAndUser/GetEntriesForDoorAndUserUseCase.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForDoorAndUser
;
use
Source\UseCases\Entries\Presenter
;
interface
GetEntriesForDoorAndUserUseCase
{
/**
* Begin and end must be parsable by datetime
*
* @param string $doorId
* @param string $userId
* @param string $begin
* @param string $end
* @param \Source\UseCases\Entries\Presenter $presenter
* @throws \Exception
*/
public
function
getEntriesForDoorAndUserBetween
(
string
$doorId
,
string
$userId
,
string
$begin
,
string
$end
,
Presenter
$presenter
):
void
;
}
src/web/backend/src/UseCases/Entries/GetEntriesForDoorAndUser/GetEntriesForDoorAndUserUseCaseServiceProvider.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForDoorAndUser
;
use
Illuminate\Support\ServiceProvider
;
use
Source\Gateways\Entries\EntriesRepository
;
use
Illuminate\Contracts\Foundation\Application
;
use
Illuminate\Contracts\Support\DeferrableProvider
;
/**
* Service provider must be registered in AppServiceProvider
*/
class
GetEntriesForDoorAndUserUseCaseServiceProvider
extends
ServiceProvider
implements
DeferrableProvider
{
/**
* Register any application services.
*
* @return void
*/
public
function
register
()
{
$this
->
app
->
bind
(
GetEntriesForDoorAndUserUseCase
::
class
,
static
function
(
Application
$app
)
{
return
new
GetEntriesForDoorAndUser
(
$app
->
make
(
EntriesRepository
::
class
));
});
}
/**
* Bootstrap any application services.
*
* @return void
*/
public
function
boot
():
void
{
}
/**
* @return array
*/
public
function
provides
()
{
return
[
GetEntriesForDoorAndUserUseCase
::
class
];
}
}
src/web/backend/src/UseCases/Entries/GetEntriesForUser/GetEntriesForUser.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForUser
;
use
Carbon\Carbon
;
use
Source\UseCases\Entries\Presenter
;
use
Source\UseCases\Entries\ResponseModel
;
use
Source\Gateways\Entries\EntriesRepository
;
class
GetEntriesForUser
implements
GetEntriesForUserUseCase
{
/**
* @var \Source\Gateways\Entries\EntriesRepository
*/
protected
EntriesRepository
$entries
;
public
function
__construct
(
EntriesRepository
$entries
)
{
$this
->
entries
=
$entries
;
}
/**
* @inheritDoc
*/
public
function
getEntriesForUserBetween
(
string
$userId
,
string
$begin
,
string
$end
,
Presenter
$presenter
):
void
{
$entries
=
$this
->
entries
->
getForUserBetween
(
$userId
,
new
Carbon
(
$begin
),
new
Carbon
(
$end
));
$response
=
new
ResponseModel
(
$entries
);
$presenter
->
present
(
$response
);
}
}
src/web/backend/src/UseCases/Entries/GetEntriesForUser/GetEntriesForUserUseCase.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForUser
;
use
Source\UseCases\Entries\Presenter
;
interface
GetEntriesForUserUseCase
{
/**
* Begin and end must be parsable by datetime
*
* @param string $userId
* @param string $begin
* @param string $end
* @param \Source\UseCases\Entries\Presenter $presenter
* @throws \Exception
*/
public
function
getEntriesForUserBetween
(
string
$userId
,
string
$begin
,
string
$end
,
Presenter
$presenter
):
void
;
}
src/web/backend/src/UseCases/Entries/GetEntriesForUser/GetEntriesForUserUseCaseServiceProvider.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries\GetEntriesForUser
;
use
Illuminate\Support\ServiceProvider
;
use
Source\Gateways\Entries\EntriesRepository
;
use
Illuminate\Contracts\Foundation\Application
;
use
Illuminate\Contracts\Support\DeferrableProvider
;
/**
* Service provider must be registered in AppServiceProvider
*/
class
GetEntriesForUserUseCaseServiceProvider
extends
ServiceProvider
implements
DeferrableProvider
{
/**
* Register any application services.
*
* @return void
*/
public
function
register
()
{
$this
->
app
->
bind
(
GetEntriesForUserUseCase
::
class
,
static
function
(
Application
$app
)
{
return
new
GetEntriesForUser
(
$app
->
make
(
EntriesRepository
::
class
));
});
}
/**
* Bootstrap any application services.
*
* @return void
*/
public
function
boot
():
void
{
}
/**
* @return array
*/
public
function
provides
()
{
return
[
GetEntriesForUserUseCase
::
class
];
}
}
src/web/backend/src/UseCases/Entries/Presenter.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries
;
interface
Presenter
{
/**
* @param ResponseModel $responseModel
* @return void
*/
public
function
present
(
ResponseModel
$responseModel
):
void
;
/**
* @return array
*/
public
function
getViewModel
():
array
;
}
src/web/backend/src/UseCases/Entries/ResponseModel.php
0 → 100644
View file @
d7db4aba
<?php
namespace
Source\UseCases\Entries
;
class
ResponseModel
{
/**
* @var \Source\Entities\Entry[]
*/
protected
array
$entries
;
/**
* @param \Source\Entities\Entry[] $entries
*/
public
function
__construct
(
array
$entries
)
{
$this
->
entries
=
$entries
;
}
/**
* @return \Source\Entities\Entry[]
*/
public
function
getEntries
():
array
{
return
$this
->
entries
;
}
}
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