Implement tenant announcements and audit log fixes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Tenant;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Tenant\TenantAnnouncementResource;
|
||||
use App\Models\Tenant;
|
||||
use App\Services\TenantAnnouncements\TenantAnnouncementService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class TenantAnnouncementController extends Controller
|
||||
{
|
||||
public function index(
|
||||
Request $request,
|
||||
TenantAnnouncementService $service
|
||||
): AnonymousResourceCollection|JsonResponse {
|
||||
$tenant = $request->attributes->get('tenant');
|
||||
|
||||
if (! $tenant instanceof Tenant) {
|
||||
$decoded = $request->attributes->get('decoded_token', []);
|
||||
$tenantId = Arr::get($decoded, 'tenant_id');
|
||||
|
||||
if ($tenantId) {
|
||||
$tenant = Tenant::query()->find($tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $tenant instanceof Tenant) {
|
||||
return response()->json([
|
||||
'message' => 'Tenant context missing.',
|
||||
], 401);
|
||||
}
|
||||
|
||||
$announcements = $service->visibleAnnouncementsForTenant($tenant);
|
||||
|
||||
return TenantAnnouncementResource::collection($announcements);
|
||||
}
|
||||
}
|
||||
@@ -311,32 +311,18 @@ class MarketingController extends Controller
|
||||
public function blogIndex(Request $request, string $locale)
|
||||
{
|
||||
$locale = $locale ?: app()->getLocale();
|
||||
Log::info('Blog Index Debug - Initial', [
|
||||
'locale' => $locale,
|
||||
'full_url' => $request->fullUrl(),
|
||||
]);
|
||||
|
||||
$query = BlogPost::query()
|
||||
->with('author')
|
||||
->whereHas('category', function ($query) {
|
||||
$query->where('slug', 'blog');
|
||||
});
|
||||
|
||||
$totalWithCategory = $query->count();
|
||||
Log::info('Blog Index Debug - With Category', ['count' => $totalWithCategory]);
|
||||
|
||||
$query->where('is_published', true)
|
||||
->whereNotNull('published_at')
|
||||
->where('published_at', '<=', now());
|
||||
|
||||
$totalPublished = $query->count();
|
||||
Log::info('Blog Index Debug - Published', ['count' => $totalPublished]);
|
||||
|
||||
// Removed translation filter for now
|
||||
|
||||
$totalWithTranslation = $query->count();
|
||||
Log::info('Blog Index Debug - With Translation', ['count' => $totalWithTranslation, 'locale' => $locale]);
|
||||
|
||||
$posts = $query->orderBy('published_at', 'desc')
|
||||
->paginate(4)
|
||||
->through(function (BlogPost $post) use ($locale) {
|
||||
@@ -354,13 +340,6 @@ class MarketingController extends Controller
|
||||
];
|
||||
});
|
||||
|
||||
Log::info('Blog Index Debug - Final Posts', [
|
||||
'count' => $posts->count(),
|
||||
'total' => $posts->total(),
|
||||
'posts_data' => $posts->toArray(),
|
||||
'first_post_title' => $posts->count() > 0 ? ($posts->first()['title'] ?? 'No title') : 'No posts',
|
||||
]);
|
||||
|
||||
$postsArray = $posts->toArray();
|
||||
$postsArray['links'] = array_map(function (array $link) use ($locale) {
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user