This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backoffice-course] List all existing courses
- Loading branch information
1 parent
f8ced75
commit 8ecc12f
Showing
13 changed files
with
243 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
api_courses_get: | ||
path: /api/courses | ||
controller: CodelyTv\Apps\Backoffice\Frontend\Controller\Courses\ApiCoursesGetController | ||
methods: [GET] |
35 changes: 35 additions & 0 deletions
35
apps/backoffice/frontend/src/Controller/Courses/ApiCoursesGetController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace CodelyTv\Apps\Backoffice\Frontend\Controller\Courses; | ||
|
||
use CodelyTv\Backoffice\Courses\Application\BackofficeCourseResponse; | ||
use CodelyTv\Backoffice\Courses\Application\BackofficeCoursesResponse; | ||
use CodelyTv\Backoffice\Courses\Application\SearchAll\SearchAllBackofficeCoursesQuery; | ||
use CodelyTv\Shared\Infrastructure\Symfony\Controller; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use function Lambdish\Phunctional\map; | ||
|
||
final class ApiCoursesGetController extends Controller | ||
{ | ||
public function __invoke(Request $request): JsonResponse | ||
{ | ||
/** @var BackofficeCoursesResponse $response */ | ||
$response = $this->ask(new SearchAllBackofficeCoursesQuery()); | ||
|
||
return new JsonResponse(map($this->toArray(), $response->courses())); | ||
} | ||
|
||
private function toArray(): callable | ||
{ | ||
return static function (BackofficeCourseResponse $course) { | ||
return [ | ||
'id' => $course->id(), | ||
'name' => $course->name(), | ||
'duration' => $course->duration(), | ||
]; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
apps/backoffice/frontend/templates/pages/courses/partials/list_courses.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<h3 class="font-sans text-gray-800 text-center text-3xl mb-10">Cursos existentes</h3> | ||
|
||
<table class="text-left w-full border-collapse"> | ||
<thead> | ||
<tr> | ||
<th class="py-4 px-6 bg-grey-lightest font-bold uppercase text-sm text-grey-dark border-b border-grey-light">Id</th> | ||
<th class="py-4 px-6 bg-grey-lightest font-bold uppercase text-sm text-grey-dark border-b border-grey-light">Nombre</th> | ||
<th class="py-4 px-6 bg-grey-lightest font-bold uppercase text-sm text-grey-dark border-b border-grey-light">Duración</th> | ||
</tr> | ||
</thead> | ||
<tbody id="courses-list"> | ||
|
||
</tbody> | ||
</table> | ||
|
||
<script> | ||
const tableBody = document.getElementById("courses-list"); | ||
fetch("{{ path('api_courses_get') }}") | ||
.then(function (response) { | ||
return response.json(); | ||
}) | ||
.then(function (courses) { | ||
tableBody.innerHTML = ""; | ||
courses.forEach(function (course) { | ||
let courseRow = document.createElement("tr"); | ||
courseRow.appendChild(tableCellFor(course.id)); | ||
courseRow.appendChild(tableCellFor(course.name)); | ||
courseRow.appendChild(tableCellFor(course.duration)); | ||
tableBody.appendChild(courseRow); | ||
}) | ||
}); | ||
function tableCellFor(text) { | ||
const cell = document.createElement("td"); | ||
cell.appendChild(document.createTextNode(text)); | ||
return cell; | ||
} | ||
</script> |
34 changes: 34 additions & 0 deletions
34
src/Backoffice/Courses/Application/BackofficeCourseResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace CodelyTv\Backoffice\Courses\Application; | ||
|
||
final class BackofficeCourseResponse | ||
{ | ||
private $id; | ||
private $name; | ||
private $duration; | ||
|
||
public function __construct(string $id, string $name, string $duration) | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
$this->duration = $duration; | ||
} | ||
|
||
public function id(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function name(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function duration(): string | ||
{ | ||
return $this->duration; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Backoffice/Courses/Application/BackofficeCoursesResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace CodelyTv\Backoffice\Courses\Application; | ||
|
||
use CodelyTv\Shared\Domain\Bus\Query\Response; | ||
|
||
final class BackofficeCoursesResponse implements Response | ||
{ | ||
private $courses; | ||
|
||
public function __construct(BackofficeCourseResponse ...$courses) | ||
{ | ||
$this->courses = $courses; | ||
} | ||
|
||
public function courses(): array | ||
{ | ||
return $this->courses; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Backoffice/Courses/Application/Create/BackofficeCourseCreator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace CodelyTv\Backoffice\Courses\Application\Create; | ||
|
||
use CodelyTv\Backoffice\Courses\Domain\BackofficeCourse; | ||
use CodelyTv\Backoffice\Courses\Domain\BackofficeCourseRepository; | ||
|
||
final class BackofficeCourseCreator | ||
{ | ||
private $repository; | ||
|
||
public function __construct(BackofficeCourseRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
public function create(string $id, string $name, string $duration): void | ||
{ | ||
$this->repository->save(new BackofficeCourse($id, $name, $duration)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Backoffice/Courses/Application/SearchAll/AllBackofficeCoursesSearcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace CodelyTv\Backoffice\Courses\Application\SearchAll; | ||
|
||
use CodelyTv\Backoffice\Courses\Application\BackofficeCourseResponse; | ||
use CodelyTv\Backoffice\Courses\Application\BackofficeCoursesResponse; | ||
use CodelyTv\Backoffice\Courses\Domain\BackofficeCourse; | ||
use CodelyTv\Backoffice\Courses\Domain\BackofficeCourseRepository; | ||
use function Lambdish\Phunctional\map; | ||
|
||
final class AllBackofficeCoursesSearcher | ||
{ | ||
private $repository; | ||
|
||
public function __construct(BackofficeCourseRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
public function searchAll(): BackofficeCoursesResponse | ||
{ | ||
return new BackofficeCoursesResponse(...map($this->toResponse(), $this->repository->searchAll())); | ||
} | ||
|
||
private function toResponse(): callable | ||
{ | ||
return static function (BackofficeCourse $course) { | ||
return new BackofficeCourseResponse($course->id(), $course->name(), $course->duration()); | ||
}; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Backoffice/Courses/Application/SearchAll/SearchAllBackofficeCoursesQuery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace CodelyTv\Backoffice\Courses\Application\SearchAll; | ||
|
||
use CodelyTv\Shared\Domain\Bus\Query\Query; | ||
|
||
final class SearchAllBackofficeCoursesQuery implements Query | ||
{ | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Backoffice/Courses/Application/SearchAll/SearchAllBackofficeCoursesQueryHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace CodelyTv\Backoffice\Courses\Application\SearchAll; | ||
|
||
use CodelyTv\Backoffice\Courses\Application\BackofficeCoursesResponse; | ||
use CodelyTv\Shared\Domain\Bus\Query\QueryHandler; | ||
|
||
final class SearchAllBackofficeCoursesQueryHandler implements QueryHandler | ||
{ | ||
private $searcher; | ||
|
||
public function __construct(AllBackofficeCoursesSearcher $searcher) | ||
{ | ||
$this->searcher = $searcher; | ||
} | ||
|
||
public function __invoke(SearchAllBackofficeCoursesQuery $query): BackofficeCoursesResponse | ||
{ | ||
return $this->searcher->searchAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters