first commit

This commit is contained in:
2026-02-04 23:23:42 +07:00
commit ee28ea1a2d
202 changed files with 34797 additions and 0 deletions

181
README.md Normal file
View File

@@ -0,0 +1,181 @@
# Тестовое задание
**На хост машине**
```bash
docker compose build --no-cache
docker compose up -d
docker compose exec php sh
npm run build
```
**Внутри контейнера**
```sh
php artisan migrate
php artisan db:seed # включая заполнение статей и комментариев
php artisan test # запуск тестов, включая тесты контроллеров
```
Маршруты в api.php
```php
Route::prefix('articles')->group(function () {
// Список статей
Route::get('/', [ArticleController::class, 'index'])->name('articles.index');
// Просмотр одной статьи
Route::get('/{article}', [ArticleController::class, 'show'])->name('articles.show');
// Создание статьи
Route::post('/', [ArticleController::class, 'store'])->name('articles.store');
// Создание комментария для статьи
Route::post('/{article}/comments', [CommentController::class, 'store'])->name('comments.store');
});
```
Маршруты в web.php
```php
// Главная страница
Route::get('/', function () {
return Inertia::render('welcome');
})->name('home');
// Просмотр статьи через Inertia
Route::get('/articles/{id}', function ($id) {
return Inertia::render('Articles/Show', [
'articleId' => (int)$id,
]);
});
// Панель управления (только для авторизованных пользователей)
Route::get('dashboard', function () {
return Inertia::render('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');
```
## Запросы
1. Получение одной статьи с комментариями
```bash
curl -X GET http://localhost:8080/api/articles/45
```
```json
{
"data": {
"id": 45,
"title": "s",
"content": "s",
"created_at": "2026-02-04",
"comments": [
{
"id": 62,
"author_name": "d",
"content": "d",
"created_at": "2026-02-04 15:51:11"
},
{
"id": 63,
"author_name": "d",
"content": "d",
"created_at": "2026-02-04 15:51:15"
}
]
}
}
```
2. Создание новой статьи
```bash
curl -X POST http://localhost:8080/api/articles \
-H "Content-Type: application/json" \
-d '{"title":"Новая статья","content":"Содержание статьи"}'
```
```json
{
"data": {
"id": 46,
"title": "Новая статья",
"content_short": "Содержание статьи",
"created_at": "2026-02-04",
"comments_count": 0
}
}
```
3. Создание комментария для статьи
```bash
curl -X POST http://localhost:8080/api/articles/46/comments \
-H "Content-Type: application/json" \
-d '{"author_name":"Иван","content":"Отличная статья!"}'
```
```json
{
"data": {
"id": 64,
"author_name": "Иван",
"content": "Отличная статья!",
"created_at": "2026-02-04 16:09:51"
}
}
```
4. Получение списка всех статей
```bash
curl -X GET http://localhost:8080/api/articles
```
```json
{
"data": [
{
"id": 45,
"title": "s",
"content_short": "s",
"created_at": "2026-02-04",
"comments_count": 2
},
{
"id": 44,
"title": "cazxdasd",
"content_short": "asdasdasd",
"created_at": "2026-02-04",
"comments_count": 3
},
{
"id": 39,
"title": "Delectus eaque sunt soluta ut tempora similique necessitatibus.",
"content_short": "Odit id quisquam consequuntur quis. Amet debitis e",
"created_at": "2026-02-04",
"comments_count": 1
},
{
"id": 40,
"title": "Tempore possimus qui ea eaque incidunt.",
"content_short": "Inventore excepturi expedita vitae nihil provident",
"created_at": "2026-02-04",
"comments_count": 3
}
]
}
```
### Комментарий:
Установил базовый пакет laravel для регистрации и тд
Маршруты не защищал
HTTPS не настраивал через certbot
Время, около 3х часов