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
30 changes: 30 additions & 0 deletions symfonyapi/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=f9868115c6c0766739be8a800c1b2bd8
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###
Empty file added symfonyapi/.env.dev
Empty file.
3 changes: 3 additions & 0 deletions symfonyapi/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
15 changes: 15 additions & 0 deletions symfonyapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> phpunit/phpunit ###
/phpunit.xml
/.phpunit.cache/
###< phpunit/phpunit ###
12 changes: 12 additions & 0 deletions symfonyapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:8.2-cli

WORKDIR /app

COPY composer.json composer.lock ./
RUN apt-get update && apt-get install -y git zip unzip && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
composer install --no-dev --no-scripts --prefer-dist

COPY . .

CMD ["php", "-S", "0.0.0.0:8080", "-t", "public"]
66 changes: 66 additions & 0 deletions symfonyapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Siroko Cart API

API de ejemplo para la gestión de un carrito de compra y checkout utilizando Symfony 6.

## Descripción

Este proyecto implementa una API sencilla que permite añadir, actualizar y eliminar productos del carrito, obtener el carrito y procesar el checkout generando una orden persistente. El dominio está desacoplado del framework siguiendo principios de DDD y se proporciona un almacén de datos basado en ficheros.

## Modelo de dominio

- **Product**: identificador, nombre y precio.
- **CartItem**: producto y cantidad.
- **Cart**: colección de items y cálculo del total.
- **Order**: carrito confirmado.

## Especificación OpenAPI

El archivo [`openapi.yaml`](openapi.yaml) describe los endpoints principales:

- `GET /api/cart`
- `GET /api/products`
- `POST /api/products`
- `POST /api/cart/items`
- `PUT /api/cart/items/{id}`
- `DELETE /api/cart/items/{id}`
- `POST /api/cart/checkout`

## Tecnología

- PHP 8
- Symfony 6
- Docker y Docker Compose

## Puesta en marcha

```bash
docker-compose up -d
```

La aplicación estará disponible en `http://localhost:8080`.

## Despliegue y funcionamiento

1. Clona este repositorio y accede al directorio `symfonyapi`.
2. Crea un fichero `.env.local` si necesitas personalizar variables de entorno.
3. Levanta los contenedores (la primera vez usa `--build` para crear la imagen):

```bash
docker-compose up --build -d
```

Esto instalará las dependencias con Composer y expondrá la API en el puerto `8080`.

Puedes entrar en el contenedor para ejecutar comandos de Symfony:

```bash
docker-compose exec app php bin/console about
```

Los datos del carrito y las órdenes se almacenan en el directorio `var/` dentro del contenedor.

## Ejecutar tests

```bash
./vendor/bin/phpunit
```
21 changes: 21 additions & 0 deletions symfonyapi/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_dir(dirname(__DIR__).'/vendor')) {
throw new LogicException('Dependencies are missing. Try running "composer install".');
}

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
23 changes: 23 additions & 0 deletions symfonyapi/bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
if (PHP_VERSION_ID >= 80000) {
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
} else {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
}
} else {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
7 changes: 7 additions & 0 deletions symfonyapi/compose.override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

services:
###> doctrine/doctrine-bundle ###
database:
ports:
- "5432"
###< doctrine/doctrine-bundle ###
73 changes: 73 additions & 0 deletions symfonyapi/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.15",
"doctrine/doctrine-migrations-bundle": "^3.4",
"doctrine/orm": "^3.5",
"symfony/console": "6.4.*",
"symfony/dotenv": "6.4.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.4.*",
"symfony/runtime": "6.4.*",
"symfony/yaml": "6.4.*"
},
"require-dev": {
"phpunit/phpunit": "^10",
"symfony/maker-bundle": "^1.64"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.4.*"
}
}
}
Loading