From 4e8843d88fb2b7d475a4619a477f8035d8e5b851 Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Mon, 25 Mar 2024 13:41:27 -0400 Subject: [PATCH] add the upload and file start processing job batch and controller --- app/Http/Controllers/CollectionController.php | 11 ++++++----- .../Http/Controllers/CollectionControllerTest.php | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index be726ab8..7ec796e3 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -48,18 +48,19 @@ public function show(Collection $collection) 'collection' => new CollectionResource($collection), 'documents' => DocumentResource::collection(Document::query() ->where('collection_id', $collection->id) - ->latest("id") + ->latest('id') ->get()), ]); } - public function filesUpload(Collection $collection) { + public function filesUpload(Collection $collection) + { $validated = request()->validate([ 'files' => 'required', ]); - foreach($validated['files'] as $file) { - Log::info("file info", [ + foreach ($validated['files'] as $file) { + Log::info('file info', [ 'name' => $file->getClientOriginalName(), 'mimetype' => $file->getMimeType(), ]); @@ -67,7 +68,7 @@ public function filesUpload(Collection $collection) { $document = Document::create([ 'collection_id' => $collection->id, 'file_path' => $file->getClientOriginalName(), - 'type' => TypesEnum::PDF + 'type' => TypesEnum::PDF, ]); $file->storeAs( diff --git a/tests/Feature/Http/Controllers/CollectionControllerTest.php b/tests/Feature/Http/Controllers/CollectionControllerTest.php index 6508a3ea..2f68bfc7 100644 --- a/tests/Feature/Http/Controllers/CollectionControllerTest.php +++ b/tests/Feature/Http/Controllers/CollectionControllerTest.php @@ -48,7 +48,8 @@ public function test_store(): void } - public function test_file_upload() { + public function test_file_upload() + { Queue::fake(); Storage::fake('collections'); $user = $this->createUserWithCurrentTeam(); @@ -59,14 +60,14 @@ public function test_file_upload() { /** * @TODO Policy in place by now */ - $response = $this->post(route("collections.upload", $collection), [ + $response = $this->post(route('collections.upload', $collection), [ 'files' => [ UploadedFile::fake()->create('exaple1.pdf', 1024, 'application/pdf'), UploadedFile::fake()->create('exaple1.pdf', 1024, 'application/pdf'), ], ]); - Storage::disk("collections")->assertExists("{$collection->id}/exaple1.pdf"); + Storage::disk('collections')->assertExists("{$collection->id}/exaple1.pdf"); Queue::assertPushed(ParsePdfFileJob::class, 2);