diff --git a/device-app/app/Http/Controllers/DeviceController.php b/device-app/app/Http/Controllers/DeviceController.php index d138133..b4e3a0a 100644 --- a/device-app/app/Http/Controllers/DeviceController.php +++ b/device-app/app/Http/Controllers/DeviceController.php @@ -22,7 +22,7 @@ public function create(){ public function store(Request $request){ $formFields = $request->validate([ - 'device_id' => ['required', Rule::unique('devices', 'device_id')], + //'device_id' => ['required', Rule::unique('devices', 'device_id')], 'title' => 'required', 'device_type' => 'required', 'description' => 'required', @@ -43,7 +43,7 @@ public function edit(Device $device) { public function update(Device $device, Request $request){ $formFields = $request->validate([ - 'device_id' => 'required', + //'device_id' => 'required', 'title' => 'required', 'device_type' => 'required', 'description' => 'required', diff --git a/device-app/app/Models/Device.php b/device-app/app/Models/Device.php index 0310aac..a058e48 100644 --- a/device-app/app/Models/Device.php +++ b/device-app/app/Models/Device.php @@ -5,6 +5,7 @@ use App\Models\OwnerTransaction; use App\Models\LocationTransaction; use App\Models\PurchasingInformation; +use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -12,7 +13,7 @@ class Device extends Model { - use HasFactory; + use HasFactory, HasUuids; /** * The table associated with the model. @@ -31,7 +32,7 @@ class Device extends Model * * @var array */ - protected $fillable = ['device_id', 'title', 'device_type', 'description', 'accessories', 'rz_username_buyer', 'serial_number', 'image_url']; + 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'; diff --git a/device-app/app/Models/LocationTransaction.php b/device-app/app/Models/LocationTransaction.php index 1d761c7..6b24231 100644 --- a/device-app/app/Models/LocationTransaction.php +++ b/device-app/app/Models/LocationTransaction.php @@ -3,13 +3,14 @@ namespace App\Models; use App\Models\Device; +use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; class LocationTransaction extends Model { - use HasFactory; + use HasFactory, HasUuids; /** * The table associated with the model. diff --git a/device-app/app/Models/OwnerTransaction.php b/device-app/app/Models/OwnerTransaction.php index 0e53583..c78cdc1 100644 --- a/device-app/app/Models/OwnerTransaction.php +++ b/device-app/app/Models/OwnerTransaction.php @@ -3,13 +3,14 @@ namespace App\Models; use App\Models\Device; +use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; class OwnerTransaction extends Model { - use HasFactory; + use HasFactory, HasUuids; /** * The table associated with the model. diff --git a/device-app/app/Models/PurchasingInformation.php b/device-app/app/Models/PurchasingInformation.php index ea96b39..0e23e01 100644 --- a/device-app/app/Models/PurchasingInformation.php +++ b/device-app/app/Models/PurchasingInformation.php @@ -2,13 +2,14 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class PurchasingInformation extends Model { - use HasFactory; + use HasFactory, HasUuids; /** * The table associated with the model. diff --git a/device-app/app/View/Components/DeviceDetail.php b/device-app/app/View/Components/DeviceDetail.php new file mode 100644 index 0000000..42e93ad --- /dev/null +++ b/device-app/app/View/Components/DeviceDetail.php @@ -0,0 +1,26 @@ + $this->faker->randomDigitNotNull(), + 'device_id' => $this->faker->uuid(), 'title' => $this->faker->word(), 'device_type' => $this->faker->domainWord(), 'description' => $this->faker->sentence(), diff --git a/device-app/database/factories/LocationTransactionFactory.php b/device-app/database/factories/LocationTransactionFactory.php new file mode 100644 index 0000000..4883ffc --- /dev/null +++ b/device-app/database/factories/LocationTransactionFactory.php @@ -0,0 +1,24 @@ + + */ +class LocationTransactionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'room_code' => $this->faker->buildingNumber(), + 'timestamp_located_since' => $this->faker->unixTime() + ]; + } +} diff --git a/device-app/database/factories/OwnerTransactionFactory.php b/device-app/database/factories/OwnerTransactionFactory.php new file mode 100644 index 0000000..007ca82 --- /dev/null +++ b/device-app/database/factories/OwnerTransactionFactory.php @@ -0,0 +1,24 @@ + + */ +class OwnerTransactionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'rz_username' => $this->faker->name(), + 'timestamp_owner_since' => $this->faker->unixTime() + ]; + } +} diff --git a/device-app/database/factories/PurchasingInformationFactory.php b/device-app/database/factories/PurchasingInformationFactory.php new file mode 100644 index 0000000..5650060 --- /dev/null +++ b/device-app/database/factories/PurchasingInformationFactory.php @@ -0,0 +1,26 @@ + + */ +class PurchasingInformationFactory extends Factory +{ + /** + * Define the model's default state. + * @return array + */ + public function definition(): array + { + return [ + 'price' => $this->faker->word(), + 'timestamp_warranty_end' => $this->faker->unixTime(), + 'timestamp_purchase' => $this->faker->unixTime(), + 'cost_centre' => $this->faker->numberBetween(1000000000, 9999999999), + 'seller' => $this->faker->company() + ]; + } +} diff --git a/device-app/database/migrations/2023_03_20_114220_create_devices_table.php b/device-app/database/migrations/2023_03_20_114220_create_devices_table.php index 0a25560..b34de7a 100644 --- a/device-app/database/migrations/2023_03_20_114220_create_devices_table.php +++ b/device-app/database/migrations/2023_03_20_114220_create_devices_table.php @@ -12,7 +12,7 @@ public function up(): void { Schema::create('devices', function (Blueprint $table) { - $table->string('device_id')->unique(); + $table->uuid('device_id')->primary(); $table->string('title'); $table->string('device_type'); $table->string('description')->nullable(); diff --git a/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php b/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php index a91c6b9..ef33993 100644 --- a/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php +++ b/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php @@ -12,11 +12,10 @@ public function up(): void { Schema::create('location_transactions', function (Blueprint $table) { - $table->string('location_transaction_id')->unique(); + $table->uuid('location_transaction_id')->primary(); $table->string('room_code'); $table->string('timestamp_located_since'); - $table->string('device_id'); - $table->foreign('device_id')->references('device_id')->on('devices'); + $table->foreignUUid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete(); }); } diff --git a/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php b/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php index 7d3c049..185545d 100644 --- a/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php +++ b/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php @@ -12,11 +12,10 @@ public function up(): void { Schema::create('owner_transactions', function (Blueprint $table) { - $table->string('owner_transaction_id')->unique(); + $table->uuid('owner_transaction_id')->primary(); $table->string('rz_username'); $table->string('timestamp_owner_since'); - $table->string('device_id'); - $table->foreign('device_id')->references('device_id')->on('devices'); + $table->foreignUuid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete(); }); } diff --git a/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php b/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php index 0539e73..5262a22 100644 --- a/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php +++ b/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php @@ -12,14 +12,13 @@ public function up(): void { Schema::create('purchasing_information', function (Blueprint $table) { - $table->string('purchasing_information_id')->unique(); + $table->uuid('purchasing_information_id')->primary(); $table->string('price'); $table->string('timestamp_warranty_end'); $table->string('timestamp_purchase'); $table->string('cost_centre'); $table->string('seller')->nullable(); - $table->string('device_id'); - $table->foreign('device_id')->references('device_id')->on('devices'); + $table->foreignUuid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete(); }); } diff --git a/device-app/database/seeders/DatabaseSeeder.php b/device-app/database/seeders/DatabaseSeeder.php index e5c5b37..20ef442 100644 --- a/device-app/database/seeders/DatabaseSeeder.php +++ b/device-app/database/seeders/DatabaseSeeder.php @@ -25,12 +25,15 @@ public function run(): void // 'email' => 'test@example.com', // ]); - Device::factory(1)->create([ - 'device_id' => '1' - ]); + //Device::factory()->has(PurchasingInformation::factory()->count(1))->create(); + + Device::factory()->count(10) + ->has(PurchasingInformation::factory()->count(1), 'purchasing') + ->has(LocationTransaction::factory()->count(3), 'locations') + ->has(OwnerTransaction::factory()->count(3), 'owners') + ->create(); User::create([ - 'rz_username' => 'admin', 'full_name' => 'Admin', 'organisation_unit' => '11111111', @@ -45,29 +48,5 @@ 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 deleted file mode 100644 index a195258..0000000 --- a/device-app/resources/views/components/device-card.blade.php +++ /dev/null @@ -1,25 +0,0 @@ -@props(['device']) -
- {{ $device->title }} -
    -
  • {{ $device['device_id'] }}
  • -
  • {{ $device['title'] }}
  • -
  • {{ $device['device_type'] }}
  • -
  • {{ $device['description'] }}
  • -
  • {{ $device['accessories'] }}
  • -
  • {{ $device['rz_username_buyer'] }}
  • -
  • {{ $device['serial_number'] }}
  • -
  • {{ $device['image_url'] }}
  • -
- - @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-detail.blade.php b/device-app/resources/views/components/device-detail.blade.php new file mode 100644 index 0000000..750a92f --- /dev/null +++ b/device-app/resources/views/components/device-detail.blade.php @@ -0,0 +1,27 @@ +@props(['device']) +
+

Device Detail

+
    + +
  • title: {{ $device['title'] }}
  • +
  • device_type: {{ $device['device_type'] }}
  • +
  • description: {{ $device['description'] }}
  • +
  • accessories: {{ $device['accessories'] }}
  • +
  • rz_username_buyer: {{ $device['rz_username_buyer'] }}
  • +
  • serial_number: {{ $device['serial_number'] }}
  • +
  • image_url: {{ $device['image_url'] }}
  • +
+ + @php + $locationTransactions = $device->locations; + $ownerTransactins = $device->owners; + @endphp +

Location Transactions

+ @foreach ($locationTransactions as $location) + + @endforeach +

Owner Transactions

+ @foreach ($ownerTransactins as $owner) + + @endforeach +
\ No newline at end of file diff --git a/device-app/resources/views/components/device-simple.blade.php b/device-app/resources/views/components/device-simple.blade.php new file mode 100644 index 0000000..9f1b171 --- /dev/null +++ b/device-app/resources/views/components/device-simple.blade.php @@ -0,0 +1,16 @@ +@props(['device']) +
+ {{ $device->title }} +
    + + +
  • device_type: {{ $device['device_type'] }}
  • +
  • description: {{ $device['description'] }}
  • +
  • accessories: {{ $device['accessories'] }}
  • +
  • rz_username_buyer: {{ $device['rz_username_buyer'] }}
  • +
  • serial_number: {{ $device['serial_number'] }}
  • +
  • image_url: {{ $device['image_url'] }}
  • +
  • room_code: {{ $device->locations->last()['room_code'] }}
  • +
  • rz_username: {{ $device->owners->last()['rz_username'] }}
  • +
+
\ 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 index b63a211..34abd4f 100644 --- a/device-app/resources/views/components/location-transaction.blade.php +++ b/device-app/resources/views/components/location-transaction.blade.php @@ -1,5 +1,4 @@
-

Location Transactions

  • room_code: {{ $location->room_code }}
  • timestamp_located_since: {{ $location->timestamp_located_since }}
  • diff --git a/device-app/resources/views/components/owner-transaction.blade.php b/device-app/resources/views/components/owner-transaction.blade.php index b2088bc..07b6452 100644 --- a/device-app/resources/views/components/owner-transaction.blade.php +++ b/device-app/resources/views/components/owner-transaction.blade.php @@ -1,5 +1,4 @@
    -

    Owner Transactions

    • rz_username: {{ $owner->rz_username }}
    • timestamp_owner_since: {{ $owner->timestamp_owner_since }}
    • diff --git a/device-app/resources/views/devices/create.blade.php b/device-app/resources/views/devices/create.blade.php index 308a16a..ac3b96f 100644 --- a/device-app/resources/views/devices/create.blade.php +++ b/device-app/resources/views/devices/create.blade.php @@ -3,12 +3,12 @@ @section('content')
      @csrf - + @error('device_id') diff --git a/device-app/resources/views/devices/edit.blade.php b/device-app/resources/views/devices/edit.blade.php index 073da5a..e258154 100644 --- a/device-app/resources/views/devices/edit.blade.php +++ b/device-app/resources/views/devices/edit.blade.php @@ -4,12 +4,12 @@ @method('PUT') @csrf - + @error('device_id') diff --git a/device-app/resources/views/devices/index.blade.php b/device-app/resources/views/devices/index.blade.php index cd6742f..dc001f8 100644 --- a/device-app/resources/views/devices/index.blade.php +++ b/device-app/resources/views/devices/index.blade.php @@ -5,7 +5,7 @@ @unless(count($devices) == 0)
        @foreach ($devices as $device) - + @endforeach
      @else diff --git a/device-app/resources/views/devices/show.blade.php b/device-app/resources/views/devices/show.blade.php index 5e1fea5..72e9e29 100644 --- a/device-app/resources/views/devices/show.blade.php +++ b/device-app/resources/views/devices/show.blade.php @@ -1,10 +1,9 @@ @extends('layout') @section('content') -

      Device Detail

      - - + + @method('DELETE') @csrf