added email notification about fulfilling upload request

This commit is contained in:
Čarodej
2022-02-24 10:43:35 +01:00
parent a589ee5f7a
commit 45dcdcce16
6 changed files with 82 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace Domain\UploadRequest\Controllers;
use Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification;
use Illuminate\Http\Response;
use Domain\UploadRequest\Models\UploadRequest;
use Illuminate\Contracts\Foundation\Application;
@@ -15,6 +16,9 @@ class SetUploadRequestAsFilledController
'status' => 'filled',
]);
// Send user notification
$uploadRequest->user->notify(new UploadRequestFulfilledNotification($uploadRequest));
return response(new UploadRequestResource($uploadRequest), 201);
}
}

View File

@@ -49,6 +49,11 @@ class UploadRequest extends Model
return $this->hasOne(Folder::class, 'id', 'id');
}
public function parent(): HasOne
{
return $this->hasOne(Folder::class, 'id', 'folder_id');
}
protected static function boot()
{
parent::boot();

View File

@@ -0,0 +1,63 @@
<?php
namespace Domain\UploadRequest\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Domain\UploadRequest\Models\UploadRequest;
use Illuminate\Notifications\Messages\MailMessage;
class UploadRequestFulfilledNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(
public UploadRequest $uploadRequest
) {
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
// TODO: add to language strings
return (new MailMessage)
->subject("Your file request was fulfilled in your '{$this->uploadRequest->parent->name}' folder")
->greeting('Hello')
->line("We are emailing you because your file request was fulfilled. Please click on the link below to show uploaded files.")
->action('Show Files', url("/platform/files/{$this->uploadRequest->id}"))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
];
}
}