From ccb47abe1ef835185abdd1494d6809ec6e19bb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Legr=C3=A1n?= Date: Thu, 3 Oct 2024 10:28:29 +0200 Subject: [PATCH] feat(api)!: remove student modality endpoint --- .../StudentResume/ModalityAnnotation.php | 63 --------------- .../StudentResume/StudentDetailAnnotation.php | 9 +++ .../api/Student/StudentModalityController.php | 34 -------- app/Http/Resources/ResumeResource.php | 1 + app/Models/Resume.php | 2 +- .../Student/StudentModalityService.php | 36 --------- database/factories/ResumeFactory.php | 2 +- ...hange_modality_column_in_resumes_table.php | 34 ++++++++ routes/api/v1.php | 16 ---- .../Student/StudentDetailControllerTest.php | 1 + .../Student/StudentModalityControllerTest.php | 63 --------------- .../Student/StudentModalityServiceTest.php | 79 ------------------- 12 files changed, 47 insertions(+), 293 deletions(-) delete mode 100755 app/Annotations/OpenApi/Controllers/StudentResume/ModalityAnnotation.php delete mode 100755 app/Http/Controllers/api/Student/StudentModalityController.php delete mode 100755 app/Service/Student/StudentModalityService.php create mode 100644 database/migrations/2024_10_03_153607_change_modality_column_in_resumes_table.php delete mode 100755 tests/Feature/Controller/Student/StudentModalityControllerTest.php delete mode 100755 tests/Feature/Service/Student/StudentModalityServiceTest.php diff --git a/app/Annotations/OpenApi/Controllers/StudentResume/ModalityAnnotation.php b/app/Annotations/OpenApi/Controllers/StudentResume/ModalityAnnotation.php deleted file mode 100755 index c849b4dc..00000000 --- a/app/Annotations/OpenApi/Controllers/StudentResume/ModalityAnnotation.php +++ /dev/null @@ -1,63 +0,0 @@ - Resume"}, - * @OA\Parameter( - * name="studentId", - * in="path", - * description="Student ID", - * required=true, - * @OA\Schema( - * type="string", - * format="uuid" - * ) - * ), - * @OA\Response( - * response=200, - * description="Successful operation", - * @OA\JsonContent( - * type="object", - * @OA\Property( - * property="modality", - * type="array", - * @OA\Items(type="string"), - * example={"Presencial", "Remot"} - * ) - * ) - * ), - * @OA\Response( - * response=404, - * description="Student or Resume not found", - * @OA\JsonContent( - * type="object", - * @OA\Property(property="message", type="string", example="No s'ha trobat cap estudiant amb aquest ID {studentId}"), - * @OA\Property(property="message2", type="string", example="No s'ha trobat cap currículum per a l'estudiant amb id: {studentId}") - * ) - * ), - * @OA\Response( - * response=500, - * description="Server error", - * @OA\JsonContent( - * type="object", - * @OA\Property(property="error", type="string", example="Hi ha hagut un error") - * ) - * ) - * ) - */ - public function __invoke() - { - } -} diff --git a/app/Annotations/OpenApi/Controllers/StudentResume/StudentDetailAnnotation.php b/app/Annotations/OpenApi/Controllers/StudentResume/StudentDetailAnnotation.php index 6f1daea6..d2c99c81 100755 --- a/app/Annotations/OpenApi/Controllers/StudentResume/StudentDetailAnnotation.php +++ b/app/Annotations/OpenApi/Controllers/StudentResume/StudentDetailAnnotation.php @@ -1,4 +1,5 @@ studentModalityService = $studentModalityService; - } - - public function __invoke(string $studentId): JsonResponse - { - try { - $service = $this->studentModalityService->execute($studentId); - return response()->json(['modality' => $service]); - } catch (StudentNotFoundException | ResumeNotFoundException $e) { - return response()->json(['message' => $e->getMessage()], $e->getCode()); - } catch (Exception $e) { - return response()->json(['message' => $e->getMessage()], $e->getCode() ?: 500); - } - } -} \ No newline at end of file diff --git a/app/Http/Resources/ResumeResource.php b/app/Http/Resources/ResumeResource.php index 0e9130f2..4c0e5589 100755 --- a/app/Http/Resources/ResumeResource.php +++ b/app/Http/Resources/ResumeResource.php @@ -15,6 +15,7 @@ class ResumeResource extends JsonResource public function toArray(Request $request): array { return [ + 'modality' => $this->modality, 'subtitle' => $this->subtitle, 'social_media' => [ 'github' => $this->github_url, diff --git a/app/Models/Resume.php b/app/Models/Resume.php index c0fda918..2df9eb2f 100755 --- a/app/Models/Resume.php +++ b/app/Models/Resume.php @@ -43,6 +43,6 @@ public function projects(): BelongsToMany public function additionalTrainings(): BelongsToMany { - return $this->belongsToMany(AdditionalTraining::class); + return $this->belongsToMany(AdditionalTraining::class); } } diff --git a/app/Service/Student/StudentModalityService.php b/app/Service/Student/StudentModalityService.php deleted file mode 100755 index 168b3f3f..00000000 --- a/app/Service/Student/StudentModalityService.php +++ /dev/null @@ -1,36 +0,0 @@ -getModalityByStudentId($studentId); - } - - public function getModalityByStudentId(string $studentId): array - { - $student = Student::find($studentId); - - if (!$student) { - throw new StudentNotFoundException($studentId); - } - - $resume = $student->resume()->first(); - - if (!$resume) { - throw new ResumeNotFoundException($studentId); - } - - $modality = $resume->modality; - - return (array) $modality; - } -} diff --git a/database/factories/ResumeFactory.php b/database/factories/ResumeFactory.php index 855815e3..143b0a23 100755 --- a/database/factories/ResumeFactory.php +++ b/database/factories/ResumeFactory.php @@ -49,7 +49,7 @@ public function definition(): array ), 'development' => $development, 'about' => $this->faker->paragraph, - 'modality' => $this->faker->randomElements(['Presencial', 'Híbrid', 'Remot'], rand(1, 3)), + 'modality' => $this->faker->randomElement(['Presencial', 'Híbrid', 'Remot']), 'collaborations_ids' => json_encode($collaborationsIds), ]; } diff --git a/database/migrations/2024_10_03_153607_change_modality_column_in_resumes_table.php b/database/migrations/2024_10_03_153607_change_modality_column_in_resumes_table.php new file mode 100644 index 00000000..06eed925 --- /dev/null +++ b/database/migrations/2024_10_03_153607_change_modality_column_in_resumes_table.php @@ -0,0 +1,34 @@ +dropColumn('modality'); + + $table->enum('modality', ['Presencial', 'Remot', 'Híbrid'])->default('Presencial')->after('specialization'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('resumes', function (Blueprint $table) { + $table->dropColumn('modality'); + + $table->json('modality')->after('specialization')->nullable(); + }); + } +}; diff --git a/routes/api/v1.php b/routes/api/v1.php index 42f6f008..ff0e7aae 100644 --- a/routes/api/v1.php +++ b/routes/api/v1.php @@ -6,7 +6,6 @@ DeleteStudentResumeLanguageController, GetStudentImageController, StudentAdditionalTrainingListController, - StudentModalityController, StudentBootcampDetailController, StudentCollaborationDetailController, StudentDetailController, @@ -56,7 +55,6 @@ Route::get('additionaltraining', StudentAdditionalTrainingListController::class)->name('student.additionaltraining'); Route::get('languages', StudentLanguagesDetailController::class)->name('student.languages'); Route::put('languages', UpdateStudentLanguagesController::class)->name('student.languages.update'); - Route::get('modality', StudentModalityController::class)->name('student.modality'); Route::get('photo', GetStudentImageController::class)->middleware('auth:api', EnsureStudentOwner::class)->name('student.photo.get'); Route::put('projects/{projectId}', UpdateStudentProjectController::class)->middleware('auth:api', EnsureStudentOwner::class)->name('student.updateProject'); //Route::put('skills', UpdateStudentSkillsController::class)->middleware('auth:api')->name('student.skills'); @@ -74,17 +72,3 @@ Route::get('/{tagId}', TagDetailController::class)->name('tag.detail'); Route::put('/{tagId}', TagUpdateController::class)->name('tag.update'); }); -// ! OLD ROUTES BLOCK -Route::get('/student/list/for-home', StudentListController::class)->name('profiles.home'); -Route::get('/student/{id}/detail/for-home', StudentDetailController::class)->name('student.detail'); -Route::get('/students/{student}/projects', StudentProjectsDetailController::class)->name('projects.list'); -Route::get('/students/{student}/collaborations', StudentCollaborationDetailController::class)->name('collaborations.list'); -Route::get('/students/{id}/bootcamp', StudentBootcampDetailController::class)->name('bootcamp.list'); -Route::get('/students/{student}/additionaltraining', StudentAdditionalTrainingListController::class)->name('additionaltraining.list'); -Route::get('/students/{id}/languages', StudentLanguagesDetailController::class)->name('languages.list'); -Route::get('/modality/{studentId}', StudentModalityController::class)->name('modality'); -// Fake endpoint development -Route::get('/development/list', DevelopmentListController::class)->name('development.list'); -// Specialization List Endpoint -Route::get('/specialization/list', SpecializationListController::class)->name('roles.list'); -// ! OLD ROUTES BLOCK diff --git a/tests/Feature/Controller/Student/StudentDetailControllerTest.php b/tests/Feature/Controller/Student/StudentDetailControllerTest.php index a8f44b80..9e88401d 100755 --- a/tests/Feature/Controller/Student/StudentDetailControllerTest.php +++ b/tests/Feature/Controller/Student/StudentDetailControllerTest.php @@ -64,6 +64,7 @@ public function testStudentDetailsJsonFormat(): void ]; })->toArray(), 'resume' => [ + 'modality' => $this->resume->modality, 'subtitle' => $this->resume->subtitle, 'social_media' => [ 'github' => $this->resume->github_url, diff --git a/tests/Feature/Controller/Student/StudentModalityControllerTest.php b/tests/Feature/Controller/Student/StudentModalityControllerTest.php deleted file mode 100755 index a8cc6489..00000000 --- a/tests/Feature/Controller/Student/StudentModalityControllerTest.php +++ /dev/null @@ -1,63 +0,0 @@ -id; - - Resumes::createResumeWithModality($studentId, 'frontend', [1, 3], 'Presencial'); - - $response = $this->getJson(route('student.modality', ['studentId' => $studentId])); - - $response->assertStatus(200); - - $response->assertJsonStructure(['modality']); - } - - public function testStudentModalityControllerReturns_404StatusAndResumeNotFoundExceptionMessageForValidStudentUuidWithoutResume():void - { - $student = Students::aStudent(); - - $studentId = $student->id; - - $response = $this->getJson(route('student.modality', ['studentId' => $studentId])); - - $response->assertStatus(404); - - $response->assertJson(['message' => 'No s\'ha trobat cap currículum per a l\'estudiant amb id: ' . $studentId]); - } - - public function testStudentModalityControllerReturns_404StatusAndStudentNotFoundExceptionMessageForInvalidStudentUuid(): void - { - $response = $this->getJson(route('student.modality', ['studentId' => 'nonExistentStudentId'])); - $response->assertStatus(404); - $response->assertJson(['message' => 'No s\'ha trobat cap estudiant amb aquest ID: nonExistentStudentId']); - } - - public function testStudentModalityControllerCanBeInstantiated():void - { - $studentModalityService = $this->createMock(StudentModalityService::class); - - $controller = new StudentModalityController($studentModalityService); - - $this->assertInstanceOf(StudentModalityController::class, $controller); - } -} - - diff --git a/tests/Feature/Service/Student/StudentModalityServiceTest.php b/tests/Feature/Service/Student/StudentModalityServiceTest.php deleted file mode 100755 index af4872e3..00000000 --- a/tests/Feature/Service/Student/StudentModalityServiceTest.php +++ /dev/null @@ -1,79 +0,0 @@ -studentModalityService = new StudentModalityService(); - } - - public function testExecuteWithValidStudentId(): void - { - $student = Students::aStudent(); - - $studentId = $student->id; - - Resumes::createResumeWithModality($studentId, 'frontend', [2, 7], 'Presencial'); - - $result = $this->studentModalityService->execute($studentId); - - $this->assertIsArray($result); - } - - public function testServiceHandlesStudentWithoutModality():void - { - $student = Students::aStudent(); - - $studentId = $student->id; - - Resumes::createResumeWithoutModality($studentId, 'frontend', [9, 10]); - - $result = $this->studentModalityService->execute($studentId); - - $this->assertIsArray($result); - - $this->assertEmpty($result); - } - - public function testExecuteWithInvalidStudentId():void - { - $this->expectException(StudentNotFoundException::class); - - $this->studentModalityService->execute('nonExistentStudentId'); - } - - public function testExecuteThrowsExceptionForStudentWithoutResume():void - { - $student = Students::aStudent(); - - $studentId = $student->id; - - $this->expectException(ResumeNotFoundException::class); - - $this->studentModalityService->execute($studentId); - } - - public function testModalityServiceCanBeInstantiated(): void - { - self::assertInstanceOf(StudentModalityService::class, $this->studentModalityService); - } - -}