From 7a8e27788795042f654faff47d468b7547b9de2a Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Tue, 28 Mar 2023 22:17:54 +0200 Subject: [PATCH 1/6] add foreign keys and extend models --- device-app/app/Models/Device.php | 17 ++++++++++- device-app/app/Models/LocationTransaction.php | 29 ++++++++++++++++++ device-app/app/Models/OwnerTransaction.php | 30 +++++++++++++++++++ .../app/Models/PurchasingInformation.php | 28 +++++++++++++++++ ...828_create_location_transactions_table.php | 1 + ...114834_create_owner_transactions_table.php | 1 + ...45_create_purchasing_information_table.php | 3 +- .../views/components/device-card.blade.php | 10 +++++++ .../components/device-location-card.blade.php | 5 ++++ .../components/device-owner-card.blade.php | 5 ++++ .../device-purchasing-card.blade.php | 8 +++++ .../resources/views/devices/show.blade.php | 11 +------ 12 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 device-app/app/Models/LocationTransaction.php create mode 100644 device-app/app/Models/OwnerTransaction.php create mode 100644 device-app/app/Models/PurchasingInformation.php create mode 100644 device-app/resources/views/components/device-location-card.blade.php create mode 100644 device-app/resources/views/components/device-owner-card.blade.php create mode 100644 device-app/resources/views/components/device-purchasing-card.blade.php diff --git a/device-app/app/Models/Device.php b/device-app/app/Models/Device.php index bb38700..cce77db 100644 --- a/device-app/app/Models/Device.php +++ b/device-app/app/Models/Device.php @@ -2,8 +2,11 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use App\Models\OwnerTransaction; +use App\Models\LocationTransaction; +use App\Models\PurchasingInformation; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Factories\HasFactory; class Device extends Model { @@ -24,4 +27,16 @@ class Device extends Model //Timestamps are disabled. public $timestamps = false; + + public function owners() { + return $this->hasMany(OwnerTransaction::class, 'device_id'); + } + + public function locations() { + return $this->hasMany(LocationTransaction::class, 'device_id'); + } + + public function purchasing() { + return $this->belongsTo(PurchasingInformation::class, 'device_id'); + } } \ No newline at end of file diff --git a/device-app/app/Models/LocationTransaction.php b/device-app/app/Models/LocationTransaction.php new file mode 100644 index 0000000..2ca3e90 --- /dev/null +++ b/device-app/app/Models/LocationTransaction.php @@ -0,0 +1,29 @@ + + */ + protected $fillable = ['location_transaction_id', 'room_code', 'timestamp_located_since', 'device_id']; + + public function device() { + return $this->belongsTo(Device::class, 'device_id'); + } +} \ No newline at end of file diff --git a/device-app/app/Models/OwnerTransaction.php b/device-app/app/Models/OwnerTransaction.php new file mode 100644 index 0000000..faa5aeb --- /dev/null +++ b/device-app/app/Models/OwnerTransaction.php @@ -0,0 +1,30 @@ + + */ + protected $fillable = ['owner_transaction_id', 'rz_username', 'timestamp_owner_since', 'device_id']; + + public function device() { + return $this->belongsTo(Device::class, 'device_id'); + } + +} diff --git a/device-app/app/Models/PurchasingInformation.php b/device-app/app/Models/PurchasingInformation.php new file mode 100644 index 0000000..ba71300 --- /dev/null +++ b/device-app/app/Models/PurchasingInformation.php @@ -0,0 +1,28 @@ + + */ + 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'); + } +} 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 6428fc7..a91c6b9 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 @@ -16,6 +16,7 @@ public function up(): void $table->string('room_code'); $table->string('timestamp_located_since'); $table->string('device_id'); + $table->foreign('device_id')->references('device_id')->on('devices'); }); } 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 fa46372..7d3c049 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 @@ -16,6 +16,7 @@ public function up(): void $table->string('rz_username'); $table->string('timestamp_owner_since'); $table->string('device_id'); + $table->foreign('device_id')->references('device_id')->on('devices'); }); } 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 b158973..0539e73 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 @@ -18,7 +18,8 @@ public function up(): void $table->string('timestamp_purchase'); $table->string('cost_centre'); $table->string('seller')->nullable(); - $table->string('device_id')->unique(); + $table->string('device_id'); + $table->foreign('device_id')->references('device_id')->on('devices'); }); } diff --git a/device-app/resources/views/components/device-card.blade.php b/device-app/resources/views/components/device-card.blade.php index dd691d8..eda7980 100644 --- a/device-app/resources/views/components/device-card.blade.php +++ b/device-app/resources/views/components/device-card.blade.php @@ -1,4 +1,14 @@ @props(['device'])
{{ $device->title }} +
\ No newline at end of file diff --git a/device-app/resources/views/components/device-location-card.blade.php b/device-app/resources/views/components/device-location-card.blade.php new file mode 100644 index 0000000..a32b7f4 --- /dev/null +++ b/device-app/resources/views/components/device-location-card.blade.php @@ -0,0 +1,5 @@ +@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 new file mode 100644 index 0000000..5f3e968 --- /dev/null +++ b/device-app/resources/views/components/device-owner-card.blade.php @@ -0,0 +1,5 @@ +@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 new file mode 100644 index 0000000..5e1679f --- /dev/null +++ b/device-app/resources/views/components/device-purchasing-card.blade.php @@ -0,0 +1,8 @@ +@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/devices/show.blade.php b/device-app/resources/views/devices/show.blade.php index e3958e2..5e1fea5 100644 --- a/device-app/resources/views/devices/show.blade.php +++ b/device-app/resources/views/devices/show.blade.php @@ -2,16 +2,7 @@ @section('content')

Device Detail

- +
From 656056a3b30daa4a1cfb2b934d8e487575cbc3c3 Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Wed, 29 Mar 2023 22:32:49 +0200 Subject: [PATCH 2/6] 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 From 6894c2c3c55845267f167fcfecdef2b3526cb66d Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Thu, 30 Mar 2023 15:16:38 +0200 Subject: [PATCH 3/6] implement uuid and make sample data factory --- .../app/Http/Controllers/DeviceController.php | 4 +-- device-app/app/Models/Device.php | 5 +-- device-app/app/Models/LocationTransaction.php | 3 +- device-app/app/Models/OwnerTransaction.php | 3 +- .../app/Models/PurchasingInformation.php | 3 +- .../app/View/Components/DeviceDetail.php | 26 ++++++++++++++ .../app/View/Components/DeviceSimple.php | 26 ++++++++++++++ .../database/factories/DeviceFactory.php | 2 +- .../factories/LocationTransactionFactory.php | 24 +++++++++++++ .../factories/OwnerTransactionFactory.php | 24 +++++++++++++ .../PurchasingInformationFactory.php | 26 ++++++++++++++ ...2023_03_20_114220_create_devices_table.php | 2 +- ...828_create_location_transactions_table.php | 5 ++- ...114834_create_owner_transactions_table.php | 5 ++- ...45_create_purchasing_information_table.php | 5 ++- .../database/seeders/DatabaseSeeder.php | 35 ++++--------------- .../views/components/device-card.blade.php | 25 ------------- .../views/components/device-detail.blade.php | 27 ++++++++++++++ .../views/components/device-simple.blade.php | 16 +++++++++ .../components/location-transaction.blade.php | 1 - .../components/owner-transaction.blade.php | 1 - .../resources/views/devices/create.blade.php | 4 +-- .../resources/views/devices/edit.blade.php | 4 +-- .../resources/views/devices/index.blade.php | 2 +- .../resources/views/devices/show.blade.php | 5 ++- 25 files changed, 202 insertions(+), 81 deletions(-) create mode 100644 device-app/app/View/Components/DeviceDetail.php create mode 100644 device-app/app/View/Components/DeviceSimple.php create mode 100644 device-app/database/factories/LocationTransactionFactory.php create mode 100644 device-app/database/factories/OwnerTransactionFactory.php create mode 100644 device-app/database/factories/PurchasingInformationFactory.php delete mode 100644 device-app/resources/views/components/device-card.blade.php create mode 100644 device-app/resources/views/components/device-detail.blade.php create mode 100644 device-app/resources/views/components/device-simple.blade.php 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 From 0e1de41203011ced62f5ef4b9f8d329bcfdda5ec Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Fri, 31 Mar 2023 10:52:12 +0200 Subject: [PATCH 4/6] add components button --- .../app/Http/Controllers/DeviceController.php | 2 - .../LocationTransactionController.php | 49 +++++++++++++++++ .../OwnerTransactionController.php | 49 +++++++++++++++++ .../PurchasingInformationController.php | 53 +++++++++++++++++++ .../views/components/device-detail.blade.php | 10 +++- .../components/location-transaction.blade.php | 6 +++ .../components/owner-transaction.blade.php | 6 +++ .../purchasing-information.blade.php | 1 + .../resources/views/devices/show.blade.php | 7 --- device-app/routes/web.php | 33 +++++++++++- 10 files changed, 205 insertions(+), 11 deletions(-) create mode 100644 device-app/app/Http/Controllers/LocationTransactionController.php create mode 100644 device-app/app/Http/Controllers/OwnerTransactionController.php create mode 100644 device-app/app/Http/Controllers/PurchasingInformationController.php diff --git a/device-app/app/Http/Controllers/DeviceController.php b/device-app/app/Http/Controllers/DeviceController.php index b4e3a0a..19a1a84 100644 --- a/device-app/app/Http/Controllers/DeviceController.php +++ b/device-app/app/Http/Controllers/DeviceController.php @@ -22,7 +22,6 @@ public function create(){ public function store(Request $request){ $formFields = $request->validate([ - //'device_id' => ['required', Rule::unique('devices', 'device_id')], 'title' => 'required', 'device_type' => 'required', 'description' => 'required', @@ -43,7 +42,6 @@ public function edit(Device $device) { public function update(Device $device, Request $request){ $formFields = $request->validate([ - //'device_id' => 'required', 'title' => 'required', 'device_type' => 'required', 'description' => 'required', diff --git a/device-app/app/Http/Controllers/LocationTransactionController.php b/device-app/app/Http/Controllers/LocationTransactionController.php new file mode 100644 index 0000000..4d23029 --- /dev/null +++ b/device-app/app/Http/Controllers/LocationTransactionController.php @@ -0,0 +1,49 @@ +validate([ + 'room_code' => 'required', + 'timestamp_located_since' => 'required' + ]); + + LocationTransaction::create($formFields); + + return redirect('/'); + } + + public function edit(LocationTransaction $location) + { + return view('locations.edit', ['location' => $location]); + } + + public function update(LocationTransaction $location, Request $request) + { + $formFields = $request->validate([ + 'room_code' => 'required', + 'timestamp_located_since' => 'required' + ]); + + $location->update($formFields); + + return back(); + } + + public function destroy(LocationTransaction $location) + { + $location->delete(); + return back(); + } +} diff --git a/device-app/app/Http/Controllers/OwnerTransactionController.php b/device-app/app/Http/Controllers/OwnerTransactionController.php new file mode 100644 index 0000000..d660a21 --- /dev/null +++ b/device-app/app/Http/Controllers/OwnerTransactionController.php @@ -0,0 +1,49 @@ +validate([ + 'rz_username' => 'required', + 'timestamp_owner_since' => 'required' + ]); + + OwnerTransaction::create($formFields); + + return redirect('/'); + } + + public function edit(OwnerTransaction $owner) + { + return view('owners.edit', ['owner' => $owner]); + } + + public function update(OwnerTransaction $owner, Request $request) + { + $formFields = $request->validate([ + 'rz_username' => 'required', + 'timestamp_owner_since' => 'required' + ]); + + $owner->update($formFields); + + return back(); + } + + public function destroy(OwnerTransaction $owner) + { + $owner->delete(); + return back(); + } +} diff --git a/device-app/app/Http/Controllers/PurchasingInformationController.php b/device-app/app/Http/Controllers/PurchasingInformationController.php new file mode 100644 index 0000000..ead94c3 --- /dev/null +++ b/device-app/app/Http/Controllers/PurchasingInformationController.php @@ -0,0 +1,53 @@ +validate([ + 'price' => 'required', + 'timestamp_warranty_end' => 'required', + 'timestamp_purchase' => 'required', + 'cost_centre' => 'required', + ]); + + PurchasingInformation::create($formFields); + + return redirect('/'); + } + + public function edit(PurchasingInformation $purchasing) + { + return view('purchasings.edit', ['purchasing' => $purchasing]); + } + + public function update(PurchasingInformation $purchasing, Request $request) + { + $formFields = $request->validate([ + 'price' => 'required', + 'timestamp_warranty_end' => 'required', + 'timestamp_purchase' => 'required', + 'cost_centre' => 'required', + ]); + + $purchasing->update($formFields); + + return back(); + } + + public function destroy(PurchasingInformation $purchasing) + { + $purchasing->delete(); + return back(); + } +} diff --git a/device-app/resources/views/components/device-detail.blade.php b/device-app/resources/views/components/device-detail.blade.php index 750a92f..c449aee 100644 --- a/device-app/resources/views/components/device-detail.blade.php +++ b/device-app/resources/views/components/device-detail.blade.php @@ -11,17 +11,25 @@
      • serial_number: {{ $device['serial_number'] }}
      • image_url: {{ $device['image_url'] }}
      + + + @method('DELETE') + @csrf + + @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/location-transaction.blade.php b/device-app/resources/views/components/location-transaction.blade.php index 34abd4f..632a17e 100644 --- a/device-app/resources/views/components/location-transaction.blade.php +++ b/device-app/resources/views/components/location-transaction.blade.php @@ -3,4 +3,10 @@
  • room_code: {{ $location->room_code }}
  • timestamp_located_since: {{ $location->timestamp_located_since }}
  • + +
    + @method('DELETE') + @csrf + +
    \ 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 index 07b6452..7105dad 100644 --- a/device-app/resources/views/components/owner-transaction.blade.php +++ b/device-app/resources/views/components/owner-transaction.blade.php @@ -3,4 +3,10 @@
  • rz_username: {{ $owner->rz_username }}
  • timestamp_owner_since: {{ $owner->timestamp_owner_since }}
  • + +
    + @method('DELETE') + @csrf + +
    \ 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 index ac4d14c..6d532ec 100644 --- a/device-app/resources/views/components/purchasing-information.blade.php +++ b/device-app/resources/views/components/purchasing-information.blade.php @@ -10,4 +10,5 @@
  • cost_centre: {{ $purchasing->cost_centre }}
  • seller: {{ $purchasing->seller }}
  • + \ No newline at end of file diff --git a/device-app/resources/views/devices/show.blade.php b/device-app/resources/views/devices/show.blade.php index 72e9e29..3956c16 100644 --- a/device-app/resources/views/devices/show.blade.php +++ b/device-app/resources/views/devices/show.blade.php @@ -2,11 +2,4 @@ @section('content') - - -
    - @method('DELETE') - @csrf - -
    @endsection diff --git a/device-app/routes/web.php b/device-app/routes/web.php index 8908730..e88a952 100644 --- a/device-app/routes/web.php +++ b/device-app/routes/web.php @@ -1,6 +1,9 @@ middleware('auth'); // store - store new device Route::post('/devices', [DeviceController::class, 'store'])->middleware('auth'); + +// Device purchasing routes +//Route::get('/devices/{device}/purchasing/create', [PurchasingInformationController::class, 'create']); +//Route::post('/devices/{device}/purchasing', [PurchasingInformationController::class, 'store']); +Route::get('/devices/{device}/purchasing/edit', [PurchasingInformationController::class, 'edit']); +Route::put('/devices/{device}/purchasing', [PurchasingInformationController::class, 'update']); +//Route::delete('/devices/{device}/purchasing', [PurchasingInformationController::class, 'destroy']); + +// Device location routes +Route::get('/devices/{device}/locations/create', [LocationTransactionController::class, 'create']); +Route::post('/devices/{device}/locations', [LocationTransactionController::class, 'store']); +Route::get('/devices/locations/{location}/edit', [LocationTransactionController::class, 'edit']); +Route::put('/devices/locations/{location}', [LocationTransactionController::class, 'update']); +Route::delete('/devices/locations/{location}', [LocationTransactionController::class, 'destroy']); + +// Device owner routes +Route::get('/devices/{device}/owners/create', [OwnerTransactionController::class, 'create']); +Route::post('/devices/{device}/owners', [OwnerTransactionController::class, 'store']); +Route::get('/devices/owners/{owner}/edit', [OwnerTransactionController::class, 'edit']); +Route::put('/devices/owners/{owner}', [OwnerTransactionController::class, 'update']); +Route::delete('/devices/owners/{owner}', [OwnerTransactionController::class, 'destroy']); + +// // edit - show edit form Route::get('devices/{device}/edit', [DeviceController::class, 'edit'])->middleware('auth'); // update - update device @@ -34,6 +64,7 @@ // show - show sigle device Route::get('/devices/{device}', [DeviceController::class, 'show']); +//User routes // create - show register form Route::get('/register', [UserController::class, 'create']); // store - store new user @@ -43,4 +74,4 @@ // authenticate - log in user Route::post('/users/authenticate', [UserController::class, 'authenticate']); // logout - log out user -Route::post('/logout', [UserController::class, 'logout']); +Route::post('/logout', [UserController::class, 'logout']); \ No newline at end of file From d5770b8cb54ba25a6396da378351e9f27a9eed15 Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Fri, 31 Mar 2023 11:39:03 +0200 Subject: [PATCH 5/6] fix edit purchasing information --- .../PurchasingInformationController.php | 11 +++--- .../resources/views/devices/create.blade.php | 14 +++---- .../views/purchasings/edit.blade.php | 37 +++++++++++++++++++ 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 device-app/resources/views/purchasings/edit.blade.php diff --git a/device-app/app/Http/Controllers/PurchasingInformationController.php b/device-app/app/Http/Controllers/PurchasingInformationController.php index ead94c3..0602f3b 100644 --- a/device-app/app/Http/Controllers/PurchasingInformationController.php +++ b/device-app/app/Http/Controllers/PurchasingInformationController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Device; use App\Models\PurchasingInformation; use Illuminate\Http\Request; @@ -26,12 +27,12 @@ public function store(Request $request) return redirect('/'); } - public function edit(PurchasingInformation $purchasing) + public function edit(Device $device) { - return view('purchasings.edit', ['purchasing' => $purchasing]); + return view('purchasings.edit', ['purchasing' => $device->purchasing]); } - public function update(PurchasingInformation $purchasing, Request $request) + public function update(Device $device, Request $request) { $formFields = $request->validate([ 'price' => 'required', @@ -40,9 +41,9 @@ public function update(PurchasingInformation $purchasing, Request $request) 'cost_centre' => 'required', ]); - $purchasing->update($formFields); + $device->purchasing->update($formFields); - return back(); + return redirect('/'); } public function destroy(PurchasingInformation $purchasing) diff --git a/device-app/resources/views/devices/create.blade.php b/device-app/resources/views/devices/create.blade.php index ac3b96f..428d877 100644 --- a/device-app/resources/views/devices/create.blade.php +++ b/device-app/resources/views/devices/create.blade.php @@ -11,43 +11,43 @@
    - @error('device_id') + @error('title')

    {{$message}}

    @enderror
    - @error('device_id') + @error('device_type')

    {{$message}}

    @enderror
    - @error('device_id') + @error('accessories')

    {{$message}}

    @enderror
    - @error('device_id') + @error('rz_username_buyer')

    {{$message}}

    @enderror
    - @error('device_id') + @error('serial_number')

    {{$message}}

    @enderror
    - @error('device_id') + @error('image_url')

    {{$message}}

    @enderror
    - @error('device_id') + @error('description')

    {{$message}}

    @enderror
    diff --git a/device-app/resources/views/purchasings/edit.blade.php b/device-app/resources/views/purchasings/edit.blade.php new file mode 100644 index 0000000..762a3af --- /dev/null +++ b/device-app/resources/views/purchasings/edit.blade.php @@ -0,0 +1,37 @@ +

    {{ $purchasing->price }}

    +
    + @method('PUT') + @csrf + + + @error('price') +

    {{ $message }}

    + @enderror +
    + + + @error('timestamp_warranty_end') +

    {{ $message }}

    + @enderror +
    + + + @error('timestamp_purchase') +

    {{ $message }}

    + @enderror +
    + + + @error('cost_centre') +

    {{ $message }}

    + @enderror +
    + + + @error('seller') +

    {{ $message }}

    + @enderror + +
    From 73ba1c8fed470bf84bd6eb66d9de7e71929e74a5 Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Fri, 31 Mar 2023 12:14:57 +0200 Subject: [PATCH 6/6] add create/edit functionality --- .../LocationTransactionController.php | 10 ++++++---- .../Controllers/OwnerTransactionController.php | 10 ++++++---- .../views/components/device-detail.blade.php | 4 ++-- .../resources/views/locations/create.blade.php | 17 +++++++++++++++++ .../resources/views/locations/edit.blade.php | 18 ++++++++++++++++++ .../resources/views/owners/create.blade.php | 17 +++++++++++++++++ .../resources/views/owners/edit.blade.php | 18 ++++++++++++++++++ .../resources/views/purchasings/edit.blade.php | 1 - 8 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 device-app/resources/views/locations/create.blade.php create mode 100644 device-app/resources/views/locations/edit.blade.php create mode 100644 device-app/resources/views/owners/create.blade.php create mode 100644 device-app/resources/views/owners/edit.blade.php diff --git a/device-app/app/Http/Controllers/LocationTransactionController.php b/device-app/app/Http/Controllers/LocationTransactionController.php index 4d23029..b40be93 100644 --- a/device-app/app/Http/Controllers/LocationTransactionController.php +++ b/device-app/app/Http/Controllers/LocationTransactionController.php @@ -2,23 +2,25 @@ namespace App\Http\Controllers; +use App\Models\Device; use Illuminate\Http\Request; use App\Models\LocationTransaction; class LocationTransactionController extends Controller { - public function create() + public function create(Device $device) { - return view('locations.create'); + return view('locations.create', ['device' => $device]); } - public function store(Request $request) + public function store(Device $device, Request $request) { $formFields = $request->validate([ 'room_code' => 'required', 'timestamp_located_since' => 'required' ]); + $formFields['device_id'] = $device->device_id; LocationTransaction::create($formFields); return redirect('/'); @@ -38,7 +40,7 @@ public function update(LocationTransaction $location, Request $request) $location->update($formFields); - return back(); + return redirect('/'); } public function destroy(LocationTransaction $location) diff --git a/device-app/app/Http/Controllers/OwnerTransactionController.php b/device-app/app/Http/Controllers/OwnerTransactionController.php index d660a21..60198fa 100644 --- a/device-app/app/Http/Controllers/OwnerTransactionController.php +++ b/device-app/app/Http/Controllers/OwnerTransactionController.php @@ -2,23 +2,25 @@ namespace App\Http\Controllers; +use App\Models\Device; use App\Models\OwnerTransaction; use Illuminate\Http\Request; class OwnerTransactionController extends Controller { - public function create() + public function create(Device $device) { - return view('owners.create'); + return view('owners.create', ['device' => $device]); } - public function store(Request $request) + public function store(Device $device, Request $request) { $formFields = $request->validate([ 'rz_username' => 'required', 'timestamp_owner_since' => 'required' ]); + $formFields['device_id'] = $device->device_id; OwnerTransaction::create($formFields); return redirect('/'); @@ -38,7 +40,7 @@ public function update(OwnerTransaction $owner, Request $request) $owner->update($formFields); - return back(); + return redirect('/'); } public function destroy(OwnerTransaction $owner) diff --git a/device-app/resources/views/components/device-detail.blade.php b/device-app/resources/views/components/device-detail.blade.php index c449aee..7049f8f 100644 --- a/device-app/resources/views/components/device-detail.blade.php +++ b/device-app/resources/views/components/device-detail.blade.php @@ -23,12 +23,12 @@ $ownerTransactins = $device->owners; @endphp

    Location Transactions

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

    Owner Transactions

    - + @foreach ($ownerTransactins as $owner) @endforeach diff --git a/device-app/resources/views/locations/create.blade.php b/device-app/resources/views/locations/create.blade.php new file mode 100644 index 0000000..4ec2798 --- /dev/null +++ b/device-app/resources/views/locations/create.blade.php @@ -0,0 +1,17 @@ +
    + @csrf + + + @error('room_code') +

    {{ $message }}

    + @enderror +
    + + + @error('timestamp_located_since') +

    {{ $message }}

    + @enderror +
    + +
    \ No newline at end of file diff --git a/device-app/resources/views/locations/edit.blade.php b/device-app/resources/views/locations/edit.blade.php new file mode 100644 index 0000000..670475e --- /dev/null +++ b/device-app/resources/views/locations/edit.blade.php @@ -0,0 +1,18 @@ +
    + @method('PUT') + @csrf + + + @error('room_code') +

    {{ $message }}

    + @enderror +
    + + + @error('timestamp_located_since') +

    {{ $message }}

    + @enderror +
    + +
    \ No newline at end of file diff --git a/device-app/resources/views/owners/create.blade.php b/device-app/resources/views/owners/create.blade.php new file mode 100644 index 0000000..0983a38 --- /dev/null +++ b/device-app/resources/views/owners/create.blade.php @@ -0,0 +1,17 @@ +
    + @csrf + + + @error('rz_username') +

    {{ $message }}

    + @enderror +
    + + + @error('timestamp_owner_since') +

    {{ $message }}

    + @enderror +
    + +
    \ No newline at end of file diff --git a/device-app/resources/views/owners/edit.blade.php b/device-app/resources/views/owners/edit.blade.php new file mode 100644 index 0000000..ea8da54 --- /dev/null +++ b/device-app/resources/views/owners/edit.blade.php @@ -0,0 +1,18 @@ +
    + @method('PUT') + @csrf + + + @error('rz_username') +

    {{ $message }}

    + @enderror +
    + + + @error('timestamp_owner_since') +

    {{ $message }}

    + @enderror +
    + +
    \ No newline at end of file diff --git a/device-app/resources/views/purchasings/edit.blade.php b/device-app/resources/views/purchasings/edit.blade.php index 762a3af..db0791c 100644 --- a/device-app/resources/views/purchasings/edit.blade.php +++ b/device-app/resources/views/purchasings/edit.blade.php @@ -1,4 +1,3 @@ -

    {{ $purchasing->price }}

    @method('PUT') @csrf