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

Add use cases for entries read

parent 5763737f
......@@ -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,
];
/**
......
<?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;
}
}
<?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);
}
}
<?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;
}
<?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];
}
}
<?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);
}
}
<?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;
}
<?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];
}
}
<?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);
}
}
<?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;
}
<?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];
}
}
<?php
namespace Source\UseCases\Entries;
interface Presenter
{
/**
* @param ResponseModel $responseModel
* @return void
*/
public function present(ResponseModel $responseModel): void;
/**
* @return array
*/
public function getViewModel(): array;
}
<?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;
}
}
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