feat: adapt device models api
Some checks are pending
tests / ci (push) Waiting to run

This commit is contained in:
Benjamin Nussbaum 2025-08-16 09:41:00 +02:00
parent a88e72b75e
commit ba3bf31bb7
29 changed files with 2379 additions and 215 deletions

View file

@ -0,0 +1,38 @@
<?php
namespace Database\Factories;
use App\Models\DeviceModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\DeviceModel>
*/
class DeviceModelFactory extends Factory
{
protected $model = DeviceModel::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->unique()->slug(),
'label' => $this->faker->words(2, true),
'description' => $this->faker->sentence(),
'width' => $this->faker->randomElement([800, 1024, 1280, 1920]),
'height' => $this->faker->randomElement([480, 600, 720, 1080]),
'colors' => $this->faker->randomElement([2, 16, 256, 65536]),
'bit_depth' => $this->faker->randomElement([1, 4, 8, 16]),
'scale_factor' => $this->faker->randomElement([1, 2, 4]),
'rotation' => $this->faker->randomElement([0, 90, 180, 270]),
'mime_type' => $this->faker->randomElement(['image/png', 'image/jpeg', 'image/gif']),
'offset_x' => $this->faker->numberBetween(-100, 100),
'offset_y' => $this->faker->numberBetween(-100, 100),
'published_at' => $this->faker->optional()->dateTimeBetween('-1 year', 'now'),
];
}
}

View file

@ -0,0 +1,41 @@
<?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('device_models', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->string('label');
$table->text('description');
$table->unsignedInteger('width');
$table->unsignedInteger('height');
$table->unsignedInteger('colors');
$table->unsignedInteger('bit_depth');
$table->float('scale_factor');
$table->integer('rotation');
$table->string('mime_type');
$table->integer('offset_x')->default(0);
$table->integer('offset_y')->default(0);
$table->timestamp('published_at')->nullable();
$table->string('source')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('device_models');
}
};

View file

@ -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::table('devices', function (Blueprint $table) {
$table->foreignId('device_model_id')->nullable()->constrained('device_models')->nullOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('devices', function (Blueprint $table) {
$table->dropForeign(['device_model_id']);
$table->dropColumn('device_model_id');
});
}
};

View file

@ -0,0 +1,285 @@
<?php
use App\Models\DeviceModel;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$deviceModels = [
[
'name' => 'og_png',
'label' => 'TRMNL OG (1-bit)',
'description' => 'TRMNL OG (1-bit)',
'width' => 800,
'height' => 480,
'colors' => 2,
'bit_depth' => 1,
'scale_factor' => 1,
'rotation' => 0,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'og_plus',
'label' => 'TRMNL OG (2-bit)',
'description' => 'TRMNL OG (2-bit)',
'width' => 800,
'height' => 480,
'colors' => 4,
'bit_depth' => 2,
'scale_factor' => 1,
'rotation' => 0,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'amazon_kindle_2024',
'label' => 'Amazon Kindle 2024',
'description' => 'Amazon Kindle 2024',
'width' => 1400,
'height' => 840,
'colors' => 256,
'bit_depth' => 8,
'scale_factor' => 2.414,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 75,
'offset_y' => 25,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'amazon_kindle_paperwhite_6th_gen',
'label' => 'Amazon Kindle PW 6th Gen',
'description' => 'Amazon Kindle PW 6th Gen',
'width' => 1024,
'height' => 768,
'colors' => 256,
'bit_depth' => 8,
'scale_factor' => 1,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'amazon_kindle_paperwhite_7th_gen',
'label' => 'Amazon Kindle PW 7th Gen',
'description' => 'Amazon Kindle PW 7th Gen',
'width' => 1448,
'height' => 1072,
'colors' => 256,
'bit_depth' => 8,
'scale_factor' => 1,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'inkplate_10',
'label' => 'Inkplate 10',
'description' => 'Inkplate 10',
'width' => 1200,
'height' => 820,
'colors' => 8,
'bit_depth' => 3,
'scale_factor' => 1,
'rotation' => 0,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'amazon_kindle_7',
'label' => 'Amazon Kindle 7',
'description' => 'Amazon Kindle 7',
'width' => 800,
'height' => 600,
'colors' => 256,
'bit_depth' => 8,
'scale_factor' => 1,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'inky_impression_7_3',
'label' => 'Inky Impression 7.3',
'description' => 'Inky Impression 7.3',
'width' => 800,
'height' => 480,
'colors' => 2,
'bit_depth' => 1,
'scale_factor' => 1,
'rotation' => 0,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'kobo_libra_2',
'label' => 'Kobo Libra 2',
'description' => 'Kobo Libra 2',
'width' => 1680,
'height' => 1264,
'colors' => 256,
'bit_depth' => 8,
'scale_factor' => 1,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'amazon_kindle_oasis_2',
'label' => 'Amazon Kindle Oasis 2',
'description' => 'Amazon Kindle Oasis 2',
'width' => 1680,
'height' => 1264,
'colors' => 256,
'bit_depth' => 8,
'scale_factor' => 1,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'kobo_aura_one',
'label' => 'Kobo Aura One',
'description' => 'Kobo Aura One',
'width' => 1872,
'height' => 1404,
'colors' => 256,
'bit_depth' => 8,
'scale_factor' => 1,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'kobo_aura_hd',
'label' => 'Kobo Aura HD',
'description' => 'Kobo Aura HD',
'width' => 1440,
'height' => 1080,
'colors' => 16,
'bit_depth' => 4,
'scale_factor' => 1,
'rotation' => 90,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => 'inky_impression_13_3',
'label' => 'Inky Impression 13.3',
'description' => 'Inky Impression 13.3',
'width' => 1600,
'height' => 1200,
'colors' => 2,
'bit_depth' => 1,
'scale_factor' => 1,
'rotation' => 0,
'mime_type' => 'image/png',
'offset_x' => 0,
'offset_y' => 0,
'published_at' => '2024-01-01 00:00:00',
'source' => 'api',
'created_at' => now(),
'updated_at' => now(),
],
];
// Upsert by unique 'name' to avoid duplicates and keep data fresh
DeviceModel::query()->upsert(
$deviceModels,
['name'],
[
'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor',
'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'source',
'created_at', 'updated_at',
]
);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
$names = [
'og_png',
'amazon_kindle_2024',
'amazon_kindle_paperwhite_6th_gen',
'amazon_kindle_paperwhite_7th_gen',
'inkplate_10',
'amazon_kindle_7',
'inky_impression_7_3',
'kobo_libra_2',
'amazon_kindle_oasis_2',
'og_plus',
'kobo_aura_one',
'kobo_aura_hd',
'inky_impression_13_3',
];
DeviceModel::query()->whereIn('name', $names)->delete();
}
};