-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
44 lines (29 loc) · 1.98 KB
/
README
File metadata and controls
44 lines (29 loc) · 1.98 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
38
39
40
41
42
43
44
Headless Product Catalog API (Symfony 7, Doctrine ORM)
Требования: PHP 8.2+, Composer. Расширения: pdo_sqlite (или pdo_mysql/pdo_pgsql), ctype, iconv, json, mbstring.
Установка и запуск
composer install
# Настройте DATABASE_URL в .env при необходимости (по умолчанию SQLite: var/data.db)
php bin/console doctrine:migrations:migrate --no-interaction
php -S localhost:8000 -t public
API: базовый URL — http://localhost:8000
Ресурс: товар (Product). Поля: id, name, price, status (active|inactive), createdAt.
Эндпоинты
POST /api/products — создать товар (body JSON: name, price, status)
GET /api/products/{id} — получить товар по ID
PUT /api/products/{id} — обновить товар (body JSON: name, price, status, все опциональны)
PATCH /api/products/{id} — то же, что PUT
DELETE /api/products/{id} — удалить товар
Примеры (curl)
# Создать товар
curl -X POST http://localhost:8000/api/products -H "Content-Type: application/json" -d "{\"name\":\"Товар\",\"price\":\"99.99\",\"status\":\"active\"}"
# Получить товар
curl http://localhost:8000/api/products/1
# Обновить товар
curl -X PUT http://localhost:8000/api/products/1 -H "Content-Type: application/json" -d "{\"name\":\"Новое название\",\"price\":\"149.00\",\"status\":\"inactive\"}"
# Удалить товар
curl -X DELETE http://localhost:8000/api/products/1
Тесты
# Создать тестовую БД и применить миграции (нужен pdo_sqlite)
php bin/console doctrine:migrations:migrate --env=test --no-interaction
./vendor/bin/phpunit
Тесты: tests/Unit/Entity/ProductTest.php (unit: сущность и валидация), tests/Functional/ProductApiTest.php (функциональный: POST + GET и GET 404).