Исправлены модели, контроллеры и маршруты для AI-сборки
This commit is contained in:
@@ -18,22 +18,14 @@ class AuthController extends Controller
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
'custom_field' => 'required|string|min:2'
|
||||
>>>>>>> origin/main
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $validated['name'],
|
||||
'email' => $validated['email'],
|
||||
'password' => Hash::make($validated['password']),
|
||||
<<<<<<< HEAD
|
||||
'custom_field' => $request->custom_field ?? 'user', // ← ключевая строка
|
||||
=======
|
||||
'custom_field' => $validated['custom_field'],
|
||||
>>>>>>> origin/main
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -9,7 +9,6 @@ use Illuminate\Http\Response;
|
||||
|
||||
class ComponentsController extends Controller
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Начинаем с базового запроса
|
||||
@@ -45,20 +44,6 @@ class ComponentsController extends Controller
|
||||
|
||||
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)
|
||||
{
|
||||
$component = Component::find($id);
|
||||
@@ -70,7 +55,6 @@ public function index()
|
||||
return response()->json($component);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public function store(Request $request)
|
||||
{
|
||||
$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;
|
||||
|
||||
protected $fillable = [
|
||||
<<<<<<< HEAD
|
||||
'title',
|
||||
'description',
|
||||
'ai_prompt_template',
|
||||
@@ -24,35 +23,4 @@ class AiTask extends Model
|
||||
'budget_max' => 'decimal:2',
|
||||
'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()
|
||||
{
|
||||
@@ -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()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
// Опционально: защита от ошибок, если сборка без пользователя
|
||||
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\Middleware;
|
||||
|
||||
<<<<<<< HEAD
|
||||
// bootstrap/app.php
|
||||
=======
|
||||
>>>>>>> origin/main
|
||||
return Application::configure(basePath: dirname(__DIR__))
|
||||
->withRouting(
|
||||
web: __DIR__.'/../routes/web.php',
|
||||
@@ -15,7 +12,6 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
commands: __DIR__.'/../routes/console.php',
|
||||
health: '/up',
|
||||
)
|
||||
<<<<<<< HEAD
|
||||
->withMiddleware(function (Middleware $middleware) {
|
||||
// Убедитесь, что HandleCors здесь
|
||||
$middleware->api(prepend: [
|
||||
@@ -30,11 +26,3 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
->withExceptions(function (Exceptions $exceptions) {
|
||||
//
|
||||
})->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
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
use WithoutModelEvents;
|
||||
>>>>>>> origin/main
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
$this->call(ComponentSeeder::class);
|
||||
=======
|
||||
>>>>>>> origin/main
|
||||
// User::factory(10)->create();
|
||||
|
||||
User::factory()->create([
|
||||
|
||||
@@ -37,7 +37,7 @@ export default function AiSuggest() {
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
'http://localhost:8000/api/ai/suggest',
|
||||
'http://localhost/api/ai/suggest',
|
||||
{
|
||||
task_id: task,
|
||||
budget: parseFloat(budget),
|
||||
|
||||
@@ -5,11 +5,8 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\ComponentsController;
|
||||
use App\Http\Controllers\AuthController;
|
||||
<<<<<<< HEAD
|
||||
use App\Http\Controllers\PCBuildsController;
|
||||
use App\Http\Controllers\AiController;
|
||||
=======
|
||||
>>>>>>> origin/main
|
||||
|
||||
Route::get('/users', function (Request $request) {
|
||||
return $request->user();
|
||||
@@ -43,7 +40,6 @@ Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::delete('/components/{id}', [ComponentsController::class, 'destroy']);
|
||||
});
|
||||
|
||||
<<<<<<< HEAD
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::get('/builds', [PCBuildsController::class, 'index']);
|
||||
Route::post('/builds', [PCBuildsController::class, 'store']);
|
||||
@@ -55,7 +51,5 @@ Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::post('/ai/suggest', [AiController::class, 'suggest']);
|
||||
});
|
||||
=======
|
||||
>>>>>>> origin/main
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user