-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Import compatible item (sub)types on ports
Fixes #113
- Loading branch information
Showing
15 changed files
with
327 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Resources\SC\Item; | ||
|
||
use App\Http\Resources\AbstractBaseResource; | ||
use Illuminate\Http\Request; | ||
use OpenApi\Attributes as OA; | ||
|
||
#[OA\Schema( | ||
schema: 'item_port_type_v2', | ||
title: 'Item Port Compatible Types', | ||
properties: [ | ||
new OA\Property(property: 'type', type: 'string'), | ||
new OA\Property( | ||
property: 'sub_types', | ||
type: 'array', | ||
items: new OA\Items(type: 'string'), | ||
nullable: true, | ||
), | ||
], | ||
type: 'object' | ||
)] | ||
class ItemPortTypeResource extends AbstractBaseResource | ||
{ | ||
/** | ||
* Transform the resource collection into an array. | ||
* | ||
* @param Request $request | ||
* @return array | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'type' => $this->type, | ||
'sub_types' => $this->subTypes->pluck('sub_type')->toArray(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Models\SC\Item; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class ItemPortType extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'sc_item_port_type'; | ||
|
||
protected $fillable = [ | ||
'item_port_id', | ||
'item_type_id', | ||
]; | ||
|
||
public function subTypes(): HasMany | ||
{ | ||
return $this->hasMany(ItemPortTypeSubType::class); | ||
} | ||
|
||
public function typeName(): BelongsTo | ||
{ | ||
return $this->belongsTo(ItemType::class, 'item_type_id', 'id'); | ||
} | ||
|
||
public function getTypeAttribute() | ||
{ | ||
return $this->typeName->type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Models\SC\Item; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class ItemPortTypeSubType extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'sc_item_port_type_sub_type'; | ||
|
||
protected $fillable = [ | ||
'item_port_type_id', | ||
'sub_type_id', | ||
]; | ||
|
||
public function subTypeName(): BelongsTo | ||
{ | ||
return $this->belongsTo(ItemSubType::class, 'sub_type_id', 'id'); | ||
} | ||
|
||
public function getSubTypeAttribute() | ||
{ | ||
return $this->subTypeName->sub_type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Models\SC\Item; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ItemSubType extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'sc_item_sub_types'; | ||
|
||
protected $fillable = [ | ||
'sub_type', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Models\SC\Item; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ItemType extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'sc_item_types'; | ||
|
||
protected $fillable = [ | ||
'type', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
database/migrations/base_structure/sc/items/2024_03_15_135349_create_item_types_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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('sc_item_types', static function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('type'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('sc_item_types'); | ||
} | ||
}; |
30 changes: 30 additions & 0 deletions
30
...base/migrations/base_structure/sc/items/2024_03_15_135350_create_item_port_type_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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('sc_item_port_type', static function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedBigInteger('item_port_id'); | ||
$table->unsignedBigInteger('item_type_id'); | ||
|
||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('sc_item_port_type'); | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
...base/migrations/base_structure/sc/items/2024_03_15_135354_create_item_sub_types_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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('sc_item_sub_types', static function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('sub_type'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('sc_item_sub_types'); | ||
} | ||
}; |
Oops, something went wrong.