Skip to content

Commit

Permalink
Tweaks (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio authored Sep 27, 2024
1 parent 1b1a77d commit 74a0ff4
Show file tree
Hide file tree
Showing 32 changed files with 345 additions and 158 deletions.
8 changes: 7 additions & 1 deletion app/DataTransferObjects/MapCoordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use MatanYadaev\EloquentSpatial\Objects\LineString;
use MatanYadaev\EloquentSpatial\Objects\Point;
use MatanYadaev\EloquentSpatial\Objects\Polygon;
use Stringable;

class MapCoordinates
class MapCoordinates implements Stringable
{
public float $latitude = 44.4327;

Expand Down Expand Up @@ -131,4 +132,9 @@ public function getZoom(): int
{
return $this->zoom;
}

public function __toString(): string
{
return \sprintf('@%s,%s,%sz', $this->latitude, $this->longitude, $this->zoom);
}
}
16 changes: 8 additions & 8 deletions app/Http/Controllers/MapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Inertia\Inertia;
use Inertia\LazyProp;
use Inertia\Response;
use Laravel\Scout\Builder as ScoutBuilder;

class MapController extends Controller
{
Expand All @@ -46,6 +47,9 @@ public function index(Request $request, MapCoordinates $coordinates): Response

public function point(Point $point, MapCoordinates $coordinates): Response
{
seo()
->title($point->pointType->name);

return $this->render($coordinates, [
'context' => 'point',
'report' => false,
Expand All @@ -69,14 +73,6 @@ public function report(Point $point, MapCoordinates $coordinates): Response
]);
}

public function material(Material $material, MapCoordinates $coordinates): Response
{
return $this->render($coordinates, [
'context' => 'material',
'material' => $material,
]);
}

public function suggest(Request $request, MapCoordinates $coordinates): JsonResource
{
$attributes = $request->validate([
Expand Down Expand Up @@ -139,6 +135,7 @@ public function search(Request $request, MapCoordinates $coordinates): Response
{
$attributes = $request->validate([
'query' => ['required', 'string'],
'material' => ['nullable', 'integer'],
]);

return $this->render($coordinates, [
Expand All @@ -149,8 +146,11 @@ public function search(Request $request, MapCoordinates $coordinates): Response
return [];
}

$material = data_get($attributes, 'material');

return SearchResultResource::collection(
Point::search($attributes['query'])
->when($material, fn (ScoutBuilder $query) => $query->where('material_ids', $material))
->take(100)
->query(
fn (Builder $query) => $query
Expand Down
20 changes: 12 additions & 8 deletions app/Http/Resources/SuggestionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,38 @@ class SuggestionResource extends JsonResource
public function toArray(Request $request): array
{
return match (\get_class($this->resource)) {
Point::class => $this->getPointArray(),
Material::class => $this->getMaterialArray(),
Location::class => $this->getLocationArray(),
Point::class => $this->getPointArray($request),
Material::class => $this->getMaterialArray($request),
Location::class => $this->getLocationArray($request),
};
}

protected function getPointArray(): array
protected function getPointArray(Request $request): array
{
return [
'name' => $this->business_name ?? $this->pointType->name,
'description' => $this->address,
'url' => route('front.map.point', $this),
'type' => 'point',
'icon' => $this->serviceType->slug,
'url' => $this->url,
];
}

protected function getMaterialArray(): array
protected function getMaterialArray(Request $request): array
{
return [
'name' => $this->name,
'url' => route('front.map.material', $this),
'type' => 'material',
'icon' => $this->icon,
'url' => route('front.map.search', [
'coordinates' => $request->coordinates,
'query' => $this->name,
'material' => $this->id,
]),
];
}

protected function getLocationArray(): array
protected function getLocationArray(Request $request): array
{
return [
'name' => $this->name,
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ public function toSearchableArray(): array
'point_type_id' => (string) $this->pointType->id,
'address' => $this->address,
'point_type' => $this->pointType->name,

'material_ids' => $this->materials
->pluck('id')
->map(fn ($id) => (string) $id),

'materials' => $this->materials
->pluck('name'),

Expand Down Expand Up @@ -251,6 +256,10 @@ public static function getTypesenseModelSettings(): array
'name' => 'address',
'type' => 'string',
],
[
'name' => 'material_ids',
'type' => 'string[]',
],
[
'name' => 'materials',
'type' => 'string[]',
Expand Down
35 changes: 16 additions & 19 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace App\Providers;

use App\Services\Filter;
use Filament\Facades\Filament;
use Filament\Navigation\NavigationGroup;
use Filament\Notifications\Livewire\DatabaseNotifications;
use Filament\Support\Assets\Css;
use Filament\Support\Assets\Js;
Expand All @@ -32,23 +30,7 @@ public function boot(): void

Number::useLocale(app()->getLocale());

Filament::serving(function () {
Filament::registerNavigationGroups([
NavigationGroup::make()
->label('Settings')
// ->icon('heroicon-s-cog')
->collapsed(),
]);

Filament::registerNavigationItems([
]);
});

Filament::registerNavigationGroups([
'Harta' => NavigationGroup::make()->label(__('nav.harta')),
'Rapoarte' => NavigationGroup::make()->label(__('nav.reports')),
'Settings' => NavigationGroup::make()->label(__('nav.settings')),
]);
$this->setSeoDefaults();
}

/**
Expand Down Expand Up @@ -99,6 +81,21 @@ protected function enforceMorphMap(): void
]);
}

protected function setSeoDefaults(): void
{
seo()
->withUrl()
->title(
default: config('app.name'),
modifier: fn (string $title) => $title . '' . config('app.name')
)
// TODO: Add a default description
// ->description(default: '')
->locale(app()->getLocale())
->favicon()
->twitter();
}

protected function registerStrMacros(): void
{
Str::macro('initials', fn (?string $value) => collect(explode(' ', (string) $value))
Expand Down
46 changes: 40 additions & 6 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,47 @@ public function boot(): void

protected function configureRateLimiting(): void
{
RateLimiter::for('register', function (Request $request) {
return Limit::perMinute(config('throttle.register_limit'))->by($request->ip());
});
RateLimiter::for(
'register',
fn (Request $request) => Limit::perMinute(config('throttle.register'))
->by($request->ip())
);

RateLimiter::for('login', function (Request $request) {
return Limit::perMinute(config('throttle.login_limit'))->by($request->ip());
});
RateLimiter::for(
'login',
fn (Request $request) => Limit::perMinute(config('throttle.login'))
->by($request->ip())
);

RateLimiter::for(
'forgot-password',
fn (Request $request) => Limit::perMinute(config('throttle.forgot-password'))
->by($request->ip())
);

RateLimiter::for(
'reset-password',
fn (Request $request) => Limit::perMinute(config('throttle.reset-password'))
->by($request->ip())
);

RateLimiter::for(
'submit',
fn (Request $request) => Limit::perMinute(config('throttle.submit'))
->by($request->user()?->id ?: $request->ip())
);

RateLimiter::for(
'media',
fn (Request $request) => Limit::perMinute(config('throttle.media'))
->by($request->user()?->id ?: $request->ip())
);

RateLimiter::for(
'map',
fn (Request $request) => Limit::perMinute(config('throttle.map'))
->by($request->user()?->id ?: $request->ip())
);
}

public static function getDashboardUrl(): string
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function getValue(mixed $value): mixed
return Str::of($value)
->explode(',')
->map(fn ($v) => self::getValue($v))
->all();;
->all();
}

if ($value === 'true') {
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"require": {
"php": "^8.2",
"archtechx/laravel-seo": "^0.10.1",
"dotswan/filament-map-picker": "^1.2",
"filament/filament": "^3.2",
"filament/forms": "^3.2",
Expand Down
60 changes: 59 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions config/throttle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@

return [

'register_limit' => (int) env('THROTTLE_REGISTER_PER_MINUTE', 10),
'login_limit' => (int) env('THROTTLE_LOGINS_PER_MINUTE', 5),
'donation_limit' => (int) env('THROTTLE_DONATIONS_PER_MINUTE', 5),
'volunteer_limit' => (int) env('THROTTLE_VOLUNTEERS_PER_MINUTE', 5),
// Number of registration attempts allowed per minute
'register' => (int) env('THROTTLE_REGISTER_PER_MINUTE', 10),

// Number of login attempts allowed per minute
'login' => (int) env('THROTTLE_LOGIN_PER_MINUTE', 5),

// Number of forgot-password attempts allowed per minute
'forgot-password' => (int) env('THROTTLE_FORGOT_PASSWORD_PER_MINUTE', 5),

// Number of reset-password attempts allowed per minute
'reset-password' => (int) env('THROTTLE_RESET_PASSWORD_PER_MINUTE', 10),

// Number of map interactions allowed per minute
'map' => (int) env('THROTTLE_MAP_PER_MINUTE', 120),

// Number of new point or report attempts allowed per minute
'submit' => (int) env('THROTTLE_SUBMIT_PER_MINUTE', 30),

// Number of media uploads or deletions allowed per minute
'media' => (int) env('THROTTLE_MEDIA_PER_MINUTE', 30),

];
1 change: 1 addition & 0 deletions lang/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"sidebar.clear_filters_label": "Șterge filtre",
"sidebar.search": "Caută",
"sidebar.results": "{0} 0 rezultate|{1} 1 rezultat|[2,19] :count rezultate|[20,*] de rezultate",
"sidebar.search_term": "Căutare după \":query\"",
"sidebar.no_results_found": "Nu am găsit niciun rezultat pentru \":query\". în zona de căutare. Folosiți un alt termen de căutare sau extindeți zona prin zoom out pe hartă.",
"sidebar.see_all_points": "Vezi toate punctele",

Expand Down
2 changes: 1 addition & 1 deletion public/robots.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
User-agent: *
Disallow:
Disallow: /admin
Loading

0 comments on commit 74a0ff4

Please sign in to comment.