From 4c0c8da0bf89e504734991485f6b3304ab33a4f4 Mon Sep 17 00:00:00 2001 From: Jian Marcus Date: Tue, 5 Dec 2023 18:05:18 +0800 Subject: [PATCH 1/2] feat: add migrations --- .../2023_12_05_093941_create_events_table.php | 32 +++++++++++++++++++ ...05_095217_create_notify_channels_table.php | 29 +++++++++++++++++ ...5810_create_event_notify_channel_table.php | 29 +++++++++++++++++ ...create_event_notify_channel_user_table.php | 27 ++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 database/migrations/2023_12_05_093941_create_events_table.php create mode 100644 database/migrations/2023_12_05_095217_create_notify_channels_table.php create mode 100644 database/migrations/2023_12_05_095810_create_event_notify_channel_table.php create mode 100644 database/migrations/2023_12_05_100210_create_event_notify_channel_user_table.php diff --git a/database/migrations/2023_12_05_093941_create_events_table.php b/database/migrations/2023_12_05_093941_create_events_table.php new file mode 100644 index 0000000..229fb88 --- /dev/null +++ b/database/migrations/2023_12_05_093941_create_events_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->dateTimeTz('trigger_time'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('events'); + } +}; diff --git a/database/migrations/2023_12_05_095217_create_notify_channels_table.php b/database/migrations/2023_12_05_095217_create_notify_channels_table.php new file mode 100644 index 0000000..4bbea56 --- /dev/null +++ b/database/migrations/2023_12_05_095217_create_notify_channels_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('name'); + $table->text('content'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('notify_channels'); + } +}; diff --git a/database/migrations/2023_12_05_095810_create_event_notify_channel_table.php b/database/migrations/2023_12_05_095810_create_event_notify_channel_table.php new file mode 100644 index 0000000..6e37c46 --- /dev/null +++ b/database/migrations/2023_12_05_095810_create_event_notify_channel_table.php @@ -0,0 +1,29 @@ +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'); + } +}; diff --git a/database/migrations/2023_12_05_100210_create_event_notify_channel_user_table.php b/database/migrations/2023_12_05_100210_create_event_notify_channel_user_table.php new file mode 100644 index 0000000..e45b92a --- /dev/null +++ b/database/migrations/2023_12_05_100210_create_event_notify_channel_user_table.php @@ -0,0 +1,27 @@ +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'); + } +}; From bc07a6d08791cabffb531e83cad5fa21241264c0 Mon Sep 17 00:00:00 2001 From: Jian Marcus Date: Wed, 6 Dec 2023 00:50:45 +0800 Subject: [PATCH 2/2] feat(event): implement index, store --- app/Http/Controllers/EventController.php | 28 ++++++++++++++++++++++++ app/Models/Event.php | 12 ++++++++++ routes/api.php | 10 ++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/EventController.php create mode 100644 app/Models/Event.php diff --git a/app/Http/Controllers/EventController.php b/app/Http/Controllers/EventController.php new file mode 100644 index 0000000..67d40a1 --- /dev/null +++ b/app/Http/Controllers/EventController.php @@ -0,0 +1,28 @@ +json($events->all()); + } + + public function store(Request $request) + { + $data = $request->only([ + 'name', + 'trigger_time' + ]); + Event::create($data); + + return response()->json(['status' => 'OK']); + } +} + diff --git a/app/Models/Event.php b/app/Models/Event.php new file mode 100644 index 0000000..afba938 --- /dev/null +++ b/app/Models/Event.php @@ -0,0 +1,12 @@ +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']);