Исправлены модели, контроллеры и маршруты для AI-сборки

This commit is contained in:
dimon8
2026-01-12 08:04:42 +00:00
parent 2d98209ce1
commit e7b63f7863
8 changed files with 1 additions and 169 deletions

View File

@@ -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([

View File

@@ -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