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(event): implement index, store #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use App\Models\Event;
use Illuminate\Http\Request;

class EventController extends Controller
{
public function index()
{
$events = Event::all();

return response()->json($events->all());
}

public function store(Request $request)
{
$data = $request->only([
'name',
'trigger_time'
]);
Event::create($data);

return response()->json(['status' => 'OK']);
}
}

12 changes: 12 additions & 0 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Event extends Model
{
protected $table = 'events';

protected $guarded = [];
}
32 changes: 32 additions & 0 deletions database/migrations/2023_12_05_093941_create_events_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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
{

// 通知管道(1…*)
// 要通知的對象(1…*)
Schema::create('events', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->dateTimeTz('trigger_time');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('events');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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('notify_channels', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('content');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notify_channels');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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('event_notify_channel', function (Blueprint $table) {
$table->id();
$table->foreignId('event_id')->constrained('events');
$table->foreignId('notify_channel_id')->constrained('notify_channels');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('event_notify_channel');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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('event_notify_channel_user', function (Blueprint $table) {
$table->foreignId('event_notify_channel_id')->constrained('event_notify_channel');
$table->foreignId('user_id')->constrained('users');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('event_notify_channel_user');
}
};
10 changes: 7 additions & 3 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\EventController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Expand All @@ -14,6 +15,9 @@
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
// return $request->user();
// });

Route::get('events', [EventController::class, 'index']);
Route::post('events', [EventController::class, 'store']);