refactor: adopt modular domain architecture (#747)

* refactor: stabilize model identities for domain migration

* refactor: extract module platform context

* refactor: assign models to domain contexts

* refactor: extract ai platform context

* refactor: extract storage platform context

* refactor: extract mail platform context

* refactor: extract pdf platform context

* refactor: extract operations platform context

* refactor: move installation into operations platform

* refactor: extract money domain context

* refactor: extract taxation domain context

* refactor: extract catalog domain context

* refactor: extract metadata domain context

* refactor: extract reporting domain context

* refactor: extract purchases domain context

* refactor: extract receivables domain context

* refactor: extract accounts domain context

* refactor: complete reporting statement boundary

* refactor: extract contacts domain context

* refactor: extract sales domain context

* refactor: remove legacy application layers

* fix: migrate legacy bouncer role identities
This commit is contained in:
Darko Gjorgjijoski
2026-08-05 17:40:03 +02:00
committed by GitHub
parent a34bf0909f
commit 5ef7804e60
878 changed files with 8997 additions and 5707 deletions
@@ -0,0 +1,117 @@
<?php
namespace App\Platform\Storage\Http;
use App\Platform\Http\Controller;
use App\Platform\Storage\Application\BackupService;
use App\Platform\Storage\Jobs\CreateBackupJob;
use App\Platform\Storage\Rules\PathToZip;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Spatie\Backup\BackupDestination\Backup;
use Spatie\Backup\Helpers\Format;
use Symfony\Component\HttpFoundation\StreamedResponse;
class BackupsController extends Controller
{
public function __construct(
private readonly BackupService $backupService,
) {}
public function index(Request $request): JsonResponse
{
$this->authorize('manage backups');
try {
$destination = $this->backupService->getDestination($request->file_disk_id);
$backups = $destination
->backups()
->map(function (Backup $backup) {
return [
'path' => $backup->path(),
'created_at' => $backup->date()->format('Y-m-d H:i:s'),
'size' => Format::humanReadableSize($backup->sizeInBytes()),
];
})
->toArray();
return response()->json([
'backups' => $backups,
]);
} catch (\Exception $e) {
return response()->json([
'backups' => [],
'error' => 'invalid_disk_credentials',
'error_message' => $e->getMessage(),
]);
}
}
public function store(Request $request): JsonResponse
{
$this->authorize('manage backups');
$data = $request->all();
dispatch(new CreateBackupJob($data))->onQueue(config('backup.queue.name'));
return response()->json(['success' => true]);
}
public function destroy($disk, Request $request): JsonResponse
{
$this->authorize('manage backups');
$validated = $request->validate([
'path' => ['required', new PathToZip],
]);
$destination = $this->backupService->getDestination($request->file_disk_id);
$destination
->backups()
->first(function (Backup $backup) use ($validated) {
return $backup->path() === $validated['path'];
})
->delete();
return response()->json(['success' => true]);
}
public function download(Request $request): Response|StreamedResponse
{
$this->authorize('manage backups');
$validated = $request->validate([
'path' => ['required', new PathToZip],
]);
$destination = $this->backupService->getDestination($request->file_disk_id);
$backup = $destination->backups()->first(function (Backup $backup) use ($validated) {
return $backup->path() === $validated['path'];
});
if (! $backup) {
return response('Backup not found', 422);
}
$fileName = pathinfo($backup->path(), PATHINFO_BASENAME);
return response()->stream(function () use ($backup) {
$stream = $backup->stream();
fpassthru($stream);
if (is_resource($stream)) {
fclose($stream);
}
}, 200, [
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Content-Type' => 'application/zip',
'Content-Length' => $backup->sizeInBytes(),
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
'Pragma' => 'public',
]);
}
}