Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
53
app/Http/Resources/PublicApi/PublicCallResource.php
Normal file
53
app/Http/Resources/PublicApi/PublicCallResource.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Call;
|
||||
use App\Support\SiteUrls;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Call
|
||||
*/
|
||||
class PublicCallResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'locale' => $locale,
|
||||
|
||||
...TranslatablePayload::resolve(
|
||||
$this->resource,
|
||||
['title', 'slug', 'description', 'what_you_get'],
|
||||
$locale,
|
||||
),
|
||||
|
||||
'status' => $this->status->value,
|
||||
|
||||
// The numbers that let someone decide in ten seconds. Time is the
|
||||
// scarce resource here, not money.
|
||||
'hours_per_week' => $this->hours_per_week,
|
||||
'duration_weeks' => $this->duration_weeks,
|
||||
'total_hours' => $this->totalHours(),
|
||||
'seniority' => $this->seniority,
|
||||
|
||||
'closes_at' => $this->closes_at?->toDateString(),
|
||||
|
||||
'project' => PublicProjectResource::make($this->whenLoaded('project')),
|
||||
'technologies' => PublicTechnologyResource::collection($this->whenLoaded('technologies')),
|
||||
|
||||
'alternates' => SiteUrls::alternates($this->resource, 'call'),
|
||||
'path' => SiteUrls::alternates($this->resource, 'call')[$locale] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Resources/PublicApi/PublicCategoryResource.php
Normal file
30
app/Http/Resources/PublicApi/PublicCategoryResource.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Category
|
||||
*/
|
||||
class PublicCategoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
...TranslatablePayload::resolve($this->resource, $this->translatable, app()->getLocale()),
|
||||
'color' => $this->color,
|
||||
'position' => $this->position,
|
||||
'pages_count' => $this->whenCounted('pages'),
|
||||
];
|
||||
}
|
||||
}
|
||||
43
app/Http/Resources/PublicApi/PublicClientResource.php
Normal file
43
app/Http/Resources/PublicApi/PublicClientResource.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Support\ImagePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Client
|
||||
*/
|
||||
class PublicClientResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'sector' => $this->getTranslation('sector', $locale, false) ?: null,
|
||||
'url' => $this->url,
|
||||
|
||||
// The logo's alt text is the organisation's name, so there is
|
||||
// nothing to type and nothing to get wrong.
|
||||
'logo' => ImagePayload::make(
|
||||
$this->logo,
|
||||
$this->resource->relationLoaded('logoMedia') ? $this->resource->getRelation('logoMedia') : null,
|
||||
$this->name,
|
||||
),
|
||||
|
||||
'projects_count' => $this->whenCounted('projects'),
|
||||
'projects' => PublicProjectResource::collection($this->whenLoaded('projects')),
|
||||
];
|
||||
}
|
||||
}
|
||||
50
app/Http/Resources/PublicApi/PublicIssueResource.php
Normal file
50
app/Http/Resources/PublicApi/PublicIssueResource.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\RepositoryIssue;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin RepositoryIssue
|
||||
*
|
||||
* An open door for someone who has never contributed before.
|
||||
*/
|
||||
class PublicIssueResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'number' => $this->number,
|
||||
'title' => $this->title,
|
||||
'url' => $this->html_url,
|
||||
'labels' => $this->labels ?? [],
|
||||
'is_good_first_issue' => $this->is_good_first_issue,
|
||||
'is_help_wanted' => $this->is_help_wanted,
|
||||
|
||||
// An issue someone has already claimed is not an invitation.
|
||||
'is_available' => $this->isUnclaimed(),
|
||||
|
||||
'comments' => $this->comments,
|
||||
'created_at' => $this->issue_created_at?->toIso8601String(),
|
||||
|
||||
'repository' => $this->whenLoaded('repository', fn () => [
|
||||
'full_name' => $this->repository->full_name,
|
||||
'url' => $this->repository->html_url,
|
||||
'primary_language' => $this->repository->primary_language,
|
||||
'project' => $this->repository->relationLoaded('project') && $this->repository->project
|
||||
? [
|
||||
'title' => $this->repository->project->getTranslation('title', app()->getLocale()),
|
||||
'slug' => $this->repository->project->getTranslation('slug', app()->getLocale()),
|
||||
]
|
||||
: null,
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
78
app/Http/Resources/PublicApi/PublicMemberResource.php
Normal file
78
app/Http/Resources/PublicApi/PublicMemberResource.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Member;
|
||||
use App\Support\ImagePayload;
|
||||
use App\Support\SiteUrls;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Member
|
||||
*
|
||||
* A member's profile is the real currency a volunteer collective pays people
|
||||
* in, so it carries everything needed to render a proper personal page rather
|
||||
* than a bare avatar and name.
|
||||
*/
|
||||
class PublicMemberResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
|
||||
...TranslatablePayload::resolve($this->resource, ['headline', 'bio'], $locale),
|
||||
|
||||
// A portrait's description is the person's name, so there is no
|
||||
// field to fill in and no way to get it wrong.
|
||||
'avatar' => ImagePayload::make(
|
||||
$this->avatar,
|
||||
$this->resource->relationLoaded('avatarMedia') ? $this->resource->getRelation('avatarMedia') : null,
|
||||
$this->avatarAlt(),
|
||||
),
|
||||
'github_username' => $this->github_username,
|
||||
'links' => (object) ($this->links ?? []),
|
||||
'is_founder' => $this->is_founder,
|
||||
|
||||
// Former members stay on the site with their history intact; the
|
||||
// frontend decides how to present them.
|
||||
'is_current' => $this->left_at === null,
|
||||
'joined_at' => $this->joined_at?->toDateString(),
|
||||
'left_at' => $this->left_at?->toDateString(),
|
||||
|
||||
'role' => $this->whenPivotLoaded('member_project', fn () => $this->pivot->role),
|
||||
|
||||
'technologies' => PublicTechnologyResource::collection($this->whenLoaded('technologies')),
|
||||
'projects' => PublicProjectResource::collection($this->whenLoaded('projects')),
|
||||
|
||||
'alternates' => $this->memberAlternates(),
|
||||
'path' => SiteUrls::path('member', $locale, $this->slug),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* A member's slug is a single string rather than a translated map, so the
|
||||
* same slug is valid in every locale — only the path prefix changes.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function memberAlternates(): array
|
||||
{
|
||||
return collect(array_keys(config('locales.supported')))
|
||||
->mapWithKeys(fn (string $locale) => [
|
||||
$locale => SiteUrls::path('member', $locale, $this->slug),
|
||||
])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
67
app/Http/Resources/PublicApi/PublicPageResource.php
Normal file
67
app/Http/Resources/PublicApi/PublicPageResource.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Page;
|
||||
use App\Support\ImagePayload;
|
||||
use App\Support\SiteUrls;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Page
|
||||
*/
|
||||
class PublicPageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'locale' => $locale,
|
||||
|
||||
/*
|
||||
* An explicit list rather than the model's whole translatable
|
||||
* set. `featured_image_alt` is in that set, and resolving it here
|
||||
* put the alt text at the top level as well as inside
|
||||
* `featured_image`, where the specification says it lives and
|
||||
* where an <img> needs it. Two names for one string is how a
|
||||
* frontend ends up reading the one that later turns out to be the
|
||||
* accidental one.
|
||||
*/
|
||||
...TranslatablePayload::resolve(
|
||||
$this->resource,
|
||||
['title', 'slug', 'excerpt', 'body', 'meta_title', 'meta_description'],
|
||||
$locale,
|
||||
),
|
||||
|
||||
'status' => $this->status->value,
|
||||
'is_featured' => $this->is_featured,
|
||||
'featured_image' => ImagePayload::make(
|
||||
$this->featured_image,
|
||||
$this->resource->relationLoaded('featuredMedia') ? $this->resource->getRelation('featuredMedia') : null,
|
||||
$this->getTranslation('featured_image_alt', $locale, false) ?: null,
|
||||
),
|
||||
'published_at' => $this->published_at?->toIso8601String(),
|
||||
|
||||
// So a cache downstream can expire when the content does, rather
|
||||
// than holding a notice that is no longer true.
|
||||
'unpublish_at' => $this->unpublish_at?->toIso8601String(),
|
||||
'updated_at' => $this->updated_at?->toIso8601String(),
|
||||
|
||||
'category' => PublicCategoryResource::make($this->whenLoaded('category')),
|
||||
|
||||
// Lets the frontend emit correct hreflang tags. Only locales that
|
||||
// actually have a translation appear.
|
||||
'alternates' => SiteUrls::alternates($this->resource, 'page'),
|
||||
'path' => SiteUrls::alternates($this->resource, 'page')[$locale] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
141
app/Http/Resources/PublicApi/PublicProjectResource.php
Normal file
141
app/Http/Resources/PublicApi/PublicProjectResource.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Media;
|
||||
use App\Models\Project;
|
||||
use App\Support\ImagePayload;
|
||||
use App\Support\SiteUrls;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Project
|
||||
*/
|
||||
class PublicProjectResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Whether to include the long-form fields. Listings stay light; the detail
|
||||
* endpoint opts in.
|
||||
*/
|
||||
protected bool $detailed = false;
|
||||
|
||||
public function detailed(bool $detailed = true): static
|
||||
{
|
||||
$this->detailed = $detailed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
$summary = TranslatablePayload::resolve($this->resource, ['title', 'slug', 'tagline'], $locale);
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'locale' => $locale,
|
||||
|
||||
...$summary,
|
||||
|
||||
'status' => $this->status->value,
|
||||
'is_featured' => $this->is_featured,
|
||||
|
||||
// True when flagged directly, or when the project carries an open
|
||||
// call. Read from a count rather than the relation so a listing
|
||||
// does not trigger a query per project.
|
||||
'needs_help' => $this->needs_help || $this->openCallCount() > 0,
|
||||
// A full image object rather than a path: the frontend needs
|
||||
// width and height to reserve the box, a srcset so a phone does
|
||||
// not download the original, and the alt text to be accessible.
|
||||
'cover_image' => ImagePayload::make(
|
||||
$this->cover_image,
|
||||
$this->loadedMedia('coverMedia'),
|
||||
$this->getTranslation('cover_image_alt', $locale, false) ?: null,
|
||||
),
|
||||
'demo_url' => $this->demo_url,
|
||||
|
||||
// Who the work is for. Central to a non-profit collective's story
|
||||
// in a way it never is for a commercial portfolio — and now a
|
||||
// record of its own, so the same organisation is the same thing on
|
||||
// every project it appears in.
|
||||
'client' => PublicClientResource::make($this->whenLoaded('client')),
|
||||
|
||||
'started_at' => $this->started_at?->toDateString(),
|
||||
'ended_at' => $this->ended_at?->toDateString(),
|
||||
'published_at' => $this->published_at?->toIso8601String(),
|
||||
'unpublish_at' => $this->unpublish_at?->toIso8601String(),
|
||||
'updated_at' => $this->updated_at?->toIso8601String(),
|
||||
|
||||
// The long form: the decisions and the postmortem are the content
|
||||
// other developers actually read, so they are never truncated.
|
||||
$this->mergeWhen($this->detailed, fn () => TranslatablePayload::resolve(
|
||||
$this->resource,
|
||||
['description', 'decisions', 'postmortem', 'meta_title', 'meta_description'],
|
||||
$locale,
|
||||
)),
|
||||
|
||||
// Only on the detail endpoint: a listing showing twenty projects
|
||||
// has no use for every screenshot of each one.
|
||||
'gallery' => $this->when(
|
||||
$this->detailed && $this->resource->relationLoaded('images'),
|
||||
fn () => $this->images->map(fn ($image) => [
|
||||
...ImagePayload::make(
|
||||
$image->path,
|
||||
$image->relationLoaded('media') ? $image->media : null,
|
||||
$image->getTranslation('alt', $locale, false) ?: null,
|
||||
),
|
||||
|
||||
// Shown to everyone, unlike the alt text.
|
||||
'caption' => $image->getTranslation('caption', $locale, false) ?: null,
|
||||
])->all(),
|
||||
),
|
||||
|
||||
'technologies' => PublicTechnologyResource::collection($this->whenLoaded('technologies')),
|
||||
'services' => PublicServiceResource::collection($this->whenLoaded('services')),
|
||||
'testimonials' => PublicTestimonialResource::collection($this->whenLoaded('testimonials')),
|
||||
'talks' => PublicTalkResource::collection($this->whenLoaded('talks')),
|
||||
'members' => PublicMemberResource::collection($this->whenLoaded('members')),
|
||||
'lead' => PublicMemberResource::make($this->whenLoaded('lead')),
|
||||
'calls' => PublicCallResource::collection($this->whenLoaded('calls')),
|
||||
|
||||
// Live repository activity — the part that keeps the site looking
|
||||
// alive without anyone maintaining it.
|
||||
'repositories' => PublicRepositoryResource::collection($this->whenLoaded('repositories')),
|
||||
|
||||
'alternates' => SiteUrls::alternates($this->resource, 'project'),
|
||||
'path' => SiteUrls::alternates($this->resource, 'project')[$locale] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The media row when the caller loaded it, and null otherwise — never a
|
||||
* lazy load, because this runs once per row in a listing.
|
||||
*/
|
||||
protected function loadedMedia(string $relation): ?Media
|
||||
{
|
||||
return $this->resource->relationLoaded($relation)
|
||||
? $this->resource->getRelation($relation)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open calls attached to this project, from whichever source the caller
|
||||
* already loaded — never by lazy-loading the relation.
|
||||
*/
|
||||
protected function openCallCount(): int
|
||||
{
|
||||
if ($this->resource->relationLoaded('calls')) {
|
||||
return $this->calls->count();
|
||||
}
|
||||
|
||||
return (int) ($this->resource->open_calls_count ?? 0);
|
||||
}
|
||||
}
|
||||
49
app/Http/Resources/PublicApi/PublicRepositoryResource.php
Normal file
49
app/Http/Resources/PublicApi/PublicRepositoryResource.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Repository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Repository
|
||||
*/
|
||||
class PublicRepositoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'provider' => $this->provider->value,
|
||||
'full_name' => $this->full_name,
|
||||
'url' => $this->html_url,
|
||||
'description' => $this->description,
|
||||
'primary_language' => $this->primary_language,
|
||||
'languages' => (object) ($this->languages ?? []),
|
||||
'topics' => $this->topics ?? [],
|
||||
'license' => $this->license,
|
||||
|
||||
'stars' => $this->stars,
|
||||
'forks' => $this->forks,
|
||||
'contributors_count' => $this->contributors_count,
|
||||
'open_issues_count' => $this->open_issues_count,
|
||||
|
||||
'is_archived' => $this->is_archived,
|
||||
|
||||
// Lets the frontend avoid presenting dead work as live.
|
||||
'is_dormant' => $this->isDormant(),
|
||||
|
||||
'pushed_at' => $this->pushed_at?->toIso8601String(),
|
||||
'synced_at' => $this->last_synced_at?->toIso8601String(),
|
||||
|
||||
'good_first_issues' => PublicIssueResource::collection($this->whenLoaded('goodFirstIssues')),
|
||||
'issues' => PublicIssueResource::collection($this->whenLoaded('issues')),
|
||||
];
|
||||
}
|
||||
}
|
||||
62
app/Http/Resources/PublicApi/PublicServiceResource.php
Normal file
62
app/Http/Resources/PublicApi/PublicServiceResource.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Service;
|
||||
use App\Support\SiteUrls;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Service
|
||||
*/
|
||||
class PublicServiceResource extends JsonResource
|
||||
{
|
||||
protected bool $detailed = false;
|
||||
|
||||
public function detailed(bool $detailed = true): static
|
||||
{
|
||||
$this->detailed = $detailed;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'locale' => $locale,
|
||||
|
||||
...TranslatablePayload::resolve($this->resource, ['title', 'slug', 'tagline'], $locale),
|
||||
|
||||
'icon' => $this->icon,
|
||||
'is_featured' => $this->is_featured,
|
||||
'position' => $this->position,
|
||||
'updated_at' => $this->updated_at?->toIso8601String(),
|
||||
|
||||
$this->mergeWhen($this->detailed, fn () => TranslatablePayload::resolve(
|
||||
$this->resource,
|
||||
['description', 'meta_title', 'meta_description'],
|
||||
$locale,
|
||||
)),
|
||||
|
||||
// The work that backs the offer. Without it a service is a
|
||||
// promise, which is why it travels with it rather than being
|
||||
// something the frontend has to go and ask for.
|
||||
'projects' => PublicProjectResource::collection($this->whenLoaded('projects')),
|
||||
'technologies' => PublicTechnologyResource::collection($this->whenLoaded('technologies')),
|
||||
'testimonials' => PublicTestimonialResource::collection($this->whenLoaded('testimonials')),
|
||||
|
||||
'alternates' => SiteUrls::alternates($this->resource, 'service'),
|
||||
'path' => SiteUrls::alternates($this->resource, 'service')[$locale] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
43
app/Http/Resources/PublicApi/PublicTalkResource.php
Normal file
43
app/Http/Resources/PublicApi/PublicTalkResource.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Talk;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Talk
|
||||
*/
|
||||
class PublicTalkResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
|
||||
// Not translated: it is the name of a talk that was given once, in
|
||||
// one language. `language` says which.
|
||||
'title' => $this->title,
|
||||
'language' => $this->language,
|
||||
|
||||
'summary' => $this->getTranslation('summary', $locale, false) ?: null,
|
||||
|
||||
'event' => $this->event,
|
||||
'city' => $this->city,
|
||||
'held_at' => $this->held_at?->toDateString(),
|
||||
|
||||
'video_url' => $this->video_url,
|
||||
'slides_url' => $this->slides_url,
|
||||
|
||||
'speaker' => PublicMemberResource::make($this->whenLoaded('member')),
|
||||
];
|
||||
}
|
||||
}
|
||||
50
app/Http/Resources/PublicApi/PublicTechnologyResource.php
Normal file
50
app/Http/Resources/PublicApi/PublicTechnologyResource.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Technology;
|
||||
use App\Support\ImagePayload;
|
||||
use App\Support\TranslatablePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Technology
|
||||
*/
|
||||
class PublicTechnologyResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
// Not translated: technology names are proper nouns.
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'category' => $this->category?->value,
|
||||
'color' => $this->color,
|
||||
'icon' => $this->icon,
|
||||
|
||||
// The alt text of a logo is the name of the thing, so there is
|
||||
// nothing to type and nothing to get wrong.
|
||||
'logo' => ImagePayload::make(
|
||||
$this->logo,
|
||||
$this->resource->relationLoaded('logoMedia') ? $this->resource->getRelation('logoMedia') : null,
|
||||
$this->name,
|
||||
),
|
||||
'website' => $this->website,
|
||||
|
||||
// Tech radar. `ring` is null for technologies used but not placed.
|
||||
'ring' => $this->radar_ring?->value,
|
||||
|
||||
...TranslatablePayload::resolve($this->resource, ['description', 'radar_note'], app()->getLocale()),
|
||||
|
||||
'projects_count' => $this->whenCounted('projects'),
|
||||
'members_count' => $this->whenCounted('members'),
|
||||
];
|
||||
}
|
||||
}
|
||||
52
app/Http/Resources/PublicApi/PublicTestimonialResource.php
Normal file
52
app/Http/Resources/PublicApi/PublicTestimonialResource.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources\PublicApi;
|
||||
|
||||
use App\Models\Testimonial;
|
||||
use App\Support\ImagePayload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Testimonial
|
||||
*/
|
||||
class PublicTestimonialResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'quote' => $this->getTranslation('quote', $locale),
|
||||
|
||||
/*
|
||||
* Whether these are the words that were actually said. A quote
|
||||
* shown in a language it was not given in has been translated by
|
||||
* us, and the frontend can say so — "translated from Spanish" —
|
||||
* instead of pretending somebody phrased it that way.
|
||||
*/
|
||||
'original_locale' => $this->original_locale,
|
||||
'is_original' => $this->isOriginal($locale),
|
||||
|
||||
'author' => [
|
||||
'name' => $this->author_name,
|
||||
'role' => $this->getTranslation('author_role', $locale, false) ?: null,
|
||||
'avatar' => ImagePayload::make(
|
||||
$this->avatar,
|
||||
$this->resource->relationLoaded('avatarMedia') ? $this->resource->getRelation('avatarMedia') : null,
|
||||
$this->author_name,
|
||||
),
|
||||
],
|
||||
|
||||
'given_at' => $this->given_at?->toDateString(),
|
||||
|
||||
'client' => PublicClientResource::make($this->whenLoaded('client')),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user