Исправлены модели, контроллеры и маршруты для 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
|
||||
}
|
||||
Reference in New Issue
Block a user