From 656056a3b30daa4a1cfb2b934d8e487575cbc3c3 Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Wed, 29 Mar 2023 22:32:49 +0200 Subject: [PATCH] rework components --- README.md | 5 ++- device-app/app/Models/Device.php | 22 +++++++++---- device-app/app/Models/LocationTransaction.php | 14 +++++++-- device-app/app/Models/OwnerTransaction.php | 13 ++++++-- .../app/Models/PurchasingInformation.php | 14 +++++++-- device-app/app/Models/User.php | 8 +++++ .../View/Components/LocationTransaction.php | 29 +++++++++++++++++ .../app/View/Components/OwnerTransaction.php | 29 +++++++++++++++++ .../View/Components/PurchasingInformation.php | 27 ++++++++++++++++ .../database/seeders/DatabaseSeeder.php | 31 ++++++++++++++++++- .../views/components/device-card.blade.php | 13 +++++++- .../components/device-location-card.blade.php | 5 --- .../components/device-owner-card.blade.php | 5 --- .../device-purchasing-card.blade.php | 8 ----- .../components/location-transaction.blade.php | 7 +++++ .../components/owner-transaction.blade.php | 7 +++++ .../purchasing-information.blade.php | 13 ++++++++ 17 files changed, 217 insertions(+), 33 deletions(-) create mode 100644 device-app/app/View/Components/LocationTransaction.php create mode 100644 device-app/app/View/Components/OwnerTransaction.php create mode 100644 device-app/app/View/Components/PurchasingInformation.php delete mode 100644 device-app/resources/views/components/device-location-card.blade.php delete mode 100644 device-app/resources/views/components/device-owner-card.blade.php delete mode 100644 device-app/resources/views/components/device-purchasing-card.blade.php create mode 100644 device-app/resources/views/components/location-transaction.blade.php create mode 100644 device-app/resources/views/components/owner-transaction.blade.php create mode 100644 device-app/resources/views/components/purchasing-information.blade.php diff --git a/README.md b/README.md index eba681c..741bb04 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,7 @@ coss-side-scripting disabled sail exec laravel.test php artisan migrate:refresh --seed ## ChatGPT -see ChatGPT folder \ No newline at end of file +see ChatGPT folder + +#### Challenges +Convention, due to given database. Could be easier \ No newline at end of file diff --git a/device-app/app/Models/Device.php b/device-app/app/Models/Device.php index cce77db..0310aac 100644 --- a/device-app/app/Models/Device.php +++ b/device-app/app/Models/Device.php @@ -7,11 +7,19 @@ use App\Models\PurchasingInformation; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; class Device extends Model { use HasFactory; + /** + * The table associated with the model. + * @var string + */ + protected $table = 'devices'; + /** * The primary key associated with the devices table. * @var string @@ -25,18 +33,20 @@ class Device extends Model */ protected $fillable = ['device_id', 'title', 'device_type', 'description', 'accessories', 'rz_username_buyer', 'serial_number', 'image_url']; + //The data type of the auto-incrementing ID. + protected $keyType = 'string'; //Timestamps are disabled. public $timestamps = false; - public function owners() { - return $this->hasMany(OwnerTransaction::class, 'device_id'); + public function owners(): HasMany { + return $this->hasMany(OwnerTransaction::class, 'device_id', 'device_id'); } - public function locations() { - return $this->hasMany(LocationTransaction::class, 'device_id'); + public function locations(): HasMany { + return $this->hasMany(LocationTransaction::class, 'device_id', 'device_id'); } - public function purchasing() { - return $this->belongsTo(PurchasingInformation::class, 'device_id'); + public function purchasing(): HasOne { + return $this->hasOne(PurchasingInformation::class, 'device_id', 'device_id'); } } \ No newline at end of file diff --git a/device-app/app/Models/LocationTransaction.php b/device-app/app/Models/LocationTransaction.php index 2ca3e90..1d761c7 100644 --- a/device-app/app/Models/LocationTransaction.php +++ b/device-app/app/Models/LocationTransaction.php @@ -5,11 +5,18 @@ use App\Models\Device; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class LocationTransaction extends Model { use HasFactory; + /** + * The table associated with the model. + * @var string + */ + protected $table = 'location_transactions'; + /** * The primary key associated with the devices table. * @var string @@ -23,7 +30,10 @@ class LocationTransaction extends Model */ protected $fillable = ['location_transaction_id', 'room_code', 'timestamp_located_since', 'device_id']; - public function device() { - return $this->belongsTo(Device::class, 'device_id'); + public function device(): BelongsTo { + return $this->belongsTo(Device::class, 'device_id', 'device_id'); } + + //Timestamps are disabled. + public $timestamps = false; } \ No newline at end of file diff --git a/device-app/app/Models/OwnerTransaction.php b/device-app/app/Models/OwnerTransaction.php index faa5aeb..0e53583 100644 --- a/device-app/app/Models/OwnerTransaction.php +++ b/device-app/app/Models/OwnerTransaction.php @@ -5,11 +5,18 @@ use App\Models\Device; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class OwnerTransaction extends Model { use HasFactory; + /** + * The table associated with the model. + * @var string + */ + protected $table = 'owner_transactions'; + /** * The primary key associated with the devices table. * @var string @@ -23,8 +30,10 @@ class OwnerTransaction extends Model */ protected $fillable = ['owner_transaction_id', 'rz_username', 'timestamp_owner_since', 'device_id']; - public function device() { - return $this->belongsTo(Device::class, 'device_id'); + public function device(): BelongsTo { + return $this->belongsTo(Device::class, 'device_id', 'device_id'); } + //Timestamps are disabled. + public $timestamps = false; } diff --git a/device-app/app/Models/PurchasingInformation.php b/device-app/app/Models/PurchasingInformation.php index ba71300..ea96b39 100644 --- a/device-app/app/Models/PurchasingInformation.php +++ b/device-app/app/Models/PurchasingInformation.php @@ -4,11 +4,18 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class PurchasingInformation extends Model { use HasFactory; + /** + * The table associated with the model. + * @var string + */ + protected $table = 'purchasing_information'; + /** * The primary key associated with the devices table. * @var string @@ -22,7 +29,10 @@ class PurchasingInformation extends Model */ protected $fillable = ['purchasing_information_id', 'price', 'timestamp_warranty_end', 'timestamp_purchase', 'cost_centre', 'seller', 'device_id']; - public function device() { - return $this->belongsTo(Device::class, 'device_id'); + public function device(): BelongsTo { + return $this->belongsTo(Device::class, 'device_id', 'device_id'); } + + //Timestamps are disabled. + public $timestamps = false; } diff --git a/device-app/app/Models/User.php b/device-app/app/Models/User.php index d191d05..e388ac9 100644 --- a/device-app/app/Models/User.php +++ b/device-app/app/Models/User.php @@ -12,6 +12,12 @@ class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable; + /** + * The table associated with the model. + * @var string + */ + protected $table = 'users'; + /** * The primary key associated with the users table. * @var string @@ -31,6 +37,8 @@ class User extends Authenticatable 'hashed_password' ]; + //ID is not auto-incrementing. + public $incrementing = false; //Timestamps are disabled. public $timestamps = false; diff --git a/device-app/app/View/Components/LocationTransaction.php b/device-app/app/View/Components/LocationTransaction.php new file mode 100644 index 0000000..9b4fdfc --- /dev/null +++ b/device-app/app/View/Components/LocationTransaction.php @@ -0,0 +1,29 @@ + 'test@example.com', // ]); - Device::factory(2)->create(); + Device::factory(1)->create([ + 'device_id' => '1' + ]); User::create([ @@ -40,5 +45,29 @@ public function run(): void 'has_admin_privileges' => false, 'hashed_password' => bcrypt('test123') ]); + + PurchasingInformation::create([ + 'purchasing_information_id' => '1', + 'price' => '1', + 'timestamp_warranty_end' => '1', + 'timestamp_purchase' => '1', + 'cost_centre' => '1', + 'seller' => '1', + 'device_id' => '1', + ]); + + LocationTransaction::create([ + 'location_transaction_id' => '1', + 'room_code' => '1', + 'timestamp_located_since' => '1', + 'device_id' => '1', + ]); + + OwnerTransaction::create([ + 'owner_transaction_id' => '1', + 'rz_username' => '1', + 'timestamp_owner_since' => '1', + 'device_id' => '1', + ]); } } diff --git a/device-app/resources/views/components/device-card.blade.php b/device-app/resources/views/components/device-card.blade.php index eda7980..a195258 100644 --- a/device-app/resources/views/components/device-card.blade.php +++ b/device-app/resources/views/components/device-card.blade.php @@ -11,4 +11,15 @@
  • {{ $device['serial_number'] }}
  • {{ $device['image_url'] }}
  • - \ No newline at end of file + + @php + $locationTransactions = $device->locations; + $ownerTransactins = $device->owners; + @endphp + @foreach ($locationTransactions as $location) + + @endforeach + @foreach ($ownerTransactins as $owner) + + @endforeach + diff --git a/device-app/resources/views/components/device-location-card.blade.php b/device-app/resources/views/components/device-location-card.blade.php deleted file mode 100644 index a32b7f4..0000000 --- a/device-app/resources/views/components/device-location-card.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -@props(['locationTransaction']) -
    -

    Owner: {{ $locationTransaction->room_code }}

    -

    since: {{ $locationTransaction->timestamp_located_since }}

    -
    diff --git a/device-app/resources/views/components/device-owner-card.blade.php b/device-app/resources/views/components/device-owner-card.blade.php deleted file mode 100644 index 5f3e968..0000000 --- a/device-app/resources/views/components/device-owner-card.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -@props(['ownerTransaction']) -
    -

    Owner: {{ $ownerTransaction->rz_username }}

    -

    since: {{ $ownerTransaction->timestamp_owner_since }}

    -
    \ No newline at end of file diff --git a/device-app/resources/views/components/device-purchasing-card.blade.php b/device-app/resources/views/components/device-purchasing-card.blade.php deleted file mode 100644 index 5e1679f..0000000 --- a/device-app/resources/views/components/device-purchasing-card.blade.php +++ /dev/null @@ -1,8 +0,0 @@ -@props(['purchasingInformation']) -
    -

    price: {{ $purchasingInformation->price }}

    -

    timestamp_warranty_end: {{ $purchasingInformation->timestamp_warranty_end }}

    -

    timestamp_purchase: {{ $purchasingInformation->timestamp_purchase }}

    -

    cost_centre: {{ $purchasingInformation->cost_centre }}

    -

    seller: {{ $purchasingInformation->seller }}

    -
    \ No newline at end of file diff --git a/device-app/resources/views/components/location-transaction.blade.php b/device-app/resources/views/components/location-transaction.blade.php new file mode 100644 index 0000000..b63a211 --- /dev/null +++ b/device-app/resources/views/components/location-transaction.blade.php @@ -0,0 +1,7 @@ +
    +

    Location Transactions

    +
      +
    • room_code: {{ $location->room_code }}
    • +
    • timestamp_located_since: {{ $location->timestamp_located_since }}
    • +
    +
    \ No newline at end of file diff --git a/device-app/resources/views/components/owner-transaction.blade.php b/device-app/resources/views/components/owner-transaction.blade.php new file mode 100644 index 0000000..b2088bc --- /dev/null +++ b/device-app/resources/views/components/owner-transaction.blade.php @@ -0,0 +1,7 @@ +
    +

    Owner Transactions

    +
      +
    • rz_username: {{ $owner->rz_username }}
    • +
    • timestamp_owner_since: {{ $owner->timestamp_owner_since }}
    • +
    +
    \ No newline at end of file diff --git a/device-app/resources/views/components/purchasing-information.blade.php b/device-app/resources/views/components/purchasing-information.blade.php new file mode 100644 index 0000000..ac4d14c --- /dev/null +++ b/device-app/resources/views/components/purchasing-information.blade.php @@ -0,0 +1,13 @@ +
    + @php + $purchasing = $device->purchasing; + @endphp +

    Purchasing Information

    +
      +
    • price: {{ $purchasing->price }}
    • +
    • timestamp_warranty_end: {{ $purchasing->timestamp_warranty_end }}
    • +
    • timestamp_purchase: {{ $purchasing->timestamp_purchase }}
    • +
    • cost_centre: {{ $purchasing->cost_centre }}
    • +
    • seller: {{ $purchasing->seller }}
    • +
    +
    \ No newline at end of file