Sfoglia il codice sorgente

feat: adiciona listagem de responsaveis

ebagabee 1 mese fa
parent
commit
38e9f81db9

+ 2 - 2
app/Http/Controllers/StudentResponsibleController.php

@@ -15,8 +15,8 @@ public function __construct(
 
     public function getByStudent(int $studentId): JsonResponse
     {
-        $item = $this->service->getByStudentId($studentId);
-        return $this->successResponse(payload: $item ? new StudentResponsibleResource($item) : null);
+        $items = $this->service->getByStudentId($studentId);
+        return $this->successResponse(payload: StudentResponsibleResource::collection($items));
     }
 
     public function store(StudentResponsibleRequest $request): JsonResponse

+ 2 - 2
app/Services/StudentResponsibleService.php

@@ -7,9 +7,9 @@
 
 class StudentResponsibleService
 {
-    public function getByStudentId(int $studentId): ?StudentResponsible
+    public function getByStudentId(int $studentId): Collection
     {
-        return StudentResponsible::where('student_id', $studentId)->first();
+        return StudentResponsible::where('student_id', $studentId)->get();
     }
 
     public function findById(int $id): ?StudentResponsible

+ 0 - 11
app/Services/StudentService.php

@@ -3,7 +3,6 @@
 namespace App\Services;
 
 use App\Models\Student;
-use App\Models\StudentResponsible;
 use App\Models\User;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Http\UploadedFile;
@@ -41,19 +40,9 @@ public function update(int $id, array $data): ?Student
             return null;
         }
 
-        $responsibleData = $data['responsible'] ?? null;
-        unset($data['responsible']);
-
         $data = $this->handlePhoto($data, $model->photo_url);
         $model->update($data);
 
-        if ($responsibleData !== null) {
-            StudentResponsible::updateOrCreate(
-                ['student_id' => $id],
-                array_merge($responsibleData, ['student_id' => $id]),
-            );
-        }
-
         return $model->fresh();
     }