Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add space columns and draggable tasks #72

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion app/Http/Controllers/Auth/SignUpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,39 @@ public function __invoke(SignUpRequest $request)

Auth::login($user, false);

$user->spaces()->create([
/** @var \App\Models\Space $space */
$space = $user->spaces()->create([
'name' => $user->name,
]);

$space->columns()->createMany([
[
'name' => 'Triage',
'status' => 'triage',
'order' => 0,
],
[
'name' => 'To Do',
'status' => 'todo',
'order' => 1,
],
[
'name' => 'Doing',
'status' => 'doing',
'order' => 2,
],
[
'name' => 'Done',
'status' => 'done',
'order' => 3,
],
[
'name' => 'Abandon',
'status' => 'abandon',
'order' => 4,
],
]);

return response()->redirectTo(route('web.space.index'));
}

Expand Down
36 changes: 34 additions & 2 deletions app/Http/Controllers/SpaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ public function store(StoreSpaceRequest $request)
]);
}

$space->columns()->createMany([
[
'name' => 'Triage',
'status' => 'triage',
'order' => 0,
],
[
'name' => 'To Do',
'status' => 'todo',
'order' => 1,
],
[
'name' => 'Doing',
'status' => 'doing',
'order' => 2,
],
[
'name' => 'Done',
'status' => 'done',
'order' => 3,
],
[
'name' => 'Abandon',
'status' => 'abandon',
'order' => 4,
],
]);

return back();
}

Expand All @@ -61,6 +89,8 @@ public function show(Space $space)
{
Gate::authorize('view', [$space]);

$space->load('columns', 'columns.tasks');

return Inertia::render('space/[id]/page', [
'breadcrumbs' => [
[
Expand All @@ -81,7 +111,6 @@ public function show(Space $space)
],
],
'space' => $space,
'tasks' => $space->tasks,
]);
}

Expand All @@ -93,7 +122,10 @@ public function update(UpdateSpaceRequest $request, Space $space)
$space->update($request->validated());
$space->refresh();

return back();
return response()->redirectTo(
route('web.space.show', ['space' => $space->id]),
303
);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/SpaceTaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ public function show(Space $space, Task $task)
public function update(UpdateTaskRequest $request, Space $space, Task $task)
{
$task->update($request->validated());
$task->refresh();

return response()->json([
'data' => $task,
]);
return back(status: 303);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Requests/Task/UpdateTaskRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Requests\Task;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateTaskRequest extends FormRequest
{
Expand All @@ -25,8 +26,12 @@ public function rules(): array
'title' => 'required|string|max:100',
'description' => 'string',
'status' => 'in:triage,todo,doing,done,abandon',
'assigned_to_id' => 'int|nullable|exists:users,id',
'assigned_to_id' => 'sometimes|nullable|exists:users,id',
'due_date' => 'date|nullable',
'space_column_id' => Rule::exists('space_columns', 'id')->where(
'space_id',
$this->space->id
),
];
}
}
5 changes: 5 additions & 0 deletions app/Models/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public function tasks()
{
return $this->hasMany(Task::class);
}

public function columns()
{
return $this->hasMany(SpaceColumn::class);
}
}
29 changes: 29 additions & 0 deletions app/Models/SpaceColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SpaceColumn extends Model
{
use HasFactory, SoftDeletes;

protected $guarded = [];

protected $casts = [
'created_at' => 'datetime',
'updated_at' => 'datetime',
];

public function space()
{
return $this->belongsTo(Space::class);
}

public function tasks()
{
return $this->hasMany(Task::class);
}
}
5 changes: 5 additions & 0 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public function space()
{
return $this->belongsTo(Space::class);
}

public function column()
{
return $this->belongsTo(SpaceColumn::class);
}
}
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function up(): void
$table->string('name');
$table->bigInteger('created_by_id')->unsigned();
$table->bigInteger('updated_by_id')->unsigned();
$table->enum('type', ['personal', 'team'])->default('personal');
$table->timestamps();
$table->softDeletes();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('space_columns', function (Blueprint $table) {
$table->id();
$table->bigInteger('space_id')->unsigned();
$table->string('name');
$table->integer('order');
$table->string('status')->nullable();
$table->timestamps();
$table->softDeletes();

$table
->foreign('space_id')
->references('id')
->on('spaces')
->cascadeOnDelete();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('space_columns');
}
};
9 changes: 8 additions & 1 deletion database/migrations/2023_09_10_234530_create_tasks_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public function up(): void
->enum('status', ['triage', 'todo', 'doing', 'done', 'abandon'])
->default('triage');
$table->date('due_date')->nullable();
$table->unsignedBigInteger('assigned_to_id')->nullable();
$table->unsignedBigInteger('space_id');
$table->unsignedBigInteger('space_column_id');
$table->unsignedBigInteger('assigned_to_id')->nullable();
$table->unsignedBigInteger('created_by_id');
$table->unsignedBigInteger('updated_by_id');
$table->timestamps();
Expand All @@ -42,6 +43,12 @@ public function up(): void
->foreign('space_id')
->references('id')
->on('spaces');

$table
->foreign('space_column_id')
->references('id')
->on('space_columns')
->cascadeOnDelete();
});
}

Expand Down

This file was deleted.

This file was deleted.

31 changes: 30 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,38 @@ public function run(): void
'password' => 'password',
]);

$user->spaces()->create([
/** @var \App\Models\Space $space */
$space = $user->spaces()->create([
'name' => $user->name,
'updated_by_id' => $user->id,
]);

$space->columns()->createMany([
[
'name' => 'Triage',
'status' => 'triage',
'order' => 0,
],
[
'name' => 'To Do',
'status' => 'todo',
'order' => 1,
],
[
'name' => 'Doing',
'status' => 'doing',
'order' => 2,
],
[
'name' => 'Done',
'status' => 'done',
'order' => 3,
],
[
'name' => 'Abandon',
'status' => 'abandon',
'order' => 4,
],
]);
}
}
Loading
Loading