Skip to content

Commit

Permalink
add the upload and file start processing job batch and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Mar 25, 2024
1 parent 0f36633 commit df8cbf9
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 7 deletions.
41 changes: 41 additions & 0 deletions app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace App\Http\Controllers;

use App\Domains\Documents\TypesEnum;
use App\Http\Resources\CollectionResource;
use App\Http\Resources\DocumentResource;
use App\Jobs\ParsePdfFileJob;
use App\Models\Collection;
use App\Models\Document;
use Illuminate\Support\Facades\Log;

class CollectionController extends Controller
{
Expand All @@ -14,6 +19,7 @@ public function index()
'collections' => CollectionResource::collection(Collection::query()
->where('team_id', auth()->user()->current_team_id)
->get()),

]);
}

Expand All @@ -40,6 +46,41 @@ public function show(Collection $collection)
{
return inertia('Collection/Show', [
'collection' => new CollectionResource($collection),
'documents' => DocumentResource::collection(Document::query()
->where('collection_id', $collection->id)
->latest("id")
->get()),
]);
}

public function filesUpload(Collection $collection) {
$validated = request()->validate([
'files' => 'required',
]);

foreach($validated['files'] as $file) {
Log::info("file info", [
'name' => $file->getClientOriginalName(),
'mimetype' => $file->getMimeType(),
]);

$document = Document::create([
'collection_id' => $collection->id,
'file_path' => $file->getClientOriginalName(),
'type' => TypesEnum::PDF
]);

$file->storeAs(
path: $collection->id,
name: $file->getClientOriginalName(),
options: ['disk' => 'collections']
);

ParsePdfFileJob::dispatch($document);
}

request()->session()->flash('flash.banner', 'Files uploaded successfully!');

return back();
}
}
19 changes: 19 additions & 0 deletions app/Http/Resources/DocumentResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class DocumentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.0",
"phpunit/phpunit": "^10.5",
"spatie/laravel-horizon-watcher": "^1.1",
"spatie/laravel-ignition": "^2.4"
},
"autoload": {
Expand Down
132 changes: 131 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
'throw' => false,
],

'collections' => [
'driver' => 'local',
'root' => storage_path('app/collections'),
'throw' => false,
],

'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
Expand Down
46 changes: 45 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@vitejs/plugin-vue": "^5.0.0",
"autoprefixer": "^10.4.16",
"axios": "^1.6.4",
"chokidar": "^3.6.0",
"laravel-vite-plugin": "^1.0",
"postcss": "^8.4.32",
"tailwindcss": "^3.4.0",
Expand All @@ -24,6 +25,8 @@
"apexcharts": "^3.47.0",
"vue-apexcharts": "^1.6.2",
"vue-toastification": "^2.0.0-rc.5",
"vue3-apexcharts": "^1.5.2"
"vue-upload-component": "^3.1.15",
"vue3-apexcharts": "^1.5.2",
"vue3-dropzone": "^2.2.1"
}
}
4 changes: 3 additions & 1 deletion resources/js/Components/PrimaryButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ defineProps({
</script>

<template>
<button :type="type" class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 focus:bg-gray-700 active:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition ease-in-out duration-150">
<button :type="type" class="
disabled:opacity-50
inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 focus:bg-gray-700 active:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition ease-in-out duration-150">
<slot />
</button>
</template>
Loading

0 comments on commit df8cbf9

Please sign in to comment.