Fix publishing system

This commit is contained in:
myrmidex 2025-08-12 01:53:59 +02:00
parent 1b29c3fc13
commit 9d6e20b4f1

View file

@ -6,6 +6,7 @@
use App\Models\Article; use App\Models\Article;
use App\Models\Setting; use App\Models\Setting;
use App\Jobs\ArticleDiscoveryJob; use App\Jobs\ArticleDiscoveryJob;
use Exception;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
@ -47,12 +48,12 @@ public function approve(Article $article): JsonResponse
{ {
try { try {
$article->approve('manual'); $article->approve('manual');
return $this->sendResponse( return $this->sendResponse(
new ArticleResource($article->fresh(['feed', 'articlePublication'])), new ArticleResource($article->fresh(['feed', 'articlePublication'])),
'Article approved and queued for publishing.' 'Article approved and queued for publishing.'
); );
} catch (\Exception $e) { } catch (Exception $e) {
return $this->sendError('Failed to approve article: ' . $e->getMessage(), [], 500); return $this->sendError('Failed to approve article: ' . $e->getMessage(), [], 500);
} }
} }
@ -64,12 +65,12 @@ public function reject(Article $article): JsonResponse
{ {
try { try {
$article->reject('manual'); $article->reject('manual');
return $this->sendResponse( return $this->sendResponse(
new ArticleResource($article->fresh(['feed', 'articlePublication'])), new ArticleResource($article->fresh(['feed', 'articlePublication'])),
'Article rejected.' 'Article rejected.'
); );
} catch (\Exception $e) { } catch (Exception $e) {
return $this->sendError('Failed to reject article: ' . $e->getMessage(), [], 500); return $this->sendError('Failed to reject article: ' . $e->getMessage(), [], 500);
} }
} }
@ -80,15 +81,14 @@ public function reject(Article $article): JsonResponse
public function refresh(): JsonResponse public function refresh(): JsonResponse
{ {
try { try {
// Dispatch the article discovery job
ArticleDiscoveryJob::dispatch(); ArticleDiscoveryJob::dispatch();
return $this->sendResponse( return $this->sendResponse(
null, null,
'Article refresh started. New articles will appear shortly.' 'Article refresh started. New articles will appear shortly.'
); );
} catch (\Exception $e) { } catch (Exception $e) {
return $this->sendError('Failed to start article refresh: ' . $e->getMessage(), [], 500); return $this->sendError('Failed to start article refresh: ' . $e->getMessage(), [], 500);
} }
} }
} }