Skip to content

Commit

Permalink
refactor(Helpers): editSlugExists
Browse files Browse the repository at this point in the history
  • Loading branch information
n3wborn committed Jan 13, 2024
1 parent 9633989 commit aa9f25f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
18 changes: 9 additions & 9 deletions docker/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ COPY ./docker-entrypoint.sh /usr/local/bin/
# https://github.com/fred-lab/Docker_Symfony/blob/master/docker/nodejs/docker-entrypoint.sh
# Si jamais tu tombe là-dessus, merci Fred ! ;)
RUN apk update \
&& chmod 777 /usr/local/bin/docker-entrypoint.sh \
&& echo -e '\033[0;31m' Change user permissions '\033[0m' \
&& cd /home/docker \
&& apk --no-cache add shadow && usermod -u $HOST_USER node && groupmod -g $HOST_USERGROUP node \
&& echo -e '\033[0;31m' Check Permissions for Workdir'\033[0m' $PWD \
&& ls -la \
&& apk del shadow \
# Clean up apk cache folder and the virtuals folders
&& rm -rf /var/cache/apk/*
&& chmod 777 /usr/local/bin/docker-entrypoint.sh \
&& echo -e '\033[0;31m' Change user permissions '\033[0m' \
&& cd /home/docker \
&& apk --no-cache add shadow && usermod -u $HOST_USER node && groupmod -g $HOST_USERGROUP node \
&& echo -e '\033[0;31m' Check Permissions for Workdir'\033[0m' $PWD \
&& ls -la \
&& apk del shadow \
# Clean up apk cache folder and the virtuals folders
&& rm -rf /var/cache/apk/*

ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
1 change: 1 addition & 0 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function findAllNotArchived(): array
->orderBy('u.email', 'ASC')
->getQuery()
->getResult();
;
}

public function findNotArchivedByEmail(string $email): ?User
Expand Down
11 changes: 4 additions & 7 deletions src/Service/Category/CategoryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
use App\Exception\BadDataException;
use App\Exception\NotFoundException;
use App\Helper\ApiMessages;
use App\Repository\CategoryRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;

final class CategoryHelper
{
public function __construct(
private EntityManagerInterface $em,
private CategoryRepository $categoryRepository,
) {
}

Expand All @@ -26,9 +28,7 @@ public static function isEditRoute(Request $request): bool
/** @throws NotFoundException */
public function editSlugParamExists(Request $request): ?Category
{
return isset($request->get('_route_params')['slug'])
? $this->em->getRepository(Category::class)->findOneBy(['slug' => $request->get('_route_params')['slug']])
: null;
return $this->categoryRepository->findOneBySlug($request->get('slug', ''));
}

public static function generateEditSuccessMessage(Request $request): string
Expand All @@ -50,10 +50,7 @@ public function validateRequestResource(Request $request, category $category): v

public static function findNotArchivedFromProject(Project $project): array
{
return array_map(
static fn (Category $category) => !$category->isArchived() ? $category : null,
$project->getCategories()->toArray()
);
return array_filter($project->getCategories()->toArray(), fn (Category $category) => $category->isArchived());
}

public static function categoryExists(?Category $category): bool
Expand Down
6 changes: 3 additions & 3 deletions src/Service/Project/ProjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
use App\Exception\BadDataException;
use App\Exception\NotFoundException;
use App\Helper\ApiMessages;
use App\Repository\ProjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;

final class ProjectHelper
{
public function __construct(
private EntityManagerInterface $em,
private ProjectRepository $projectRepository
) {
}

Expand All @@ -26,9 +28,7 @@ public static function isEditRoute(Request $request): bool
/** @throws NotFoundException */
public function editSlugParamExists(Request $request): ?Project
{
return isset($request->get('_route_params')['slug'])
? $this->em->getRepository(Project::class)->findOneBy(['slug' => $request->get('_route_params')['slug']])
: null;
return $this->projectRepository->findOneBySlug($request->get('slug', ''));
}

public static function generateEditSuccessMessage(Request $request): string
Expand Down
4 changes: 2 additions & 2 deletions src/Service/User/UserFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function getAll(): array
return $this->userRepository->findAll();
}

public function getAllNotArchived(): array
public function getAllNotArchived()
{
return $this->userRepository->findAllNotArchived();
$this->userRepository->findAllNotArchived();
}

/** @throws NotFoundException */
Expand Down
6 changes: 3 additions & 3 deletions src/Service/User/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
use App\Exception\BadDataException;
use App\Exception\NotFoundException;
use App\Helper\ApiMessages;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;

final class UserHelper
{
public function __construct(
private EntityManagerInterface $em,
private UserRepository $userRepository,
) {
}

Expand All @@ -26,9 +28,7 @@ public static function isEditRoute(Request $request): bool
/** @throws NotFoundException */
public function editSlugParamExists(Request $request): ?User
{
return isset($request->get('_route_params')['slug'])
? $this->em->getRepository(User::class)->findOneBy(['slug' => $request->get('_route_params')['slug']])
: null;
return $this->userRepository->findOneBySlug($request->get('slug', ''));
}

public static function generateEditSuccessMessage(Request $request): string
Expand Down

0 comments on commit aa9f25f

Please sign in to comment.