Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions back/src/app/Http/Controllers/ProfessorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function index()
}


public function store(Request $request)
public function store(StoreProfessorRequest $request)
{
try {
DB::beginTransaction();
Expand Down Expand Up @@ -51,7 +51,7 @@ public function store(Request $request)
}


public function update(Request $request, $id)
public function update(UpdateProfessorRequest $request, $id)
{
$professor = Professor::findOrFail($id);
$user = User::findOrFail($professor->id);
Expand Down Expand Up @@ -89,9 +89,19 @@ public function destroy($id)
$professor = Professor::findOrFail($id);
$user = User::findOrFail($id);

$professor->delete();
$user->delete();
try {
DB::beginTransaction();

$professor->delete();
$user->delete();

DB::commit();

return response()->json(null, 204);
return response()->json(null, 204);
} catch (\Throwable $e) {
DB::rollBack();

return response()->json(['error' => 'Erro ao deletar professor', 'details' => $e->getMessage()], 500);
}
}
}
32 changes: 32 additions & 0 deletions back/src/app/Http/Requests/StoreProfessorRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreProfessorRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => [ 'required', 'string', 'max:255', ],
'email' => [ 'required', 'string','email', 'max:255', Rule::unique('users', 'email'), ],
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for Rule class. Add use Illuminate\Validation\Rule; at the top of the file.

Copilot uses AI. Check for mistakes.
'password' => [ 'required', 'string', ],
'area_atuacao' => [ 'required', 'string', 'max:255', ],
];
}
}
33 changes: 33 additions & 0 deletions back/src/app/Http/Requests/UpdateProfessorRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateProfessorRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$professorId = $this->route('professor');

return [
'name' => [ 'sometimes', 'string', 'max:255', ],
'email' => [ 'sometimes', 'string','email', 'max:255', Rule::unique('users', 'email')->ignore($professorId), ],
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for Rule class. Add use Illuminate\Validation\Rule; at the top of the file.

Copilot uses AI. Check for mistakes.
'area_atuacao' => [ 'sometimes', 'string', 'max:255', ],
];
}
}