Skip to content

Commit 4c209fe

Browse files
authored
Merge pull request #16 from codebar-ag/feature-feature
Feature About Us
2 parents ec4cdd5 + dd5967c commit 4c209fe

37 files changed

+1202
-549
lines changed

app/Actions/ViewDataAction.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace App\Actions;
44

5+
use App\DTO\ContactDTO;
6+
use App\Enums\ContactSectionEnum;
7+
use App\Models\Contact;
58
use App\Models\News;
69
use App\Models\Product;
710
use App\Models\Service;
@@ -37,4 +40,28 @@ public function news(string $locale): Collection
3740
return News::where('locale', $locale)->whereNotNull('published_at')->orderByDesc('published_at')->get();
3841
});
3942
}
43+
44+
public function contacts(string $locale): object
45+
{
46+
$key = Str::slug("contacts_published_{$locale}");
47+
48+
return Cache::rememberForever($key, function () use ($locale) {
49+
return (object) collect([
50+
ContactSectionEnum::EMPLOYEE_SERVICES,
51+
ContactSectionEnum::EMPLOYEE_PRODUCTS,
52+
ContactSectionEnum::EMPLOYEE_ADMINISTRATION,
53+
ContactSectionEnum::COLLABORATIONS,
54+
ContactSectionEnum::BOARD_MEMBERS,
55+
])->mapWithKeys(function (string $section) use ($locale) {
56+
$contacts = Contact::query()
57+
->where('published', true)
58+
->whereRaw("JSON_CONTAINS_PATH(sections, 'one', '$.\"$section\"')")
59+
->orderBy('name')
60+
->get()
61+
->map(fn ($contact) => ContactDTO::fromModel($contact, $section, $locale));
62+
63+
return [$section => $contacts];
64+
})->all();
65+
});
66+
}
4067
}

app/DTO/ContactDTO.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\DTO;
4+
5+
use App\Models\Contact;
6+
use Illuminate\Support\Arr;
7+
8+
class ContactDTO
9+
{
10+
public function __construct(
11+
public readonly string $locale,
12+
public readonly string $section,
13+
public readonly string $name,
14+
public readonly ?string $role,
15+
public readonly string $image,
16+
public readonly array $icons,
17+
) {}
18+
19+
public static function fromModel(Contact $contact, string $section, string $locale): self
20+
{
21+
$role = Arr::get($contact->sections, "$section.role.$locale");
22+
23+
return new self(
24+
name: $contact->name,
25+
role: $role,
26+
locale: $locale,
27+
image: $contact->image,
28+
icons: $contact->icons ?? [],
29+
section: $section,
30+
);
31+
}
32+
}

app/Enums/ContactSectionEnum.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum ContactSectionEnum: string
6+
{
7+
const string EMPLOYEE_SERVICES = 'employee_services';
8+
9+
const string EMPLOYEE_PRODUCTS = 'employee_products';
10+
11+
const string EMPLOYEE_ADMINISTRATION = 'employee_administration';
12+
13+
const string COLLABORATIONS = 'collaborations';
14+
15+
const string BOARD_MEMBERS = 'board_members';
16+
}

app/Http/Controllers/AboutUs/AboutUsIndexController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers\AboutUs;
44

55
use App\Actions\PageAction;
6+
use App\Actions\ViewDataAction;
67
use App\Http\Controllers\Controller;
78
use Illuminate\View\View;
89

@@ -13,8 +14,11 @@ class AboutUsIndexController extends Controller
1314
*/
1415
public function __invoke(): View
1516
{
17+
$locale = app()->getLocale();
18+
1619
return view('app.about-us.index')->with([
1720
'page' => (new PageAction(locale: null, routeName: 'about-us.index'))->default(),
21+
'contacts' => (new ViewDataAction)->contacts($locale),
1822
]);
1923
}
2024
}

app/Http/Controllers/Sitemap/SitemapController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SitemapController extends Controller
1919

2020
protected const array DEFAULT_ROUTES = [
2121
'start.index',
22+
'about-us.index',
2223
'products.index',
2324
'services.index',
2425
'contact.index',

app/Models/Contact.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Contact extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $casts = [
13+
'published' => 'boolean',
14+
'sections' => 'json',
15+
'icons' => 'json',
16+
];
17+
}

app/Models/Product.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Traits\HasLocalizedRouteBinding;
88
use Illuminate\Database\Eloquent\Factories\HasFactory;
99
use Illuminate\Database\Eloquent\Model;
10+
use Illuminate\Database\Eloquent\Relations\HasMany;
1011

1112
class Product extends Model
1213
{
@@ -24,4 +25,9 @@ public function getRouteKeyName(): string
2425
{
2526
return 'slug';
2627
}
28+
29+
public function productModules(): HasMany
30+
{
31+
return $this->hasMany(ProductModule::class);
32+
}
2733
}

app/Models/ProductModule.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Enums\LocaleEnum;
6+
use App\Traits\HasLocalizedReferences;
7+
use App\Traits\HasLocalizedRouteBinding;
8+
use Illuminate\Database\Eloquent\Factories\HasFactory;
9+
use Illuminate\Database\Eloquent\Model;
10+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
11+
12+
class ProductModule extends Model
13+
{
14+
use HasFactory;
15+
use HasLocalizedReferences;
16+
use HasLocalizedRouteBinding;
17+
18+
protected $casts = [
19+
'published' => 'boolean',
20+
'locale' => LocaleEnum::class,
21+
'tags' => 'json',
22+
];
23+
24+
public function getRouteKeyName(): string
25+
{
26+
return 'slug';
27+
}
28+
29+
public function product(): BelongsTo
30+
{
31+
return $this->belongsTo(Product::class);
32+
}
33+
}

app/Security/Presets/MyCspPreset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function configure(Policy $policy): void
4040
$policy->add(Directive::IMG, [
4141
Keyword::SELF,
4242
'data:',
43+
'res.cloudinary.com',
4344
]);
4445

4546
$policy->add(Directive::FONT, Keyword::SELF);

0 commit comments

Comments
 (0)