-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathAllCoursesController.php
More file actions
37 lines (32 loc) · 1.18 KB
/
AllCoursesController.php
File metadata and controls
37 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace CodelyTv\Apps\Backoffice\Backend\Controller\Courses;
use CodelyTv\Backoffice\Courses\Application\BackofficeCourseResponse;
use CodelyTv\Backoffice\Courses\Application\BackofficeCoursesResponse;
use CodelyTv\Backoffice\Courses\Application\SearchAll\SearchAllBackofficeCoursesQuery;
use CodelyTv\Shared\Domain\Bus\Query\QueryBus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use function Lambdish\Phunctional\map;
class AllCoursesController
{
public function __construct(private QueryBus $queryBus)
{
}
public function __invoke(Request $request): JsonResponse
{
/** @var BackofficeCoursesResponse $response */
$response = $this->queryBus->ask(new SearchAllBackofficeCoursesQuery());
return new JsonResponse(
map(
fn(BackofficeCourseResponse $course) => [
'id' => $course->id(),
'name' => $course->name(),
'duration' => $course->duration(),
],
$response->courses()
),
200,
['Access-Control-Allow-Origin' => '*']
);
}
}