Add check for geolocation

This commit is contained in:
Philipp Lang 2023-08-15 15:11:12 +02:00
parent 0e023a06ec
commit 925754bd26
4 changed files with 73 additions and 20 deletions

View File

@ -120,7 +120,7 @@ class Member extends Model implements Geolocatable
// ----------------------------------- Getters ----------------------------------- // ----------------------------------- Getters -----------------------------------
public function getFullnameAttribute(): string public function getFullnameAttribute(): string
{ {
return $this->firstname.' '.$this->lastname; return $this->firstname . ' ' . $this->lastname;
} }
public function getPreferredPhoneAttribute(): ?string public function getPreferredPhoneAttribute(): ?string
@ -151,12 +151,12 @@ class Member extends Model implements Geolocatable
public function getEtagAttribute(): string public function getEtagAttribute(): string
{ {
return $this->updated_at->timestamp.'_'.$this->version; return $this->updated_at->timestamp . '_' . $this->version;
} }
public function getFullAddressAttribute(): string public function getFullAddressAttribute(): string
{ {
return $this->address.', '.$this->zip.' '.$this->location; return $this->address . ', ' . $this->zip . ' ' . $this->location;
} }
public function getEfzLink(): ?string public function getEfzLink(): ?string
@ -412,7 +412,7 @@ class Member extends Model implements Geolocatable
$settings = app(NamiSettings::class); $settings = app(NamiSettings::class);
$card = Reader::read($data); $card = Reader::read($data);
[$lastname, $firstname] = $card->N->getParts(); [$lastname, $firstname] = $card->N->getParts();
[$deprecated1, $deprecated2 , $address, $location, $region, $zip, $country] = $card->ADR->getParts(); [$deprecated1, $deprecated2, $address, $location, $region, $zip, $country] = $card->ADR->getParts();
return new static([ return new static([
'joined_at' => now(), 'joined_at' => now(),
@ -482,8 +482,8 @@ class Member extends Model implements Geolocatable
return Sender::from([ return Sender::from([
'name' => $this->fullname, 'name' => $this->fullname,
'address' => $this->address, 'address' => $this->address,
'zipLocation' => $this->zip.' '.$this->location, 'zipLocation' => $this->zip . ' ' . $this->location,
'mglnr' => Lazy::create(fn () => 'Mglnr.: '.$this->nami_id), 'mglnr' => Lazy::create(fn () => 'Mglnr.: ' . $this->nami_id),
]); ]);
} }
@ -525,4 +525,11 @@ class Member extends Model implements Geolocatable
'lon' => null, 'lon' => null,
]); ]);
} }
public function needsGeolocationUpdate(): bool
{
return $this->getOriginal('address') !== $this->address
|| $this->getOriginal('zip') !== $this->zip
|| $this->getOriginal('location') !== $this->location;
}
} }

View File

@ -49,7 +49,7 @@
"spatie/laravel-settings": "^2.2", "spatie/laravel-settings": "^2.2",
"worksome/request-factories": "^2.5", "worksome/request-factories": "^2.5",
"zoomyboy/laravel-nami": "dev-master", "zoomyboy/laravel-nami": "dev-master",
"zoomyboy/osm": "^1.0", "zoomyboy/osm": "1.0.3",
"zoomyboy/phone": "^1.0", "zoomyboy/phone": "^1.0",
"zoomyboy/tex": "dev-main as 1.0" "zoomyboy/tex": "dev-main as 1.0"
}, },

19
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f2cf2548c5e063cf19556d09a5cf2af7", "content-hash": "62586d4169459f71189b880d8a86e1ec",
"packages": [ "packages": [
{ {
"name": "beyondcode/laravel-dump-server", "name": "beyondcode/laravel-dump-server",
@ -10642,11 +10642,11 @@
}, },
{ {
"name": "zoomyboy/osm", "name": "zoomyboy/osm",
"version": "1.0.1", "version": "1.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.zoomyboy.de/zoomyboy/osm.git", "url": "https://git.zoomyboy.de/zoomyboy/osm.git",
"reference": "255a7819f54b204c4da10f534a4bbb8b9fb3776c" "reference": "132d15f36885ba06f0ea2d1715f2e7e148f37df1"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -10662,7 +10662,7 @@
} }
], ],
"description": "OSM Helper", "description": "OSM Helper",
"time": "2023-05-16T14:19:14+00:00" "time": "2023-08-15T11:24:07+00:00"
}, },
{ {
"name": "zoomyboy/phone", "name": "zoomyboy/phone",
@ -10700,7 +10700,7 @@
"dist": { "dist": {
"type": "path", "type": "path",
"url": "./packages/tex", "url": "./packages/tex",
"reference": "6f162102ef7ceca41822d18c3e694abd926f550b" "reference": "48251272de62e3fea044a7ad31e1a411c15eb4c6"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@ -13463,14 +13463,7 @@
"time": "2023-05-30T22:51:52+00:00" "time": "2023-05-30T22:51:52+00:00"
} }
], ],
"aliases": [ "aliases": [],
{
"package": "zoomyboy/tex",
"version": "dev-main",
"alias": "1.0",
"alias_normalized": "1.0.0.0"
}
],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {
"zoomyboy/laravel-nami": 20, "zoomyboy/laravel-nami": 20,

View File

@ -0,0 +1,53 @@
<?php
namespace Tests\Feature\Member;
use App\Member\Member;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
use Zoomyboy\Osm\FillCoordsJob;
class GeolocationTest extends TestCase
{
public function testItFiresGeolocationJob(): void
{
Queue::fake();
Member::enableGeolocation();
$member = Member::factory()->defaults()->create();
Queue::assertPushed(FillCoordsJob::class, fn ($job) => $job->model->is($member));
}
public function testItDoesntFireJobWhenUpdateNotNeeded(): void
{
Queue::fake();
$member = Member::factory()->defaults()->create();
Member::enableGeolocation();
$member->update(['nickname' => 'test']);
Queue::assertNotPushed(FillCoordsJob::class);
}
public function testItFiresJobWhenAddressUpdateNeeded(): void
{
Queue::fake();
$member = Member::factory()->defaults()->create();
Member::enableGeolocation();
$member->update(['address' => 'abcdef']);
Queue::assertPushed(FillCoordsJob::class, fn ($job) => $job->model->address === 'abcdef');
}
public function testItFiresJobWhenZipUpdateNeeded(): void
{
Queue::fake();
$member = Member::factory()->defaults()->create();
Member::enableGeolocation();
$member->update(['zip' => '33445']);
Queue::assertPushed(FillCoordsJob::class, fn ($job) => $job->model->zip === '33445');
}
}