WIP: feature_paste #1
|
@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
|
||||
class PasteController extends AbstractController
|
||||
{
|
||||
|
||||
#[Route('/')]
|
||||
#[Route('/', name: 'homepage')]
|
||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
You don't really need Make your repository implement You don't really need `EntityManager` here.
Make your repository implement `save` like I showed you and use it instead.
|
||||
public function new(Request $request, PasteRepository $pasteRepository): Response
|
||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
I'd suggest we refactor this to to DTO usage and make our I'd suggest we refactor this to to DTO usage and make our `Paste` entity immutable.
|
||||
{
|
||||
$pasteData = new PasteFormData();
|
||||
|
@ -28,7 +28,7 @@ class PasteController extends AbstractController
|
|||
$paste = Paste::fromFormDataAndIp($pasteData, $request->getClientIp());
|
||||
$pasteRepository->save($paste, true);
|
||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
Do we need double quotes here? By the way, we can also do that in the constructor. Do we need double quotes here?
By the way, we can also do that in the constructor.
skobkin marked this conversation as resolved
Outdated
skobkin
commented
This still could be done in the entity itself. This still could be done in the entity itself.
|
||||
|
||||
return $this->redirectToRoute($request->attributes->get('_route'));
|
||||
return $this->redirectToRoute('showpaste', ['id' => $paste->id, 'secret' => $paste->secret]);
|
||||
}
|
||||
|
||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
I still suggest to make I still suggest to make `Paste::fromFormData()`.
|
||||
return $this->render('paste.html.twig', [
|
||||
|
@ -36,7 +36,7 @@ class PasteController extends AbstractController
|
|||
]);
|
||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
I see you needed some space 🤔 I see you needed some space 🤔
|
||||
}
|
||||
|
||||
#[Route('/{id}/{secret}')]
|
||||
#[Route('/{id}/{secret}', name: 'showpaste')]
|
||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
I mean you don't need to pass creation date here at all. I mean you don't need to pass creation date here at all.
|
||||
public function showPaste(PasteRepository $pasteRepository, string $id, ?string $secret = NULL): Response
|
||||
skobkin
commented
`show_paste` at least.
|
||||
{
|
||||
$paste = $pasteRepository->findOneBy(['id' => $id, 'secret' => $secret]);
|
||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
- it's a good idea to add `,` to the last argument too if you use multi-line formatting
- if you're doing this in the controller, you can just do something like `$pasteData->private ? \hash('sha1', \random_bytes(25)) : null`. But I suggest to do that in the static method (named constructor) as I also suggested nearby.
|
||||
|
|
Loading…
Reference in a new issue
I'd suggest explicitly defining which request methods we're processing here.
P.S. We'll move this to YAML in the end.