feat: L'Ami Fiduciaire V1.0.0 — full codebase with Story 0.1 complete
Initial commit of the L'Ami Fiduciaire SaaS platform built on Laravel 12, Vue 3, Inertia.js 2, and Tailwind CSS 4. Story 0.1 (rename folders to declarations in database) is implemented and code-reviewed: migration, rollback, and 6 Pest tests all passing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
90
app/Http/Controllers/Client/UploadController.php
Normal file
90
app/Http/Controllers/Client/UploadController.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Enums\ActorType;
|
||||
use App\Enums\FolderStatus;
|
||||
use App\Enums\MessageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\FolderTextMessageMail;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class UploadController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the client upload page.
|
||||
*/
|
||||
public function show(Request $request, string $token): Response
|
||||
{
|
||||
$invitation = $request->attributes->get('folder_invitation');
|
||||
$folder = $invitation->folder;
|
||||
|
||||
$folder->load(['client']);
|
||||
$documents = $folder->getMedia('documents')->map(fn ($m) => [
|
||||
'id' => $m->id,
|
||||
'name' => $m->name,
|
||||
'file_name' => $m->file_name,
|
||||
'size' => $m->human_readable_size,
|
||||
'created_at' => $m->created_at->format('d/m/Y H:i'),
|
||||
])->values()->all();
|
||||
|
||||
return Inertia::render('client/Upload', [
|
||||
'folder' => [
|
||||
'id' => $folder->id,
|
||||
'title' => $folder->title,
|
||||
'client_name' => $folder->client->company_name,
|
||||
],
|
||||
'token' => $token,
|
||||
'documents' => $documents,
|
||||
'uploadUrl' => route('client.upload.store', ['token' => $token]),
|
||||
'csrfToken' => csrf_token(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store uploaded files.
|
||||
*/
|
||||
public function store(Request $request, string $token): RedirectResponse
|
||||
{
|
||||
$invitation = $request->attributes->get('folder_invitation');
|
||||
$folder = $invitation->folder;
|
||||
|
||||
$request->validate([
|
||||
'files' => ['required', 'array', 'min:1'],
|
||||
'files.*' => ['file', 'max:10240'],
|
||||
]);
|
||||
|
||||
$message = $folder->messages()->create([
|
||||
'type' => MessageType::Text,
|
||||
'body' => 'Documents déposés par le client.',
|
||||
'sent_by_type' => ActorType::Client,
|
||||
'sent_by_id' => $folder->client_id,
|
||||
'metadata' => ['invitation_id' => $invitation->id],
|
||||
]);
|
||||
|
||||
foreach ($request->file('files') as $file) {
|
||||
$folder->addMedia($file)
|
||||
->withCustomProperties([
|
||||
'message_id' => $message->id,
|
||||
'uploaded_by_type' => ActorType::Client,
|
||||
'uploaded_by_id' => $folder->client_id,
|
||||
])
|
||||
->toMediaCollection('documents');
|
||||
}
|
||||
|
||||
$folder->update(['status' => FolderStatus::DocumentsReceived]);
|
||||
|
||||
$recipient = $folder->assignee ?? $folder->creator;
|
||||
if ($recipient?->email) {
|
||||
Mail::to($recipient->email)->send(
|
||||
new FolderTextMessageMail($folder, 'Le client a déposé des documents.', null)
|
||||
);
|
||||
}
|
||||
|
||||
return back()->with('flash', ['type' => 'success', 'message' => 'Documents envoyés avec succès.']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user