Skip to content

Commit

Permalink
feat: do not edit/show archived data
Browse files Browse the repository at this point in the history
  • Loading branch information
n3wborn committed Sep 11, 2023
1 parent ae6cce8 commit 3c23e0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Service/Project/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public function __construct(
) {
}

public function get(?Project $project): ?Project
public function get(Project $project): ?Project
{
(null === $project)
$project->isArchived()
&& throw new NotFoundException(ApiMessages::translate(ApiMessages::PROJECT_NOT_FOUND));

return
Expand All @@ -31,4 +31,9 @@ public function getAll(): array
{
return $this->projectRepository->findAll();
}

public function getAllNotArchived(): array
{
return $this->projectRepository->findBy(['archivedAt' => null]);
}
}
2 changes: 1 addition & 1 deletion src/Service/Project/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function handleGetProject(?Project $project): JsonResponse

public function handleGetAllProjects(): JsonResponse
{
$projects = $this->finder->getAll();
$projects = $this->finder->getAllNotArchived();
$result = array_map(static fn (Project $project) => Mapper::fromEntityToJson($project), $projects);

return new ApiResponse($result);
Expand Down
8 changes: 6 additions & 2 deletions src/Service/Project/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Controller\ProjectController;
use App\Entity\Project;
use App\Exception\BadDataException;
use App\Exception\NotFoundException;
use App\Helper\ApiMessages;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -36,10 +37,13 @@ public static function generateEditSuccessMessage(Request $request): string
: ApiMessages::PROJECT_CREATE_SUCCESS_MESSAGE;
}

/** @throws NotFoundException */
public function validateRequestResource(Request $request): void
/** @throws NotFoundException|BadDataException */
public function validateRequestResource(Request $request, Project $project): void
{
(self::isEditRoute($request) && (null === $this->editSlugParamExists($request)))
&& throw new NotFoundException(ApiMessages::translate(ApiMessages::PROJECT_UNKNOWN));

$project->isArchived()
&& throw new BadDataException(Validator::PROJECT_ALREADY_ARCHIVED);
}
}

0 comments on commit 3c23e0e

Please sign in to comment.