mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 02:50:39 +00:00
create team folder
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace Domain\Teams\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Domain\Teams\DTO\CreateTeamFolderData;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Domain\Teams\Models\TeamFoldersInvitation;
|
||||
use Domain\Teams\Notifications\InvitationIntoTeamFolder;
|
||||
|
||||
class TeamFoldersController extends Controller
|
||||
{
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$data = CreateTeamFolderData::fromRequest($request);
|
||||
|
||||
$teamFolder = Folder::create([
|
||||
'user_id' => $request->user()->id,
|
||||
'name' => $data->name,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
collect($data->members)
|
||||
->each(function ($email) use ($teamFolder) {
|
||||
|
||||
// Create invitation
|
||||
$invitation = TeamFoldersInvitation::create([
|
||||
'folder_id' => $teamFolder->id,
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
// Invite user
|
||||
Notification::route('mail', $email)
|
||||
->notify(new InvitationIntoTeamFolder($teamFolder, $invitation));
|
||||
});
|
||||
|
||||
return response($teamFolder, 201);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Domain\Teams\DTO;
|
||||
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
|
||||
class CreateTeamFolderData extends DataTransferObject
|
||||
{
|
||||
public string $name;
|
||||
public array $members;
|
||||
|
||||
public static function fromRequest($request): self
|
||||
{
|
||||
return new self([
|
||||
'name' => $request->input('name'),
|
||||
'members' => $request->input('members'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Domain\Teams\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
/**
|
||||
* @method static create(array $array)
|
||||
* @property string id
|
||||
* @property string folder_id
|
||||
* @property string email
|
||||
* @property string status
|
||||
* @property string created_at
|
||||
* @property string updated_at
|
||||
*/
|
||||
class TeamFoldersInvitation extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
];
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->id = Str::uuid();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Domain\Teams\Notifications;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Domain\Teams\Models\TeamFoldersInvitation;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class InvitationIntoTeamFolder extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public Folder $teamFolder,
|
||||
public TeamFoldersInvitation $invitation,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*/
|
||||
public function via(): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$appTitle = get_settings('app_title') ?? 'VueFileManager';
|
||||
|
||||
$user = User::find($this->invitation->email);
|
||||
|
||||
if ($user) {
|
||||
return (new MailMessage)
|
||||
->subject("You are invited to collaboration with team folder in $appTitle")
|
||||
->greeting('Hello!')
|
||||
->line('You are invited to collaboration with team folder')
|
||||
->action('Join into Team Folder', url('/team-folder-invitation', ['id' => $this->invitation->id]))
|
||||
->salutation("Regards, $appTitle");
|
||||
}
|
||||
|
||||
return (new MailMessage)
|
||||
->subject("You are invited to collaboration with team folder in $appTitle")
|
||||
->greeting('Hello!')
|
||||
->line('You are invited to collaboration with team folder. But at first, you have to create an account to proceed into team folder.')
|
||||
->action('Join & Create an Account', url('/team-folder-invitation', ['id' => $this->invitation->id]))
|
||||
->salutation("Regards, $appTitle");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user