Исправлены модели, контроллеры и маршруты для AI-сборки
This commit is contained in:
@@ -18,22 +18,14 @@ class AuthController extends Controller
|
|||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
'email' => 'required|string|email|max:255|unique:users',
|
'email' => 'required|string|email|max:255|unique:users',
|
||||||
'password' => 'required|string|min:8|confirmed',
|
'password' => 'required|string|min:8|confirmed',
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
=======
|
|
||||||
'custom_field' => 'required|string|min:2'
|
|
||||||
>>>>>>> origin/main
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'name' => $validated['name'],
|
'name' => $validated['name'],
|
||||||
'email' => $validated['email'],
|
'email' => $validated['email'],
|
||||||
'password' => Hash::make($validated['password']),
|
'password' => Hash::make($validated['password']),
|
||||||
<<<<<<< HEAD
|
|
||||||
'custom_field' => $request->custom_field ?? 'user', // ← ключевая строка
|
'custom_field' => $request->custom_field ?? 'user', // ← ключевая строка
|
||||||
=======
|
|
||||||
'custom_field' => $validated['custom_field'],
|
|
||||||
>>>>>>> origin/main
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use Illuminate\Http\Response;
|
|||||||
|
|
||||||
class ComponentsController extends Controller
|
class ComponentsController extends Controller
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
// Начинаем с базового запроса
|
// Начинаем с базового запроса
|
||||||
@@ -45,20 +44,6 @@ class ComponentsController extends Controller
|
|||||||
|
|
||||||
return response()->json($components);
|
return response()->json($components);
|
||||||
}
|
}
|
||||||
=======
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
$components = Component::with('user', 'componentType')
|
|
||||||
->where('is_official', true)
|
|
||||||
->orWhere('created_by_user_id', auth()->id())
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return response()->json($components);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
>>>>>>> origin/main
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$component = Component::find($id);
|
$component = Component::find($id);
|
||||||
@@ -70,7 +55,6 @@ public function index()
|
|||||||
return response()->json($component);
|
return response()->json($component);
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
@@ -137,77 +121,3 @@ public function index()
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
=======
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
$validated = $request->validate([
|
|
||||||
'name' => 'required|string|max:255',
|
|
||||||
'price' => 'required|numeric|min:0',
|
|
||||||
'component_type_id' => 'required|exists:component_types,id',
|
|
||||||
'specifications' => 'nullable|array',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$component = Component::create([
|
|
||||||
'name' => $validated['name'],
|
|
||||||
'price' => $validated['price'],
|
|
||||||
'component_type_id' => $validated['component_type_id'],
|
|
||||||
'specifications' => $validated['specifications'] ?? null,
|
|
||||||
'is_official' => false, // всегда false для пользователя
|
|
||||||
'created_by_user_id' => auth()->id(), // автоматически привязываем к пользователю
|
|
||||||
]);
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Компонент успешно создан.',
|
|
||||||
'component' => $component
|
|
||||||
], 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
|
||||||
{
|
|
||||||
$component = Component::findOrFail($id);
|
|
||||||
|
|
||||||
// Проверяем, что компонент принадлежит пользователю и не официальный
|
|
||||||
if ($component->created_by_user_id !== auth()->id() || $component->is_official) {
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Вы не можете редактировать этот компонент.'
|
|
||||||
], 403);
|
|
||||||
}
|
|
||||||
|
|
||||||
$validated = $request->validate([
|
|
||||||
'name' => 'required|string|max:255',
|
|
||||||
'price' => 'required|numeric|min:0',
|
|
||||||
'component_type_id' => 'required|exists:component_types,id',
|
|
||||||
'specifications' => 'nullable|array',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$component->update($validated);
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Компонент обновлён.',
|
|
||||||
'component' => $component
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroy($id)
|
|
||||||
{
|
|
||||||
$component = Component::findOrFail($id);
|
|
||||||
|
|
||||||
// Проверяем, что компонент принадлежит пользователю и не официальный
|
|
||||||
if ($component->created_by_user_id !== auth()->id() || $component->is_official) {
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Вы не можете удалить этот компонент.'
|
|
||||||
], 403);
|
|
||||||
}
|
|
||||||
|
|
||||||
$component->delete();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'message' => 'Компонент удалён.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
>>>>>>> origin/main
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ class AiTask extends Model
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
<<<<<<< HEAD
|
|
||||||
'title',
|
'title',
|
||||||
'description',
|
'description',
|
||||||
'ai_prompt_template',
|
'ai_prompt_template',
|
||||||
@@ -24,35 +23,4 @@ class AiTask extends Model
|
|||||||
'budget_max' => 'decimal:2',
|
'budget_max' => 'decimal:2',
|
||||||
'is_active' => 'boolean'
|
'is_active' => 'boolean'
|
||||||
];
|
];
|
||||||
=======
|
|
||||||
'user_id',
|
|
||||||
'name',
|
|
||||||
'prompt_template',
|
|
||||||
'is_active',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $casts = [
|
|
||||||
'is_active' => 'boolean',
|
|
||||||
'created_at' => 'datetime',
|
|
||||||
'updated_at' => 'datetime',
|
|
||||||
];
|
|
||||||
|
|
||||||
// Связь с пользователем (если шаблон пользовательский)
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Общие (глобальные) шаблоны — где user_id IS NULL
|
|
||||||
public function scopeGlobal($query)
|
|
||||||
{
|
|
||||||
return $query->whereNull('user_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Активные шаблоны
|
|
||||||
public function scopeActive($query)
|
|
||||||
{
|
|
||||||
return $query->where('is_active', true);
|
|
||||||
}
|
|
||||||
>>>>>>> origin/main
|
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,6 @@ class PcBuild extends Model
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
// 👇 Связь "многие-ко-многим" с компонентами
|
// 👇 Связь "многие-ко-многим" с компонентами
|
||||||
public function components()
|
public function components()
|
||||||
{
|
{
|
||||||
@@ -26,20 +25,10 @@ class PcBuild extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Обратная связь
|
// Обратная связь
|
||||||
=======
|
|
||||||
protected $casts = [
|
|
||||||
'is_ai_generated' => 'boolean',
|
|
||||||
'created_at' => 'datetime',
|
|
||||||
'updated_at' => 'datetime',
|
|
||||||
];
|
|
||||||
|
|
||||||
// Связь с пользователем
|
|
||||||
>>>>>>> origin/main
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
// Опционально: защита от ошибок, если сборка без пользователя
|
// Опционально: защита от ошибок, если сборка без пользователя
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
@@ -50,6 +39,4 @@ class PcBuild extends Model
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
=======
|
|
||||||
>>>>>>> origin/main
|
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,7 @@ use Illuminate\Foundation\Application;
|
|||||||
use Illuminate\Foundation\Configuration\Exceptions;
|
use Illuminate\Foundation\Configuration\Exceptions;
|
||||||
use Illuminate\Foundation\Configuration\Middleware;
|
use Illuminate\Foundation\Configuration\Middleware;
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
// bootstrap/app.php
|
// bootstrap/app.php
|
||||||
=======
|
|
||||||
>>>>>>> origin/main
|
|
||||||
return Application::configure(basePath: dirname(__DIR__))
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
->withRouting(
|
->withRouting(
|
||||||
web: __DIR__.'/../routes/web.php',
|
web: __DIR__.'/../routes/web.php',
|
||||||
@@ -15,7 +12,6 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
commands: __DIR__.'/../routes/console.php',
|
commands: __DIR__.'/../routes/console.php',
|
||||||
health: '/up',
|
health: '/up',
|
||||||
)
|
)
|
||||||
<<<<<<< HEAD
|
|
||||||
->withMiddleware(function (Middleware $middleware) {
|
->withMiddleware(function (Middleware $middleware) {
|
||||||
// Убедитесь, что HandleCors здесь
|
// Убедитесь, что HandleCors здесь
|
||||||
$middleware->api(prepend: [
|
$middleware->api(prepend: [
|
||||||
@@ -30,11 +26,3 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
->withExceptions(function (Exceptions $exceptions) {
|
->withExceptions(function (Exceptions $exceptions) {
|
||||||
//
|
//
|
||||||
})->create();
|
})->create();
|
||||||
=======
|
|
||||||
->withMiddleware(function (Middleware $middleware): void {
|
|
||||||
//
|
|
||||||
})
|
|
||||||
->withExceptions(function (Exceptions $exceptions): void {
|
|
||||||
//
|
|
||||||
})->create();
|
|
||||||
>>>>>>> origin/main
|
|
||||||
|
|||||||
@@ -8,20 +8,13 @@ use Illuminate\Database\Seeder;
|
|||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
class DatabaseSeeder extends Seeder
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
use WithoutModelEvents;
|
|
||||||
>>>>>>> origin/main
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seed the application's database.
|
* Seed the application's database.
|
||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
|
||||||
$this->call(ComponentSeeder::class);
|
$this->call(ComponentSeeder::class);
|
||||||
=======
|
|
||||||
>>>>>>> origin/main
|
|
||||||
// User::factory(10)->create();
|
// User::factory(10)->create();
|
||||||
|
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default function AiSuggest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
'http://localhost:8000/api/ai/suggest',
|
'http://localhost/api/ai/suggest',
|
||||||
{
|
{
|
||||||
task_id: task,
|
task_id: task,
|
||||||
budget: parseFloat(budget),
|
budget: parseFloat(budget),
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\ComponentsController;
|
use App\Http\Controllers\ComponentsController;
|
||||||
use App\Http\Controllers\AuthController;
|
use App\Http\Controllers\AuthController;
|
||||||
<<<<<<< HEAD
|
|
||||||
use App\Http\Controllers\PCBuildsController;
|
use App\Http\Controllers\PCBuildsController;
|
||||||
use App\Http\Controllers\AiController;
|
use App\Http\Controllers\AiController;
|
||||||
=======
|
|
||||||
>>>>>>> origin/main
|
|
||||||
|
|
||||||
Route::get('/users', function (Request $request) {
|
Route::get('/users', function (Request $request) {
|
||||||
return $request->user();
|
return $request->user();
|
||||||
@@ -43,7 +40,6 @@ Route::middleware('auth:sanctum')->group(function () {
|
|||||||
Route::delete('/components/{id}', [ComponentsController::class, 'destroy']);
|
Route::delete('/components/{id}', [ComponentsController::class, 'destroy']);
|
||||||
});
|
});
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
Route::middleware('auth:sanctum')->group(function () {
|
Route::middleware('auth:sanctum')->group(function () {
|
||||||
Route::get('/builds', [PCBuildsController::class, 'index']);
|
Route::get('/builds', [PCBuildsController::class, 'index']);
|
||||||
Route::post('/builds', [PCBuildsController::class, 'store']);
|
Route::post('/builds', [PCBuildsController::class, 'store']);
|
||||||
@@ -55,7 +51,5 @@ Route::middleware('auth:sanctum')->group(function () {
|
|||||||
Route::middleware('auth:sanctum')->group(function () {
|
Route::middleware('auth:sanctum')->group(function () {
|
||||||
Route::post('/ai/suggest', [AiController::class, 'suggest']);
|
Route::post('/ai/suggest', [AiController::class, 'suggest']);
|
||||||
});
|
});
|
||||||
=======
|
|
||||||
>>>>>>> origin/main
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user