-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: (LAR-105) create TransfertDiscutionToThreadAction file #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
StevyMarlino
merged 15 commits into
develop
from
feature/lar-105-donnez-la-possibilite-de-transformer-une-discussion-en-sujet
Dec 14, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
40c9d58
feat: (LAR-105) create TransfertDiscutionToThreadAction file
StevyMarlino 491b6f8
feat: (LAR-105) convert discussion to thread creator part
StevyMarlino 31ea9fc
Merge branch 'develop' into feature/lar-105-donnez-la-possibilite-de-…
StevyMarlino 9139b82
Merge branch 'develop' into feature/lar-105-donnez-la-possibilite-de-…
StevyMarlino d41b68d
feat:(LAR-105) add transform a discussion to a thread
StevyMarlino 614bd11
feat: (LAR-105) add translation
StevyMarlino ffbc8e2
refact(test): refactoring test and logic of action
StevyMarlino db25b23
fix: (LAR-105) fixing stan error
StevyMarlino 63d3a1f
refact(lang):(LAR-105) refactoring lang discussion
StevyMarlino 2626d99
fix: (LAR-105) fixing style lint
StevyMarlino 2ab0980
refact: (LAR-105) refactoring style
StevyMarlino d0f9500
fix(phpstan):(LAR-105) fixing phpstan error
StevyMarlino 4277e95
fix(phpstan):(LAR-105) fixing phpstan error
StevyMarlino 07402a1
fix(phpstan):(LAR-105) fixing phpstan error on User model
StevyMarlino b14aaea
fix(pint):(LAR-105) fixing lint error on User model
StevyMarlino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
app/Actions/Discussion/ConvertDiscussionToThreadAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Discussion; | ||
|
||
use App\Models\Discussion; | ||
use App\Models\Thread; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
final class ConvertDiscussionToThreadAction | ||
{ | ||
public function execute(Discussion $discussion): Thread | ||
{ | ||
return DB::transaction(function () use ($discussion) { | ||
$thread = Thread::create([ | ||
'title' => $discussion->title, | ||
'slug' => $discussion->slug, | ||
'body' => $discussion->body, | ||
'user_id' => $discussion->user_id, | ||
'last_posted_at' => null, | ||
]); | ||
|
||
$discussion->replies()->update([ | ||
'replyable_type' => 'thread', | ||
'replyable_id' => $thread->id, | ||
]); | ||
|
||
$discussion->delete(); | ||
|
||
app(NotifyUsersOfThreadConversion::class)->execute($thread); | ||
|
||
return $thread; | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Discussion; | ||
|
||
use App\Models\Thread; | ||
use App\Models\User; | ||
use App\Notifications\ThreadConvertedByAdmin; | ||
use App\Notifications\ThreadConvertedByCreator; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
final class NotifyUsersOfThreadConversion | ||
{ | ||
public function execute(Thread $thread): void | ||
{ | ||
$usersToNotify = $thread->replies()->pluck('user_id')->unique()->toArray(); | ||
|
||
User::whereIn('id', $usersToNotify)->get()->each->notify(new ThreadConvertedByCreator($thread)); | ||
|
||
if (Auth::check() && Auth::user()->isAdmin()) { | ||
$thread->user->notify(new ThreadConvertedByAdmin($thread)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Livewire\Modals; | ||
|
||
use App\Actions\Discussion\ConvertDiscussionToThreadAction; | ||
use App\Models\Discussion; | ||
use Illuminate\Contracts\View\View; | ||
use LivewireUI\Modal\ModalComponent; | ||
|
||
final class ConvertDiscussion extends ModalComponent | ||
{ | ||
public int $discussionId; | ||
|
||
public function save(): void | ||
{ | ||
/** @var Discussion $discussion */ | ||
$discussion = Discussion::query()->findOrFail($this->discussionId); | ||
|
||
$this->authorize('convertedToThread', $discussion); | ||
|
||
$thread = app(ConvertDiscussionToThreadAction::class)->execute($discussion); | ||
|
||
$this->redirectRoute('forum.show', $thread, navigate: true); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.modals.convert-discussion'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Models\Thread; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
|
||
final class ThreadConvertedByAdmin extends Notification | ||
{ | ||
use Queueable; | ||
|
||
public function __construct(public Thread $thread) {} | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public function via(object $notifiable): array | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
/** | ||
* Get the mail representation of the notification. | ||
*/ | ||
public function toMail(object $notifiable): MailMessage | ||
{ | ||
return (new MailMessage) | ||
->subject(__('pages/discussion.converted_by_admin.subject')) | ||
->greeting(__('pages/discussion.converted_by_admin.greeting')) | ||
->line(__('pages/discussion.converted_by_admin.converted_line')) | ||
->line(__('pages/discussion.converted_by_admin.thread_title').$this->thread->title) | ||
->action(__('pages/discussion.converted_by_admin.action_text'), route('forum.show', $this->thread)) | ||
->line(__('pages/discussion.converted_by_admin.admin_action_line')); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Models\Thread; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
|
||
final class ThreadConvertedByCreator extends Notification | ||
{ | ||
use Queueable; | ||
|
||
public function __construct(public Thread $thread) {} | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public function via(object $notifiable): array | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
/** | ||
* Get the mail representation of the notification. | ||
*/ | ||
public function toMail(object $notifiable): MailMessage | ||
{ | ||
return (new MailMessage) | ||
->subject(__('pages/discussion.converted_by_creator')) | ||
->line(__('pages/discussion.converted_by_creator.converted_line')) | ||
->line(__('pages/discussion.converted_by_creator.thread_title').$this->thread->title) | ||
->action(__('pages/discussion.converted_by_creator.action_text'), route('forum.show', $this->thread)) | ||
->line(__('pages/discussion.converted_by_creator.thank_you_line')); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ | |
'save' => 'Save', | ||
'ban' => 'Ban', | ||
'unban' => 'Cancel ban', | ||
'confirm' => 'Confirm', | ||
|
||
]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.