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 df8cbf9 commit 4e8843d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,27 @@ 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(),
]);

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

$file->storeAs(
Expand Down
7 changes: 4 additions & 3 deletions tests/Feature/Http/Controllers/CollectionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand Down

0 comments on commit 4e8843d

Please sign in to comment.