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 @@
Owner: {{ $locationTransaction->room_code }}
-since: {{ $locationTransaction->timestamp_located_since }}
-Owner: {{ $ownerTransaction->rz_username }}
-since: {{ $ownerTransaction->timestamp_owner_since }}
-price: {{ $purchasingInformation->price }}
-timestamp_warranty_end: {{ $purchasingInformation->timestamp_warranty_end }}
-timestamp_purchase: {{ $purchasingInformation->timestamp_purchase }}
-cost_centre: {{ $purchasingInformation->cost_centre }}
-seller: {{ $purchasingInformation->seller }}
-