This commit is contained in:
Doar Mihai
2026-04-03 01:04:19 +03:00
parent 2b930a0636
commit 1cbe5bfe3b
12 changed files with 536 additions and 2 deletions
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class JobCategoryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'icon' => $this->icon,
'jobs_count' => $this->when(isset($this->jobs_count), $this->jobs_count),
];
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class JobCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @return array<int|string, mixed>
*/
public function toArray(Request $request): array
{
return [
'data' => $this->collection,
'meta' => [
'total' => $this->total(),
'current_page' => $this->currentPage(),
'last_page' => $this->lastPage(),
'per_page' => $this->perPage(),
'from' => $this->firstItem(),
'to' => $this->lastItem(),
],
'links' => [
'first' => $this->url(1),
'last' => $this->url($this->lastPage()),
'prev' => $this->previousPageUrl(),
'next' => $this->nextPageUrl(),
],
];
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class JobLocationResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'city' => $this->city,
'state' => $this->state,
'country' => $this->country,
'country_code' => $this->country_code,
'formatted' => $this->formatted(),
];
}
/**
* Format location as a readable string
*/
private function formatted(): string
{
$parts = array_filter([
$this->city,
$this->state,
$this->country,
]);
return implode(', ', $parts);
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class JobResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'external_id' => $this->external_id,
'title' => $this->title,
'company' => $this->company,
'description' => $this->description,
'location' => $this->location,
'salary' => [
'min' => $this->salary_min,
'max' => $this->salary_max,
'currency' => $this->salary_currency,
'formatted' => $this->formatSalary(),
],
'job_type' => $this->job_type,
'remote_allowed' => $this->remote_allowed,
'experience_level' => $this->experience_level,
'source' => new JobSourceResource($this->whenLoaded('source')),
'category' => new JobCategoryResource($this->whenLoaded('category')),
'job_location' => new JobLocationResource($this->whenLoaded('jobLocation')),
'urls' => [
'source' => $this->source_url,
'apply' => $this->apply_url,
],
'dates' => [
'posted_at' => $this->posted_at?->toIso8601String(),
'expires_at' => $this->expires_at?->toIso8601String(),
'created_at' => $this->created_at->toIso8601String(),
'updated_at' => $this->updated_at->toIso8601String(),
],
];
}
/**
* Format salary range for display
*/
private function formatSalary(): ?string
{
if (!$this->salary_min && !$this->salary_max) {
return null;
}
$currency = $this->salary_currency ?? 'USD';
$symbol = $currency === 'USD' ? '$' : $currency . ' ';
if ($this->salary_min && $this->salary_max) {
return $symbol . number_format($this->salary_min, 0) . ' - ' . $symbol . number_format($this->salary_max, 0);
}
if ($this->salary_min) {
return $symbol . number_format($this->salary_min, 0) . '+';
}
return 'Up to ' . $symbol . number_format($this->salary_max, 0);
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class JobSourceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'api_type' => $this->api_type,
'website_url' => $this->website_url,
'is_active' => $this->is_active,
];
}
}