Commit 3665e08a authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add routes and fix some issues where I wasn't formatting date properly

parent 02cefcb6
Pipeline #9542 canceled with stages
in 44 seconds
......@@ -13,7 +13,9 @@ use Source\UseCases\Users\UpdateUser\UpdateUserUseCase;
use Source\UseCases\Users\GetAllUsers\GetAllUsersUseCase;
use Source\UseCases\GroupUser\GetUserGroups\GetUserGroupsUseCase;
use Source\UseCases\TokenUser\GetUserTokens\GetUserTokensUseCase;
use Source\UseCases\DoorUser\UserDoorAccess\UserDoorAccessUseCase;
use Source\UseCases\GroupUser\AddUserToGroup\AddUserToGroupUseCase;
use Source\UseCases\DoorUser\UserDoorAccess\PrivilegedApiPresenter;
use Source\UseCases\Users\GetUser\APIPresenter as GetUserAPIPresenter;
use Source\UseCases\Users\GetAllUsers\APIPresenter as AllUsersAPIPresenter;
use Source\UseCases\Users\CreateUser\APIPresenter as CreateUserAPIPresenter;
......@@ -226,4 +228,22 @@ class UsersController extends ApiController
return $this->respondWithData($presenter->getViewModel());
}
/**
* @param \Source\UseCases\DoorUser\UserDoorAccess\UserDoorAccessUseCase $userDoorAccessUseCase
* @param string $userId
* @return \Illuminate\Http\JsonResponse
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function doors(UserDoorAccessUseCase $userDoorAccessUseCase, string $userId): JsonResponse
{
$this->authorizer->protect(Permissions::MANAGE_USERS);
$presenter = new PrivilegedApiPresenter();
$userDoorAccessUseCase->getUserDoorRelationships($userId, $presenter);
return $this->respondWithData($presenter->getViewModel());
}
}
......@@ -42,6 +42,7 @@ Route::group(['middleware' => 'auth:api'], static function () {
Route::post('{userId}/group/{groupId}', [UsersController::class, 'addUserToGroup']);
Route::delete('{userId}/group/{groupId}', [UsersController::class, 'removeUserFromGroup']);
Route::get('{userId}/tokens', [UsersController::class, 'tokens']);
Route::get('{userId}/doors', [UsersController::class, 'doors']);
});
Route::group([
......
......@@ -142,8 +142,8 @@ abstract class BasePresenter
'rset' => $schedule->getRset(),
'duration' => $schedule->getDuration(),
'description' => $schedule->getDescription(),
'start_date' => $schedule->getStart(),
'end_date' => $schedule->getEnd(),
'start_date' => $this->formatDateTime($schedule->getStart()),
'end_date' => $this->formatDateTime($schedule->getEnd()),
'created_at' => $this->formatDateTime($schedule->getCreatedAt()),
'updated_at' => $this->formatDateTime($schedule->getUpdatedAt()),
];
......@@ -162,7 +162,7 @@ abstract class BasePresenter
return [
'id' => $attempt->getId(),
'door_id' => $attempt->getDoorId(),
'created_at' => $attempt->getCreatedAt(),
'created_at' => $this->formatDateTime($attempt->getCreatedAt()),
];
}
......@@ -181,7 +181,7 @@ abstract class BasePresenter
'user_id' => $entry->getUserId(),
'door_id' => $entry->getDoorId(),
'success' => $entry->wasSuccessful(),
'created_at' => $entry->getCreatedAt(),
'created_at' => $this->formatDateTime($entry->getCreatedAt()),
];
}
......
......@@ -32,12 +32,14 @@ class MePresenter extends BasePresenter implements Presenter
'location' => $door->getLocation(),
];
}, $responseModel->getDoorsForGroup($group));
$this->viewModel['schedules'][$group->getId()] = array_map(static function (Schedule $schedule) {
$this->viewModel['schedules'][$group->getId()] = array_map(function (Schedule $schedule) {
return [
'id' => $schedule->getId(),
'description' => $schedule->getDescription(),
'rset' => $schedule->getRset(),
'duration' => $schedule->getDuration(),
'start_date' => $this->formatDateTime($schedule->getStart()),
'end_date' => $this->formatDateTime($schedule->getEnd()),
];
}, $responseModel->getSchedulesForGroup($group));
}
......
<?php
namespace Source\UseCases\DoorUser\UserDoorAccess;
use Source\Entities\Door;
use Source\Entities\Group;
use Source\Entities\Schedule;
use Source\UseCases\BasePresenter;
class PrivilegedApiPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
/**
* @inheritDoc
*/
public function present(ResponseModel $responseModel): void
{
$groups = $responseModel->getGroups();
$this->viewModel['groups'] = array_map(function (Group $group) {
return $this->formatGroup($group);
}, $groups);
$this->viewModel['doors'] = [];
$this->viewModel['schedules'] = [];
foreach ($groups as $group) {
$this->viewModel['doors'][$group->getId()] = array_map(function (Door $door) {
return $this->formatDoor($door);
}, $responseModel->getDoorsForGroup($group));
$this->viewModel['schedules'][$group->getId()] = array_map(function (Schedule $schedule) {
return $this->formatSchedule($schedule);
}, $responseModel->getSchedulesForGroup($group));
}
}
/**
* @inheritDoc
*/
public function getViewModel(): array
{
return $this->viewModel;
}
}
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