From 18f7cde415117856b8f8975126e97445d86a7636 Mon Sep 17 00:00:00 2001 From: grothedev Date: Sun, 22 Jun 2025 16:44:48 -0500 Subject: added quote model. working on some websocket stuff. --- app/Http/Controllers/QuoteController.php | 68 ++++++++++++++++++++++ app/Http/Requests/StoreQuoteRequest.php | 28 +++++++++ app/Http/Requests/UpdateQuoteRequest.php | 28 +++++++++ app/Models/Quote.php | 18 ++++++ database/factories/QuoteFactory.php | 23 ++++++++ .../2025_06_08_022018_create_quotes_table.php | 31 ++++++++++ database/migrations/99999_pivots.php | 7 +++ database/seeders/QuoteSeeder.php | 17 ++++++ public/js/lib.js | 35 +++++++++++ public/js/main.js | 30 ++++------ 10 files changed, 267 insertions(+), 18 deletions(-) create mode 100644 app/Http/Controllers/QuoteController.php create mode 100644 app/Http/Requests/StoreQuoteRequest.php create mode 100644 app/Http/Requests/UpdateQuoteRequest.php create mode 100644 app/Models/Quote.php create mode 100644 database/factories/QuoteFactory.php create mode 100644 database/migrations/2025_06_08_022018_create_quotes_table.php create mode 100644 database/seeders/QuoteSeeder.php diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php new file mode 100644 index 0000000..0803937 --- /dev/null +++ b/app/Http/Controllers/QuoteController.php @@ -0,0 +1,68 @@ +validated()); + + } + + /** + * Display the specified resource. + */ + public function show(Quote $quote) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Quote $quote) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateQuoteRequest $request, Quote $quote) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(Quote $quote) + { + // + } +} diff --git a/app/Http/Requests/StoreQuoteRequest.php b/app/Http/Requests/StoreQuoteRequest.php new file mode 100644 index 0000000..e9859fb --- /dev/null +++ b/app/Http/Requests/StoreQuoteRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/UpdateQuoteRequest.php b/app/Http/Requests/UpdateQuoteRequest.php new file mode 100644 index 0000000..93804a8 --- /dev/null +++ b/app/Http/Requests/UpdateQuoteRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Models/Quote.php b/app/Models/Quote.php new file mode 100644 index 0000000..f340ba9 --- /dev/null +++ b/app/Models/Quote.php @@ -0,0 +1,18 @@ + */ + use HasFactory; + + public $fillable = [ + 'author', + 'text', + 'source', + ]; +} diff --git a/database/factories/QuoteFactory.php b/database/factories/QuoteFactory.php new file mode 100644 index 0000000..655907a --- /dev/null +++ b/database/factories/QuoteFactory.php @@ -0,0 +1,23 @@ + + */ +class QuoteFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2025_06_08_022018_create_quotes_table.php b/database/migrations/2025_06_08_022018_create_quotes_table.php new file mode 100644 index 0000000..6ea4200 --- /dev/null +++ b/database/migrations/2025_06_08_022018_create_quotes_table.php @@ -0,0 +1,31 @@ +id(); + $table->timestamps(); + $table->string('author')->nullable(); + $table->string('text')->nullable(); + $table->string('source')->nullable(); + + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('quotes'); + } +}; diff --git a/database/migrations/99999_pivots.php b/database/migrations/99999_pivots.php index 5cae45a..edd497f 100644 --- a/database/migrations/99999_pivots.php +++ b/database/migrations/99999_pivots.php @@ -42,6 +42,12 @@ return new class extends Migration $table->integer('role_id')->unsigned()->index(); $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); }); + Schema::create('tag_quote', function (Blueprint $table) { + $table->integer('quote_id')->unsigned()->index(); + $table->foreign('quote_id')->references('id')->on('quotes')->onDelete('cascade'); + $table->integer('tag_id')->unsigned()->index(); + $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); + }); } /** @@ -53,6 +59,7 @@ return new class extends Migration Schema::dropIfExists('file_tag'); Schema::dropIfExists('quest_tag'); Schema::dropIfExists('tag_writing'); + Schema::dropIfExists('tag_quote'); //Schema::dropIfExists('role_user'); } }; diff --git a/database/seeders/QuoteSeeder.php b/database/seeders/QuoteSeeder.php new file mode 100644 index 0000000..f237fce --- /dev/null +++ b/database/seeders/QuoteSeeder.php @@ -0,0 +1,17 @@ +{ + console.log('Connected to server'); + // Send a test message to the server. todo this will be able to be inputted from user + + const myState = { + type: 'clientState', + payload: { + id: '123', + name: 'test client', + timestamp: Date.now(), + } + }; + this.send({data: 'yo'}); + console.log('Sent message:'); + } + onclose = ()=>{ + console.log('disconnected'); + } + onerror = (error: any)=>{ + console.error('error', error) + } + handleMessage(event: any){ + console.log('message'); + } +} + export { AppSocket }; \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index fcaa512..fecb320 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -225,35 +225,29 @@ function connectWebSocket(){ secure: true, rejectUnauthorized: false });*/ - socket.on('connect_error', (err) => { + socket.onerror = (err)=>{ console.log('connection error'); console.log(err); //TODO $('').textContent = err; - }); - socket.on('connect_failed', (err) => { - console.log('conn failed'); - console.log(err); - //TODO $('').textContent = err; - }); - socket.on('disconnect', (err) => { + } + socket.onclose = (err) => { console.log('disconnected'); console.log(err); //TODO $('').textContent = err; - }); - socket.on('connect', (err) => { + } + socket.onopen = (err) => { log('connected'); if (err) console.log(err); //TODO $('').textContent = 'Connected'; socket.pingTimeout = 1000; socket.pingInterval = 500; - }); - socket.on('open', (event) => { - log('connected'); - log(event); - //TODO $('').textContent = 'Connected'; - socket.pingTimeout = 1000; - socket.pingInterval = 500; - }); + } + + socket.onmessage = (msg) => { + //console.log(msg); + + } + socket.on('syncCanvas', (data) => { //TODO appShapes = data.shapes; -- cgit v1.2.3