Skip to content

Commit

Permalink
Merge pull request #128 from IT-Academy-BCN/feature/123-make-about-to…
Browse files Browse the repository at this point in the history
…-return-real-data

Feature/123 make about to return real data
  • Loading branch information
Agonpas authored May 5, 2024
2 parents c126725 + 18276a5 commit 22761f7
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,67 @@
class AnnotationsStudentDetail
{
/**
* @OA\Get(
* path="/student/detail/for-home",
* operationId="getStudentDetail",
* @OA\Get (
* path="/student/{id}/detail/for-home",
* operationId="getStudentDetailsabout",
* tags={"Student"},
* summary="Get Student Detail.",
* description="Get student detail registered. No authentication required",
*
* description="Retrieve details of a specific student. No authentication required.",
* @OA\Parameter(
* name="id",
* in="path",
* description="Student ID",
* required=true,
* @OA\Schema(
* type="string"
* )
* ),
* @OA\Response(
* response=200,
* description="",
*
* description="Success. Returns the student details.",
* @OA\JsonContent(
* @OA\Property(
* type="array",
* property="data",
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(property="student_id", type="integer", example=1),
* @OA\Property(property="fullname", type="string", example="Katrine Wyman Jacobson"),
* @OA\Property(property="subtitle", type="string", example="Full Stack developer en PHP"),
* @OA\Property(
* property="profile_detail",
* property="social_media",
* type="object",
* @OA\Property(property="fullname", type="string", example="Juan Pérez"),
* @OA\Property(property="subtitle", type="string", example="Desarrollador Frontend"),
* @OA\Property(
* property="social_media",
* property="github",
* type="object",
* @OA\Property(
* property="linkedin",
* type="object",
* @OA\Property(property="url", type="string", example="https://es.linkedin.com/"),
* ),
* @OA\Property(
* property="github",
* type="object",
* @OA\Property(property="url", type="string", example="https://github.com/"),
* )
* @OA\Property(property="url", type="string", example="https://github.com/bettie52")
* ),
* @OA\Property(
* property="about",
* property="linkedin",
* type="object",
* @OA\Property(property="description", type="string", example="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam a euismod elit. Nunc elit ante, vulputate sed maximus eu, posuere eu nibh. In eget lacus in mi pharetra volutpat a a justo. Fusce aliquet nibh nec accumsan facilisis. Suspendisse in tempor nibh, eu fermentum velit. Suspendisse cursus ultricies ipsum, eget tincidunt arcu pretium laoreet. Pellentesque eget egestas erat. Donec dapibus pharetra ultrices. Vivamus mollis sapien sed laoreet interdum."
* )
* ),
* @OA\Property(property="tags",type="array",@OA\Items(ref="#/components/schemas/Tag"))
* @OA\Property(property="url", type="string", example="https://linkedin.com/abernathy.dayne")
* )
* ),
* @OA\Property(property="about", type="string", example="Iusto aut debitis soluta facere tempore quisquam. Vel assumenda aliquid quod et eum quos ex. Ipsa ea tempora minima occaecati. Culpa occaecati quod laboriosam reiciendis quia consequuntur."),
* @OA\Property(
* property="tags",
* type="array",
* @OA\Items(
* @OA\Property(property="id", type="integer", example=4),
* @OA\Property(property="name", type="string", example="HTML&CSS")
* )
*
* )
* )
* )
* ),
*
*
* @OA\Schema(
* schema="Tag",
* type="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="JavaScript"),
* example={"id": 1, "name": "JavaScript"}
* )
* )
* )
* )
* )
* ),
* @OA\Response(
* response=404,
* description="No hem trobat cap estudiant amb aquest ID"
* ),
* @OA\Response(
* response=500,
* description="Error inesperat"
* )
* )
*/
public function __invoke() {}
public function show() {}
}
26 changes: 21 additions & 5 deletions app/Http/Controllers/api/StudentDetailController.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
<?php

declare(strict_types=1);
namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Models\Resume;
use App\Service\StudentDetailsService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Exceptions\StudentNotFoundException;

class StudentDetailController extends Controller
{
public function __invoke()
{
$data = file_get_contents(base_path('database/data/studentDetail.json'));
private StudentDetailsService $studentDetailsService;

return response()->json(json_decode($data, true));
public function __construct(StudentDetailsService $studentDetailsService)
{
$this->studentDetailsService =$studentDetailsService;
}
function __invoke($studentId):JsonResponse
{
try {
$service = $this->studentDetailsService->execute($studentId);
return response()->json(['data'=> [$service]], 200);
} catch (StudentNotFoundException $e) {
return response()->json(['message' => $e->getMessage()], $e->getCode());
} catch (\Exception $e) {
return response()->json(['error' => 'Error inesperat'], 500);
}
}
}
1 change: 1 addition & 0 deletions app/Models/Resume.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ public function bootcamps()
return $this->belongsToMany(Bootcamp::class)->withPivot('end_date');
}
}

66 changes: 66 additions & 0 deletions app/Service/StudentDetailsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace App\Service;

use App\Exceptions\StudentNotFoundException;
use App\Exceptions\ResumeNotFoundException;
use App\Models\Resume;
use App\Models\Student;
use App\Models\Tag;

class StudentDetailsService
{
public function execute($student)
{
return $this->getStudentDetailsById($student);
}


public function getStudentDetailsById($studentId){

$resume = Resume::where('student_id', $studentId)->first();

if(!$resume){
throw new ResumeNotFoundException($studentId);
}

$student = Student::find($resume->student_id);

if(!$student){
throw new StudentNotFoundException($studentId);
}

$fullName = $student->name . ' ' . $student->surname;

$tagsIds = json_decode($resume->tags_ids, true);
$tags = Tag::whereIn('id', $tagsIds)->get(['id', 'tag_name'])->toArray();

$formattedTags = [];
foreach ($tags as $tag) {
$formattedTags[] = [
'id' => $tag['id'],
'name' => $tag['tag_name']
];
}

return [
'fullname' => $fullName,
'subtitle' => $resume->subtitle,
'social_media' => [
'github' => [
'url' => $resume->github_url
],
'linkedin' => [
'url' => $resume->linkedin_url
]

],
'about' => $resume->about,
'tags' => $formattedTags,
];

}

}
1 change: 1 addition & 0 deletions database/factories/ResumeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function definition(): array
['Frontend', 'Backend', 'Fullstack', 'Data Science', 'Not Set'],
),
'project_ids' => json_encode($projectIds),
'about' => $this->faker->paragraph,
'modality' => $this->faker->randomElements(['Presencial', 'Híbrid', 'Remot'], rand(1, 3)),
'additional_trainings_ids' => json_encode($additionalTrainingsIds),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
*/
public function up(): void
{
//
Schema::table('resumes', function (Blueprint $table) {
$table->text('about')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
//
Schema::table('resumes', function (Blueprint $table) {
$table->dropColumn('about');
});
}
};
2 changes: 1 addition & 1 deletion routes/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

// Students Home
Route::get('/student/list/for-home', StudentListController::class)->name('profiles.home');
Route::get('/student/detail/for-home', StudentDetailController::class)->name('student.detail');
Route::get('/student/{id}/detail/for-home', StudentDetailController::class)->name('student.detail');

Route::post('/recruiters', [RecruiterController::class, 'store'])->name('recruiter.create');
Route::get('/recruiters', [RecruiterController::class, 'index'])->name('recruiter.list');
Expand Down
Loading

0 comments on commit 22761f7

Please sign in to comment.