From 363254d13c75b51c89b12449e6f18fe9cf8c2a4b Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sun, 17 Aug 2025 11:05:38 +0100 Subject: [PATCH] Some fixes related to developing my Micropub client --- app/Http/Requests/MicropubRequest.php | 17 +++++++- docker-compose.yml | 2 +- resources/views/admin/clients/index.blade.php | 2 +- resources/views/login.blade.php | 4 +- routes/web.php | 10 +++++ tests/Feature/MicropubControllerTest.php | 39 +++++++++++++++---- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/app/Http/Requests/MicropubRequest.php b/app/Http/Requests/MicropubRequest.php index d931f139..41c70280 100644 --- a/app/Http/Requests/MicropubRequest.php +++ b/app/Http/Requests/MicropubRequest.php @@ -51,7 +51,7 @@ class MicropubRequest extends FormRequest // Convert JSON type (h-entry) to simple type (entry) if (isset($data['type']) && is_array($data['type'])) { $type = current($data['type']); - if (strpos($type, 'h-') === 0) { + if (str_starts_with($type, 'h-')) { $this->micropubData['type'] = substr($type, 2); } } @@ -67,7 +67,7 @@ class MicropubRequest extends FormRequest $this->micropubData['content'] = Arr::get($data, 'properties.content.0'); $this->micropubData['in-reply-to'] = Arr::get($data, 'properties.in-reply-to.0'); $this->micropubData['published'] = Arr::get($data, 'properties.published.0'); - $this->micropubData['location'] = Arr::get($data, 'location'); + $this->micropubData['location'] = $this->getLocationData($data); $this->micropubData['bookmark-of'] = Arr::get($data, 'properties.bookmark-of.0'); $this->micropubData['like-of'] = Arr::get($data, 'properties.like-of.0'); $this->micropubData['mp-syndicate-to'] = Arr::get($data, 'properties.mp-syndicate-to'); @@ -103,4 +103,17 @@ class MicropubRequest extends FormRequest $this->micropubData[$key] = $value; } } + + private function getLocationData(array $data): array|string|null + { + if (! Arr::has($data, 'properties.location')) { + return null; + } + + if (Arr::has($data, 'properties.location.0')) { + return Arr::get($data, 'properties.location.0'); + } + + return Arr::get($data, 'properties.location'); + } } diff --git a/docker-compose.yml b/docker-compose.yml index cd9242e8..74f97af5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' - image: sail-8.3/app + image: sail-8.4/app extra_hosts: - 'host.docker.internal:host-gateway' ports: diff --git a/resources/views/admin/clients/index.blade.php b/resources/views/admin/clients/index.blade.php index df731b5c..a99937b5 100644 --- a/resources/views/admin/clients/index.blade.php +++ b/resources/views/admin/clients/index.blade.php @@ -13,6 +13,6 @@ @endforeach

- Create a new entry? + Create a new entry?

@stop diff --git a/resources/views/login.blade.php b/resources/views/login.blade.php index b80bd147..65da9813 100644 --- a/resources/views/login.blade.php +++ b/resources/views/login.blade.php @@ -3,8 +3,8 @@ @section('content')

Login

-
- + + @csrf diff --git a/routes/web.php b/routes/web.php index 86e5dc7e..95825352 100644 --- a/routes/web.php +++ b/routes/web.php @@ -137,6 +137,16 @@ Route::middleware(MyAuthMiddleware::class)->prefix('admin')->group(function () { Route::delete('/{syndicationTarget}', [SyndicationTargetsController::class, 'destroy']); }); + // Clients + Route::prefix('clients')->group(function () { + Route::get('/', [ClientsController::class, 'index']); + Route::get('/create', [ClientsController::class, 'create']); + Route::post('/', [ClientsController::class, 'store']); + Route::get('/{clientId}/edit', [ClientsController::class, 'edit']); + Route::put('/{clientId}', [ClientsController::class, 'update']); + Route::delete('/{clientId}', [ClientsController::class, 'destroy']); + }); + // Bio Route::prefix('bio')->group(function () { Route::get('/', [BioController::class, 'show'])->name('admin.bio.show'); diff --git a/tests/Feature/MicropubControllerTest.php b/tests/Feature/MicropubControllerTest.php index 9c095174..3d28f399 100644 --- a/tests/Feature/MicropubControllerTest.php +++ b/tests/Feature/MicropubControllerTest.php @@ -278,6 +278,31 @@ class MicropubControllerTest extends TestCase Queue::assertPushed(SyndicateNoteToBluesky::class); } + #[Test] + public function micropub_client_api_request_creates_new_note_with_geo_location(): void + { + $faker = Factory::create(); + $note = $faker->text; + $response = $this->postJson( + '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'content' => [$note], + 'location' => ['geo:1.23,4.56'], + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] + ); + $response + ->assertStatus(201) + ->assertJson(['response' => 'created']); + $this->assertDatabaseHas('notes', [ + 'note' => $note, + 'location' => '1.23, 4.56', + ]); + } + /** * Test a valid micropub requests using JSON syntax creates a new note with * existing self-created place. @@ -323,13 +348,13 @@ class MicropubControllerTest extends TestCase 'type' => ['h-entry'], 'properties' => [ 'content' => [$note], - ], - 'location' => [ - 'type' => ['h-card'], - 'properties' => [ - 'name' => ['Awesome Venue'], - 'latitude' => ['1.23'], - 'longitude' => ['4.56'], + 'location' => [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Awesome Venue'], + 'latitude' => ['1.23'], + 'longitude' => ['4.56'], + ], ], ], ],