Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

¡A practicar! Controller enriquecido #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.env.local
/.env.*.local
/.idea

/apps/*/*/var/

Expand Down
4 changes: 4 additions & 0 deletions apps/mooc/backend/config/routes/fino.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fino_get:
path: /fino/{name}
controller: CodelyTv\Apps\Mooc\Backend\Controller\Fino\FinoGetController
methods: [GET]
31 changes: 31 additions & 0 deletions apps/mooc/backend/src/Controller/Fino/FinoGetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Apps\Mooc\Backend\Controller\Fino;

use CodelyTv\Shared\Domain\CurrentDateGenerator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class FinoGetController
{
private $date;

public function __construct(CurrentDateGenerator $date)
{
$this->date = $date->generate();
}

public function __invoke(Request $request): Response
{
$name = $request->get('name');
return new JsonResponse(
[
'desc' => 'Todo va fino ' . $name,
'date' => $this->date,
]
);
}
}
10 changes: 10 additions & 0 deletions src/Shared/Domain/CurrentDateGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types = 1);

namespace CodelyTv\Shared\Domain;

interface CurrentDateGenerator
{
public function generate(): string;
}
15 changes: 15 additions & 0 deletions src/Shared/Infrastructure/PhpCurrentDateGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types = 1);

namespace CodelyTv\Shared\Infrastructure;

use CodelyTv\Shared\Domain\CurrentDateGenerator;

final class PhpCurrentDateGenerator implements CurrentDateGenerator
{
public function generate(): string
{
return date('Y-m-d H:i:s', strtotime('now'));
}
}
13 changes: 13 additions & 0 deletions tests/apps/mooc/backend/features/fino/fino_get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature: Fino endpoint
In order to see todo va fino endpoind called by with name as param
I want to check the Fino endpoint

Scenario: Check the api status
Given I send a GET request to "/fino/Carlitos"
Then the response content should be:
"""
{
"desc": "Todo va fino Carlitos",
"date": "2020-01-01 00:00:00"
}
"""
15 changes: 15 additions & 0 deletions tests/src/Shared/Infrastructure/ConstantCurrentDateGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types = 1);

namespace CodelyTv\Tests\Shared\Infrastructure;

use CodelyTv\Shared\Domain\CurrentDateGenerator;

final class ConstantCurrentDateGenerator implements CurrentDateGenerator
{
public function generate(): string
{
return "2020-01-01 00:00:00";
}
}