Skip to content
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ RABBITMQ_EXCHANGE=domain_events
RABBITMQ_MAX_RETRIES=5
# RabbitMQ - Application Specific
RABBITMQ_MOOC_VHOST=/
# Discord - set the real webhook URL in .env.test.local (APP_ENV=test does not load .env.local)
DISCORD_WEBHOOK_URL=
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app
RUN apk --update upgrade \
&& apk add --no-cache autoconf automake make gcc g++ git bash icu-dev libzip-dev rabbitmq-c rabbitmq-c-dev linux-headers

RUN pecl install apcu-5.1.23 && pecl install amqp-2.1.1 && pecl install xdebug-3.3.0
RUN pecl install apcu-5.1.23 && pecl install amqp-2.1.1 && pecl install xdebug-3.4.2

RUN docker-php-ext-install -j$(nproc) \
bcmath \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ ping-rabbitmq:
@docker exec codely-php_ddd_skeleton-rabbitmq rabbitmqctl ping --silent

clean-cache:
@rm -rf apps/*/*/var
@rm -rf apps/*/*/var/*
@docker exec codely-php_ddd_skeleton-mooc_backend-php ./apps/mooc/backend/bin/console cache:warmup
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@

### 🔥 Application execution

1. Install all the dependencies and bring up the project with Docker executing: `make build`
2. Then you'll have 3 apps available (2 APIs and 1 Frontend):
1. Install all the dependencies (runs Composer inside Docker, no local PHP needed): `make composer-install`
2. Bring up the project with Docker: `make start`
3. Then you'll have 3 apps available (2 APIs and 1 Frontend):
1. [Mooc Backend](apps/mooc/backend): http://localhost:8030/health-check
2. [Backoffice Backend](apps/backoffice/backend): http://localhost:8040/health-check
3. [Backoffice Frontend](apps/backoffice/frontend): http://localhost:8041/health-check

### ✅ Tests execution

1. Install the dependencies if you haven't done it previously: `make deps`
1. Install the dependencies and start the containers if you haven't done it previously: `make composer-install && make start`
2. Execute PHPUnit and Behat tests: `make test`
3. Stop the containers when you're done: `make stop`

## 👩‍💻 Project explanation

Expand Down
4 changes: 4 additions & 0 deletions apps/mooc/backend/config/routes/videos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
videos_put:
path: /videos/{id}
controller: CodelyTv\Apps\Mooc\Backend\Controller\Videos\VideosPutController
methods: [PUT]
5 changes: 5 additions & 0 deletions apps/mooc/backend/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,10 @@ services:
CodelyTv\Shared\Infrastructure\Bus\Event\WithMonitoring\WithPrometheusMonitoringEventBus:
arguments: ['@CodelyTv\Shared\Infrastructure\Monitoring\PrometheusMonitor', 'mooc_backend', '@CodelyTv\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqEventBus']

# Discord
CodelyTv\Mooc\Videos\Infrastructure\Notification\DiscordVideoPublishedNotifier:
arguments:
$webhookUrl: '%env(DISCORD_WEBHOOK_URL)%'

# -- IMPLEMENTATIONS SELECTOR --
CodelyTv\Shared\Domain\Bus\Event\EventBus: '@CodelyTv\Shared\Infrastructure\Bus\Event\WithMonitoring\WithPrometheusMonitoringEventBus'
33 changes: 33 additions & 0 deletions apps/mooc/backend/src/Controller/Videos/VideosPutController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

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

use CodelyTv\Mooc\Videos\Application\Create\CreateVideoCommand;
use CodelyTv\Shared\Infrastructure\Symfony\ApiController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class VideosPutController extends ApiController
{
public function __invoke(string $id, Request $request): Response
{
$this->dispatch(
new CreateVideoCommand(
$id,
(string) $request->request->get('type'),
(string) $request->request->get('title'),
(string) $request->request->get('url'),
(string) $request->request->get('courseId')
)
);

return new Response('', Response::HTTP_CREATED);
}

protected function exceptions(): array
{
return [];
}
}
17 changes: 17 additions & 0 deletions apps/mooc/backend/tests/features/videos/video_put.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Create a new video
In order to have videos on the platform
As a user with admin permissions
I want to create a new video

Scenario: A valid non existing video
Given I send a PUT request to "/videos/3c5e9a1f-2b7d-4e8a-9f61-0d4b7c2e8a15" with body:
"""
{
"type": "screencast",
"title": "The best video",
"url": "https://codely.com/videos/the-best-video",
"course_id": "1aab45ba-3c7a-4344-8936-78466eca77fa"
}
"""
Then the response status code should be 201
And the response should be empty
6 changes: 6 additions & 0 deletions apps/mooc/backend/tests/mooc_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ mooc_backend:
contexts:
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApplicationFeatureContext
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiContext

videos:
paths: [ apps/mooc/backend/tests/features/videos ]
contexts:
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApplicationFeatureContext
- CodelyTv\Tests\Shared\Infrastructure\Behat\ApiContext
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"elasticsearch/elasticsearch": "^7",
"monolog/monolog": "^3",

"promphp/prometheus_client_php": "^2.7.2"
"promphp/prometheus_client_php": "^2.7.2",
"symfony/http-client": "^7.1"
},
"require-dev": {
"ext-xdebug": "*",
Expand Down
185 changes: 184 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ services:
- shared_rabbitmq
- shared_prometheus
- backoffice_elasticsearch
command: symfony serve --dir=apps/backoffice/backend/public --port=8040
command: symfony serve --dir=apps/backoffice/backend/public --port=8040 --allow-all-ip

backoffice_frontend_php:
container_name: codely-php_ddd_skeleton-backoffice_frontend-php
Expand All @@ -86,7 +86,7 @@ services:
- shared_prometheus
- backoffice_elasticsearch
- mooc_mysql
command: symfony serve --dir=apps/backoffice/frontend/public --port=8041
command: symfony serve --dir=apps/backoffice/frontend/public --port=8041 --allow-all-ip

mooc_backend_php:
container_name: codely-php_ddd_skeleton-mooc_backend-php
Expand All @@ -104,4 +104,4 @@ services:
- shared_rabbitmq
- shared_prometheus
- mooc_mysql
command: symfony serve --dir=apps/mooc/backend/public --port=8030
command: symfony serve --dir=apps/mooc/backend/public --port=8030 --allow-all-ip
11 changes: 11 additions & 0 deletions etc/databases/mooc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ CREATE TABLE courses_counter (
INSERT INTO courses_counter (id, total, existing_courses)
VALUES ("cdf26d7d-3deb-4e8c-9f73-4ac085a8d6f3", 0, "[]");

CREATE TABLE videos (
id CHAR(36) NOT NULL,
type VARCHAR(255) NOT NULL,
title VARCHAR(255) NOT NULL,
url VARCHAR(255) NOT NULL,
course_id CHAR(36) NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci;

CREATE TABLE steps (
id CHAR(36) NOT NULL,
title VARCHAR(255) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<embeddable name="CodelyTv\Mooc\Videos\Domain\VideoType">
<field name="value" type="string" column="type" />
<embeddable name="CodelyTv\Mooc\Shared\Domain\Videos\VideoUrl">
<field name="value" type="string" column="url" />
</embeddable>

</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ services:

# Courses
CodelyTv\Mooc\Courses\Domain\CourseRepository: '@CodelyTv\Mooc\Courses\Infrastructure\Persistence\DoctrineCourseRepository'

# Videos
CodelyTv\Mooc\Videos\Domain\VideoPublishedNotifier: '@CodelyTv\Mooc\Videos\Infrastructure\Notification\DiscordVideoPublishedNotifier'
Loading