Commit 791e7e22 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add ability to remove door from group

parent 5a138539
Pipeline #5563 failed with stages
in 2 minutes and 5 seconds
......@@ -9,6 +9,8 @@ use Source\UseCases\Doors\CreateDoor\CreateDoorUseCase;
use Source\UseCases\Doors\DeleteDoor\DeleteDoorUseCase;
use Source\UseCases\Doors\UpdateDoor\UpdateDoorUseCase;
use Source\UseCases\Doors\GetAllDoors\GetAllDoorsUseCase;
use Source\UseCases\DoorGroup\RemoveDoorFromGroup\APIPresenter as RemoveDoorFromGroupAPIPresenter;
use Source\UseCases\DoorGroup\RemoveDoorFromGroup\RemoveDoorFromGroupUseCase;
use Source\UseCases\DoorGroup\AddDoorToGroup\APIPresenter as AddDoorToGroupAPIPresenter;
use Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupUseCase;
use Source\UseCases\DoorGroup\GetDoorGroups\APIPresenter as GetDoorGroupsAPIPresenter;
......@@ -179,4 +181,22 @@ class DoorsController extends ApiController
return $this->respondWithData($presenter->getViewModel());
}
/**
* @param \Source\UseCases\DoorGroup\RemoveDoorFromGroup\RemoveDoorFromGroupUseCase $removeDoorFromGroup
* @param string $doorId
* @param string $groupId
* @return \Illuminate\Http\JsonResponse
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function removeDoorFromGroup(RemoveDoorFromGroupUseCase $removeDoorFromGroup, string $doorId, string $groupId): JsonResponse {
$this->authorizer->protect(Permissions::MANAGE_DOORS);
$presenter = new RemoveDoorFromGroupAPIPresenter();
$removeDoorFromGroup->removeDoorFromGroup($doorId, $groupId, $presenter);
return $this->respondWithData($presenter->getViewModel());
}
}
......@@ -35,6 +35,7 @@ use Source\UseCases\GroupUser\AddUserToGroup\AddUserToGroupUseCaseServiceProvide
use Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupUseCaseServiceProvider;
use Source\UseCases\Doors\GenerateDoorToken\GenerateDoorTokenUseCaseServiceProvider;
use Source\UseCases\GroupUser\RemoveUserFromGroup\RemoveUserFromGroupUseCaseServiceProvider;
use Source\UseCases\DoorGroup\RemoveDoorFromGroup\RemoveDoorFromGroupUseCaseServiceProvider;
use Source\UseCases\Doors\Authenticate\AuthenticateUseCaseServiceProvider as DoorAuthenticateUseCaseServiceProvider;
use Source\UseCases\Users\Authenticate\AuthenticateUseCaseServiceProvider as UserAuthenticateUseCaseServiceProvider;
......@@ -82,6 +83,7 @@ class AppServiceProvider extends ServiceProvider
GetDoorGroupsUseCaseServiceProvider::class,
GetGroupDoorsUseCaseServiceProvider::class,
AddDoorToGroupUseCaseServiceProvider::class,
RemoveDoorFromGroupUseCaseServiceProvider::class,
// Doors
GetDoorUseCaseServiceProvider::class,
......
......@@ -61,7 +61,7 @@ Route::group(['middleware' => 'auth:api'], static function () {
Route::get('{doorId}/groups', [DoorsController::class, 'getGroupsForDoor']);
Route::post('{doorId}/group/{groupId}', [DoorsController::class, 'addDoorToGroup']);
// Route::delete('{doorId}/group/{groupId}', [DoorsController::class, 'removeDoorFromGroup']);
Route::delete('{doorId}/group/{groupId}', [DoorsController::class, 'removeDoorFromGroup']);
});
Route::group([
......
<?php
namespace Source\UseCases\DoorGroup\RemoveDoorFromGroup;
use Source\UseCases\BasePresenter;
class APIPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['message'] = $responseModel->getMessage();
}
/** @inheritDoc */
public function getViewModel(): array
{
return $this->viewModel;
}
}
<?php
namespace Source\UseCases\DoorGroup\RemoveDoorFromGroup;
interface Presenter
{
/**
* @param ResponseModel $responseModel
* @return void
*/
public function present(ResponseModel $responseModel): void;
/**
* @return array
*/
public function getViewModel(): array;
}
<?php
namespace Source\UseCases\DoorGroup\RemoveDoorFromGroup;
use Source\Gateways\DoorGroup\DoorGroupRepository;
class RemoveDoorFromGroup implements RemoveDoorFromGroupUseCase
{
/**
* @var \Source\Gateways\DoorGroup\DoorGroupRepository
*/
protected DoorGroupRepository $repository;
public function __construct(DoorGroupRepository $repository)
{
$this->repository = $repository;
}
/**
* @inheritDoc
*/
public function removeDoorFromGroup(string $doorId, string $groupId, Presenter $presenter): void
{
$this->repository->removeDoorFromGroup($doorId, $groupId);
$response = new ResponseModel('Success');
$presenter->present($response);
}
}
<?php
namespace Source\UseCases\DoorGroup\RemoveDoorFromGroup;
interface RemoveDoorFromGroupUseCase
{
/**
* @param string $doorId
* @param string $groupId
* @param \Source\UseCases\DoorGroup\RemoveDoorFromGroup\Presenter $presenter
* @throws \Source\Exceptions\EntityNotFoundException
*/
public function removeDoorFromGroup(string $doorId, string $groupId, Presenter $presenter): void;
}
<?php
namespace Source\UseCases\DoorGroup\RemoveDoorFromGroup;
use Illuminate\Contracts\Foundation\Application;
use Source\Gateways\DoorGroup\DoorGroupRepository;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
/**
* Service provider must be registered in AppServiceProvider
*/
class RemoveDoorFromGroupUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(RemoveDoorFromGroupUseCase::class, static function (Application $app) {
return new RemoveDoorFromGroup($app->make(DoorGroupRepository::class));
});
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{
}
/**
* @return array
*/
public function provides()
{
return [RemoveDoorFromGroupUseCase::class];
}
}
<?php
namespace Source\UseCases\DoorGroup\RemoveDoorFromGroup;
class ResponseModel
{
/**
* @var string
*/
protected string $message;
public function __construct(string $message)
{
$this->message = $message;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
}
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