Skip to content

Commit

Permalink
add collections
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Mar 25, 2024
1 parent dee8d03 commit 0f36633
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
25 changes: 13 additions & 12 deletions app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

use App\Http\Resources\CollectionResource;
use App\Models\Collection;
use Illuminate\Http\Request;

class CollectionController extends Controller
{

public function index() {
public function index()
{

return inertia("Collection/Index", [
return inertia('Collection/Index', [
'collections' => CollectionResource::collection(Collection::query()
->where("team_id", auth()->user()->current_team_id)
->get())
->where('team_id', auth()->user()->current_team_id)
->get()),
]);
}

public function store() {

public function store()
{

$validated = request()->validate([
'name' => 'required',
'description' => 'required',
Expand All @@ -31,14 +31,15 @@ public function store() {
/**
* Make and then reditect to the view page
*/
request()->session()->flash("flash.banner", "Collection created successfully!");
request()->session()->flash('flash.banner', 'Collection created successfully!');

return to_route('collections.show', $collection);
}

public function show(Collection $collection) {
return inertia("Collection/Show", [
'collection' => new CollectionResource($collection)
public function show(Collection $collection)
{
return inertia('Collection/Show', [
'collection' => new CollectionResource($collection),
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function version(Request $request): ?string
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'app_name' => config("app.name"),
'app_name' => config('app.name'),
'features' => Feature::all(),
]);
}
Expand Down
8 changes: 4 additions & 4 deletions app/Jobs/ProcessFileJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function handle(): void
->name('OptOutRequests')
->finally(function (Batch $batch) {
/**
* @TODO
* make a job that does that and also
* closes up the batch on the run watcher
*/
* @TODO
* make a job that does that and also
* closes up the batch on the run watcher
*/
CollectionStatusEvent::dispatch(
$this->document->collection,
CollectionStatusEnum::PROCESSED);
Expand Down
3 changes: 1 addition & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use App\Http\Controllers\CollectionController;
use App\Http\Controllers\ExampleChatBotController;
use App\Http\Controllers\ExampleController;
use App\Models\Collection;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
Expand All @@ -23,7 +22,7 @@
'verified',
])->group(function () {
Route::get('/dashboard', function () {
return to_route("collections.index");
return to_route('collections.index');
//return Inertia::render('Dashboard');
})->name('dashboard');

Expand Down
12 changes: 4 additions & 8 deletions tests/Feature/Http/Controllers/CollectionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace Tests\Feature\Http\Controllers;

use App\Models\Collection;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;

class CollectionControllerTest extends TestCase
{
Expand All @@ -25,7 +22,7 @@ public function test_example(): void

Collection::factory()->create();

$response = $this->get(route("collections.index"))
$response = $this->get(route('collections.index'))
->assertStatus(200)
->assertInertia(fn (Assert $page) => $page
->component('Collection/Index')
Expand All @@ -39,12 +36,11 @@ public function test_store(): void
$this->actingAs($user);

$this->assertDatabaseCount('collections', 0);
$response = $this->post(route("collections.store"), [
'name' => "Test",
$response = $this->post(route('collections.store'), [
'name' => 'Test',
'description' => 'Test Description',
])->assertStatus(302);
$this->assertDatabaseCount('collections', 1);


}
}
6 changes: 3 additions & 3 deletions tests/Feature/UpdateTeamMemberRoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function test_team_member_roles_can_be_updated(): void
);

$response = $this->put('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id, [
'role' => 'editor',
'role' => 'member',
]);

$this->assertTrue($otherUser->fresh()->hasTeamRole(
$user->currentTeam->fresh(), 'editor'
$user->currentTeam->fresh(), 'member'
));
}

Expand All @@ -38,7 +38,7 @@ public function test_only_team_owner_can_update_team_member_roles(): void
$this->actingAs($otherUser);

$response = $this->put('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id, [
'role' => 'editor',
'role' => 'member',
]);

$this->assertTrue($otherUser->fresh()->hasTeamRole(
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ abstract class TestCase extends BaseTestCase
{
use LazilyRefreshDatabase;


public function createUserWithCurrentTeam() {
public function createUserWithCurrentTeam()
{
$user = User::factory()->withPersonalTeam()->create();
$user->current_team_id = Team::first()->id;
$user->save();
Expand Down

0 comments on commit 0f36633

Please sign in to comment.