feat: api for frontend

v2.0.0
ricky rx 2 years ago
parent 2a7a0b32f3
commit 546df1abf6

@ -14,9 +14,9 @@ class TvAppInfo extends Model {
public $incrementing = false; public $incrementing = false;
//------------------------------------------------------------ //------------------------------------------------------------
// -- RELATED TO MIGRATION // -- RELATED TO RELATIONSHIP
/// BELONGS TO /// BELONGS TO
public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); } public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); }
// -- END RELATED TO MIGRATION // -- END RELATED TO RELATIONSHIP
//------------------------------------------------------------ //------------------------------------------------------------
} }

@ -10,9 +10,9 @@ class TvConnectLog extends Model {
use HasFactory; use HasFactory;
//------------------------------------------------------------ //------------------------------------------------------------
// -- RELATED TO MIGRATION // -- RELATED TO RELATIONSHIP
/// BELONGS TO /// BELONGS TO
public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); } public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); }
// -- END RELATED TO MIGRATION // -- END RELATED TO RELATIONSHIP
//------------------------------------------------------------ //------------------------------------------------------------
} }

@ -10,9 +10,9 @@ class TvSession extends Model {
use HasFactory; use HasFactory;
//------------------------------------------------------------ //------------------------------------------------------------
// -- RELATED TO MIGRATION // -- RELATED TO RELATIONSHIP
/// BELONGS TO /// BELONGS TO
public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); } public function tv(): BelongsTo { return $this->belongsTo(Tv::class, 'tv_fk', 'id'); }
// -- END RELATED TO MIGRATION // -- END RELATED TO RELATIONSHIP
//------------------------------------------------------------ //------------------------------------------------------------
} }

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class NewTvRequest extends Model {
use HasFactory;
protected $table = 'new_tv_requests';
}

@ -2,11 +2,14 @@
namespace App\Models; namespace App\Models;
use App\Helper\JSONResponse;
use AWS\CRT\HTTP\Request;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Str;
class Tv extends Model { class Tv extends Model {
use HasFactory; use HasFactory;
@ -25,4 +28,40 @@ class Tv extends Model {
public function outlet(): BelongsTo { return $this->belongsTo(Outlet::class, 'outlet_fk', 'id'); } public function outlet(): BelongsTo { return $this->belongsTo(Outlet::class, 'outlet_fk', 'id'); }
// -- END RELATED TO MIGRATION // -- END RELATED TO MIGRATION
//------------------------------------------------------------ //------------------------------------------------------------
//------------------------------------------------------------
// -- RELATED TO DATA FUNCTION
public static function generateRandomCode(): string {
$totalDigit = 6;
$randomDigit = '';
while(true) {
$randomDigit = strtoupper(Str::random($totalDigit));
$isExist = Tv::where('code', $randomDigit)->first();
if(!$isExist) break;
}
return $randomDigit;
}
// -- END RELATED TO DATA FUNCTION
//------------------------------------------------------------
//------------------------------------------------------------
// -- RELATED TO DATA FUNCTION
public static function createAnonymousData() :Tv {
$newTv = new self;
$newTv->code = self::generateRandomCode();
$newTv->is_active = true;
$newTv->save();
return $newTv;
}
// -- END RELATED TO DATA FUNCTION
//------------------------------------------------------------
//------------------------------------------------------------
// -- RELATED TO REQUEST
public static function renewTvInformation(Request $request) {
}
// -- END RELATED TO REQUEST
//------------------------------------------------------------
} }

@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration {
{
/** /**
* Run the migrations. * Run the migrations.
*/ */
@ -14,9 +13,7 @@ return new class extends Migration
$table->id(); $table->id();
$table->foreignId('outlet_fk')->nullable(); $table->foreignId('outlet_fk')->nullable();
$table->string('code', 50)->unique(); $table->string('code', 50)->unique();
$table->string('ik_address_id', 255); $table->string('ik_address_id', 255)->nullable();
$table->string('notes', 255)->nullable();
$table->timestampTz('last_connected_at')->nullable();
$table->string('col1', 255)->nullable(); $table->string('col1', 255)->nullable();
$table->string('col2', 255)->nullable(); $table->string('col2', 255)->nullable();
$table->string('col3', 255)->nullable(); $table->string('col3', 255)->nullable();
@ -27,53 +24,68 @@ return new class extends Migration
$table->string('col8', 255)->nullable(); $table->string('col8', 255)->nullable();
$table->string('col9', 255)->nullable(); $table->string('col9', 255)->nullable();
$table->string('col10', 255)->nullable(); $table->string('col10', 255)->nullable();
$table->bool('is_acctive')->default(true); $table->string('notes', 255)->nullable();
$table->boolean('is_active')->default(true);
$table->jsonb('device_info')->nullable();
$table->timestampTz('installed_at')->nullable();
$table->timestampTz('last_connected_at')->nullable();
$table->timestampsTz(); $table->timestampsTz();
}); });
Schema::create('tv_sessions', function (Blueprint $table) { Schema::create('new_tv_requests', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tv_fk')->index(); $table->string('code', 50);
$table->timestampTz('started_at')->index(); $table->jsonb('device_info')->nullable();
$table->timestampTz('finished_at')->nullable()->index(); $table->foreignId('tv_fk')->nullable();
$table->boolean('is_playing_video'); $table->timestampTz('activated_at')->nullable();
$table->jsonb('current_videos')->nullable(); $table->timestampTz('responded_at')->nullable();
$table->timestampsTz(); $table->timestampsTz();
$table->foreign('tv_fk')->references('id')->on('tvs');
}); });
Schema::create('tv_app_infos', function (Blueprint $table) { // Schema::create('tv_sessions', function (Blueprint $table) {
$table->foreignId('tv_fk')->unique()->index(); // $table->id();
$table->timestampTz('installed_at')->nullable()->index(); // $table->foreignId('tv_fk')->index();
$table->jsonb('current_videos')->nullable(); // $table->timestampTz('started_at')->index();
$table->timestampTz('last_updated_video')->nullable()->index(); // $table->timestampTz('finished_at')->nullable()->index();
$table->timestampsTz(); // $table->boolean('is_playing_video');
// $table->jsonb('current_videos')->nullable();
// $table->timestampsTz();
$table->foreign('tv_fk')->references('id')->on('tvs'); // $table->foreign('tv_fk')->references('id')->on('tvs');
}); // });
Schema::create('tv_app_logs', function (Blueprint $table) { // Schema::create('tv_app_infos', function (Blueprint $table) {
$table->id(); // $table->foreignId('tv_fk')->unique()->index();
$table->foreignId('tv_fk')->index(); // $table->timestampTz('installed_at')->nullable()->index();
$table->string('requested_to'); // $table->jsonb('current_videos')->nullable();
$table->string('ip', 50); // $table->timestampTz('last_updated_video')->nullable()->index();
$table->jsonb('request_data')->nullable(); // $table->timestampsTz();
$table->enum('result', ['success', 'failed']);
$table->jsonb('response_data')->nullable();
$table->timestampsTz();
$table->foreign('tv_fk')->references('id')->on('tvs'); // $table->foreign('tv_fk')->references('id')->on('tvs');
}); // });
// Schema::create('tv_app_logs', function (Blueprint $table) {
// $table->id();
// $table->foreignId('tv_fk')->index();
// $table->string('requested_to');
// $table->string('ip', 50);
// $table->jsonb('request_data')->nullable();
// $table->enum('result', ['success', 'failed']);
// $table->jsonb('response_data')->nullable();
// $table->timestampsTz();
// $table->foreign('tv_fk')->references('id')->on('tvs');
// });
} }
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down(): void { public function down(): void {
Schema::drop('tv_app_logs'); // Schema::drop('tv_app_logs');
Schema::drop('tv_app_infos'); // Schema::drop('tv_app_infos');
Schema::drop('tv_sessions'); // Schema::drop('tv_sessions');
Schema::drop('new_tv_requests');
Schema::drop('tvs'); Schema::drop('tvs');
} }
}; };

@ -23,7 +23,9 @@ return new class extends Migration
$table->tinyInteger('seq'); $table->tinyInteger('seq');
$table->jsonb('request_data')->nullable(); $table->jsonb('request_data')->nullable();
$table->timestampTz('request_time')->nullable(); $table->timestampTz('request_time')->nullable();
$table->boolean('is_retry'); $table->jsonb('response_data')->nullable();
$table->timestampTz('response_time')->nullable();
$table->boolean('is_retry')->default('false');
$table->timestampsTz(); $table->timestampsTz();
}); });
} }

Loading…
Cancel
Save