Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Commit 5f0743c

Browse files
Refactor FilamentData and UserProfileService: add UserFilamentNotFoundException, set default color, improve filament retrieval, and handle missing filaments gracefully.
1 parent 13e009b commit 5f0743c

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

app/Data/OrcaSlicer/FilamentData.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public function __construct(
1919
#[WithCast(ArrayToStringCast::class)]
2020
public string $externalId,
2121

22-
#[MapInputName('default_filament_colour')]
23-
#[WithCast(ArrayToStringCast::class)]
24-
public string $color,
25-
2622
public string $name,
2723

2824
public string $inherits,
2925

26+
#[MapInputName('default_filament_colour')]
27+
#[WithCast(ArrayToStringCast::class)]
28+
public string $color = '#000000',
29+
3030
#[WithCast(ArrayToFloatCast::class)]
3131
public float $pressureAdvance = 0,
3232

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Exceptions;
6+
7+
use OutOfRangeException;
8+
9+
class UserFilamentNotFoundException extends OutOfRangeException
10+
{
11+
public function __construct(string $vendor, string $filament)
12+
{
13+
parent::__construct("Vendor: [$vendor] Filament: [$filament]");
14+
}
15+
}

app/Services/OrcaSlicer/UserProfileService.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use App\Concerns\WithColor;
88
use App\Data\OrcaSlicer\FilamentData;
9+
use App\Exceptions\UserFilamentNotFoundException;
910
use App\Models\Filament;
1011
use App\Models\Machine;
1112
use App\Models\User;
@@ -24,8 +25,17 @@ public function import(User $user, Machine $machine, FilamentData $profile): voi
2425
{
2526
$vendor = $this->vendor($profile);
2627

27-
$filament = $this->filament($vendor, $profile->inherits ?: $profile->externalId);
28-
$color = $this->color($profile->color);
28+
$value = $profile->inherits ?: $profile->externalId;
29+
30+
$filament = $this->filament($vendor, $value);
31+
32+
if (! $filament) {
33+
report(new UserFilamentNotFoundException($vendor, $value));
34+
35+
return;
36+
}
37+
38+
$color = $this->color($profile->color);
2939

3040
$content = $this->filament->get($profile)->toArray();
3141

@@ -36,20 +46,20 @@ public function import(User $user, Machine $machine, FilamentData $profile): voi
3646
], $content);
3747
}
3848

39-
protected function filament(string $vendor, string $filament): Filament
49+
protected function filament(string $vendor, string $filament): ?Filament
4050
{
4151
$path = $vendor . '/filament/' . $filament . '.json';
4252

43-
$detected = $this->filamentType->detect($vendor, $filament, $path);
53+
$typeId = $this->filamentType->detect($filament, $path);
4454

4555
return Filament::query()
4656
->whereRelation('vendor', 'title', 'ilike', '%' . $vendor . '%')
47-
->whereRelation('type', 'title', $detected)
48-
->firstOrFail();
57+
->where('filament_type_id', $typeId)
58+
->first();
4959
}
5060

5161
protected function vendor(FilamentData $filament): string
5262
{
53-
return Str::of($filament->inherits ?: $filament->externalId)->before(' ')->trim()->toString();
63+
return Str::of($filament->externalId)->before(' ')->trim()->toString();
5464
}
5565
}

0 commit comments

Comments
 (0)