From 1f803d5355df5ba564ff5fdfbb8c984b40eba7af Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Sat, 27 Jul 2024 09:28:57 -0400 Subject: [PATCH] fix the data var --- Modules/LlmDriver/app/ClaudeClient.php | 1 + app/Http/Controllers/CollectionController.php | 9 +++++++ routes/web.php | 1 + .../Controllers/CollectionControllerTest.php | 25 +++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/Modules/LlmDriver/app/ClaudeClient.php b/Modules/LlmDriver/app/ClaudeClient.php index ae60ec82..98d48712 100644 --- a/Modules/LlmDriver/app/ClaudeClient.php +++ b/Modules/LlmDriver/app/ClaudeClient.php @@ -124,6 +124,7 @@ public function completion(string $prompt): CompletionResponse public function getContentAndToolTypeFromResults(Response $results): array { + $data = 'No results found'; $results = $results->json(); $tool_used = null; $stop_reason = data_get($results, 'stop_reason', 'end_turn'); diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index 2e0c6799..4c31e15d 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -142,4 +142,13 @@ public function resetCollectionDocument(Collection $collection, Document $docume return back(); } + + public function delete(Collection $collection) + { + $collection->delete(); + + request()->session()->flash('flash.banner', 'Collection deleted!'); + + return back(); + } } diff --git a/routes/web.php b/routes/web.php index 531625a4..46fdd421 100644 --- a/routes/web.php +++ b/routes/web.php @@ -282,6 +282,7 @@ function () { ->name('collections.documents.reset'); Route::post('/collections', 'store')->name('collections.store'); Route::put('/collections/{collection}', 'update')->name('collections.update'); + Route::delete('/collections/{collection}', 'delete')->name('collections.delete'); Route::get('/collections/{collection}', 'show')->name('collections.show'); Route::any('/collections/{collection}/upload', 'filesUpload')->name('collections.upload'); }); diff --git a/tests/Feature/Http/Controllers/CollectionControllerTest.php b/tests/Feature/Http/Controllers/CollectionControllerTest.php index 3e398e18..e8b4cb15 100644 --- a/tests/Feature/Http/Controllers/CollectionControllerTest.php +++ b/tests/Feature/Http/Controllers/CollectionControllerTest.php @@ -3,9 +3,11 @@ namespace Tests\Feature\Http\Controllers; use App\Jobs\ProcessFileJob; +use App\Models\Chat; use App\Models\Collection; use App\Models\Document; use App\Models\DocumentChunk; +use App\Models\Message; use App\Models\User; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Queue; @@ -16,6 +18,29 @@ class CollectionControllerTest extends TestCase { + public function test_delete(): void + { + $user = User::factory()->create(); + $collection = Collection::factory()->create(); + + $document = Document::factory(4) + ->has(DocumentChunk::factory(4), 'document_chunks')->create([ + 'collection_id' => $collection->id, + ]); + + $chat = Chat::factory(3) + ->has(Message::factory(3))->create([ + 'chatable_id' => $collection->id, + 'chatable_type' => Collection::class, + ]); + + $this->actingAs($user) + ->delete(route('collections.delete', $collection)); + $this->assertDatabaseMissing('collections', [ + 'id' => $collection->id, + ]); + } + /** * A basic feature test example. */