You've already forked isop-mirror
feat: add API route for getting a single internship
This commit is contained in:
@@ -65,6 +65,33 @@ class InternshipController extends Controller
|
|||||||
return response()->json($internships);
|
return response()->json($internships);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get(int $id) {
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
$internship = Internship::find($id);
|
||||||
|
|
||||||
|
if(!$internship) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'No such internship exists.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->role !== 'ADMIN' && $internship->user_id !== $user->id) {
|
||||||
|
abort(403, 'Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
|
$internship->company = Company::find($internship->company_id)->makeHidden(['created_at', 'updated_at']);
|
||||||
|
unset($internship->company_id);
|
||||||
|
|
||||||
|
$internship->contact = User::find($internship->company->contact)->makeHidden(['created_at', 'updated_at', 'email_verified_at']);
|
||||||
|
unset($internship->company->contact);
|
||||||
|
|
||||||
|
$internship->status = InternshipStatus::whereColumn('internship_id', '=', $internship->id)->get()->first()->makeHidden(['created_at', 'updated_at', 'id']);
|
||||||
|
$internship->status->modified_by = User::find($internship->status->modified_by)->makeHidden(['created_at', 'updated_at', 'email_verified_at']);
|
||||||
|
|
||||||
|
return response()->json($internship);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ Route::prefix('/internships')->group(function () {
|
|||||||
Route::get("/my", [InternshipController::class, 'all_student'])->name("api.internships.student");
|
Route::get("/my", [InternshipController::class, 'all_student'])->name("api.internships.student");
|
||||||
|
|
||||||
Route::middleware("auth:sanctum")->group(function () {
|
Route::middleware("auth:sanctum")->group(function () {
|
||||||
|
Route::get("/{id}", [InternshipController::class, 'get'])->name("api.internships.get");
|
||||||
Route::put("/new", [InternshipController::class, 'store'])->name("api.internships.create");
|
Route::put("/new", [InternshipController::class, 'store'])->name("api.internships.create");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user