|
4 | 4 |
|
5 | 5 | namespace App\Livewire\Articles;
|
6 | 6 |
|
7 |
| -use App\Events\ArticleWasSubmittedForApproval; |
8 |
| -use App\Gamify\Points\PostCreated; |
9 |
| -use App\Models\Article; |
| 7 | +use App\Actions\Article\CreateArticleAction; |
| 8 | +use App\Data\Article\CreateArticleData; |
10 | 9 | use App\Models\Tag;
|
11 | 10 | use App\Models\User;
|
12 | 11 | use App\Traits\WithArticleAttributes;
|
13 | 12 | use App\Traits\WithTagsAssociation;
|
14 |
| -use Carbon\Carbon; |
15 |
| -use DateTimeInterface; |
16 | 13 | use Illuminate\Contracts\View\View;
|
17 | 14 | use Illuminate\Support\Facades\Auth;
|
18 | 15 | use Livewire\Component;
|
@@ -52,46 +49,16 @@ public function store(): void
|
52 | 49 | /** @var User $user */
|
53 | 50 | $user = Auth::user();
|
54 | 51 |
|
55 |
| - if ($this->published_at && ! ($this->published_at instanceof DateTimeInterface)) { |
56 |
| - $this->published_at = new Carbon( |
57 |
| - time: $this->published_at, |
58 |
| - tz: config('app.timezone') |
59 |
| - ); |
60 |
| - } |
61 |
| - |
62 |
| - /** @var Article $article */ |
63 |
| - $article = Article::create([ |
| 52 | + $article = app(CreateArticleAction::class)->execute(CreateArticleData::from([ |
64 | 53 | 'title' => $this->title,
|
65 | 54 | 'slug' => $this->slug,
|
66 | 55 | 'body' => $this->body,
|
67 |
| - 'published_at' => $this->published_at, |
68 |
| - 'submitted_at' => $this->submitted_at, |
69 |
| - 'approved_at' => $this->approved_at, |
70 |
| - 'show_toc' => $this->show_toc, |
71 |
| - 'canonical_url' => $this->canonical_url, |
72 |
| - 'user_id' => $user->id, |
73 |
| - ]); |
74 |
| - |
75 |
| - if (collect($this->associateTags)->isNotEmpty()) { |
76 |
| - $article->syncTags(tags: $this->associateTags); |
77 |
| - } |
78 |
| - |
79 |
| - if ($this->file) { |
80 |
| - $article->addMedia($this->file->getRealPath())->toMediaCollection('media'); |
81 |
| - } |
82 |
| - |
83 |
| - if ($article->isAwaitingApproval()) { |
84 |
| - if (app()->environment('production')) { |
85 |
| - // Envoi de la notification sur le channel Telegram pour la validation de l'article. |
86 |
| - event(new ArticleWasSubmittedForApproval($article)); |
87 |
| - } |
88 |
| - |
89 |
| - session()->flash('status', __('Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.')); |
90 |
| - } |
91 |
| - |
92 |
| - if ($user->hasAnyRole(['admin', 'moderator'])) { |
93 |
| - givePoint(new PostCreated($article)); |
94 |
| - } |
| 56 | + 'publishedAt' => $this->published_at, |
| 57 | + 'submittedAt' => $this->submitted_at, |
| 58 | + 'approvedAt' => $this->approved_at, |
| 59 | + 'showToc' => $this->show_toc, |
| 60 | + 'canonicalUrl' => $this->canonical_url, |
| 61 | + ])); |
95 | 62 |
|
96 | 63 | $user->hasRole('user') ?
|
97 | 64 | $this->redirectRoute('dashboard') :
|
|
0 commit comments