diff --git a/src/.env.example b/src/.env.example index bf78dae..dbae05b 100644 --- a/src/.env.example +++ b/src/.env.example @@ -1,4 +1,4 @@ -APP_NAME=Laravel +APP_NAME=Biblio APP_ENV=local APP_KEY= APP_DEBUG=true @@ -57,3 +57,5 @@ VITE_PUSHER_HOST="${PUSHER_HOST}" VITE_PUSHER_PORT="${PUSHER_PORT}" VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +BARCODE_COMPANY_PREFIX=069420 diff --git a/src/app/Http/Controllers/FineController.php b/src/app/Http/Controllers/FineController.php new file mode 100644 index 0000000..cbfbf79 --- /dev/null +++ b/src/app/Http/Controllers/FineController.php @@ -0,0 +1,65 @@ + - */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; - - /** - * The attributes that should be hidden for serialization. - * - * @var array - */ - protected $hidden = [ - 'password', - 'remember_token', - ]; - - /** - * The attributes that should be cast. - * - * @var array - */ - protected $casts = [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - ]; + protected $guarded = []; } diff --git a/src/app/Traits/CommonLibraryTrait.php b/src/app/Traits/CommonLibraryTrait.php new file mode 100644 index 0000000..e87f4ec --- /dev/null +++ b/src/app/Traits/CommonLibraryTrait.php @@ -0,0 +1,53 @@ +generateLibraryPassBarCode(); + while($this->isLibraryPassBarCodeAlreadyInUse($barcode)) { + $barcode = $this->generateLibraryPassBarCode(); + } + return $barcode; + } + + /** + * @return string A random library pass barcode + */ + private function generateLibraryPassBarCode(): string + { + $prefix = Env::get('BARCODE_COMPANY_PREFIX'); + return $prefix . $this->generateRandomNumber(9); + } + + /** + * @param $length + * @return string A random number with the given length + */ + public function generateRandomNumber($length): string + { + $result = ''; + for($i = 0; $i < $length; $i++) { + $result .= mt_rand(0, 9); + } + return $result; + } + + /** + * @param $barcode + * @return bool True if the barcode is already in use, false otherwise + */ + private function isLibraryPassBarCodeAlreadyInUse($barcode): bool + { + return LibraryPass::where('barcode', $barcode)->exists(); + } +} + diff --git a/src/database/migrations/2014_10_12_000000_create_users_table.php b/src/database/migrations/2014_10_12_000000_create_users_table.php index 444fafb..0b060a0 100644 --- a/src/database/migrations/2014_10_12_000000_create_users_table.php +++ b/src/database/migrations/2014_10_12_000000_create_users_table.php @@ -13,11 +13,16 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); + $table->string('first_name' ); + $table->string('last_name' ); + $table->string('email' )->unique(); + $table->string('residence'); + $table->string('street'); + $table->string('zip_code'); + $table->string('house_number'); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); $table->timestamps(); }); } diff --git a/src/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php b/src/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php deleted file mode 100644 index 81a7229..0000000 --- a/src/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php +++ /dev/null @@ -1,28 +0,0 @@ -string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('password_reset_tokens'); - } -}; diff --git a/src/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/src/database/migrations/2019_08_19_000000_create_failed_jobs_table.php deleted file mode 100644 index 249da81..0000000 --- a/src/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ /dev/null @@ -1,32 +0,0 @@ -id(); - $table->string('uuid')->unique(); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('failed_jobs'); - } -}; diff --git a/src/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/src/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php deleted file mode 100644 index e828ad8..0000000 --- a/src/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - $table->morphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamp('expires_at')->nullable(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('personal_access_tokens'); - } -}; diff --git a/src/database/migrations/2023_12_04_105123_create_item_age_ratings_table.php b/src/database/migrations/2023_12_04_105123_create_item_age_ratings_table.php new file mode 100644 index 0000000..ae438a5 --- /dev/null +++ b/src/database/migrations/2023_12_04_105123_create_item_age_ratings_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('rating'); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('item_age_ratings'); + } +}; diff --git a/src/database/migrations/2023_12_04_105135_create_item_categories_table.php b/src/database/migrations/2023_12_04_105135_create_item_categories_table.php new file mode 100644 index 0000000..2759412 --- /dev/null +++ b/src/database/migrations/2023_12_04_105135_create_item_categories_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('category'); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('item_categories'); + } +}; diff --git a/src/database/migrations/2023_12_04_125021_create_library_passes_table.php b/src/database/migrations/2023_12_04_125021_create_library_passes_table.php new file mode 100644 index 0000000..d0be0ce --- /dev/null +++ b/src/database/migrations/2023_12_04_125021_create_library_passes_table.php @@ -0,0 +1,34 @@ +id(); + $table->unsignedBigInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users')->onDelete("cascade"); + $table->string('barcode'); + $table->boolean('is_active')->default(true); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('library_passes'); + } +}; diff --git a/src/database/migrations/2023_12_04_125045_create_items_table.php b/src/database/migrations/2023_12_04_125045_create_items_table.php new file mode 100644 index 0000000..2e9e448 --- /dev/null +++ b/src/database/migrations/2023_12_04_125045_create_items_table.php @@ -0,0 +1,40 @@ +id(); + $table->string('identifier')->unique(); + $table->string('type'); + $table->string('name'); + $table->text('description'); + $table->unsignedBigInteger('category'); + $table->foreign('category')->references('id')->on('item_categories'); + $table->string('ISBN')->nullable(); + $table->unsignedBigInteger('rating'); + $table->foreign('rating')->references('id')->on('item_age_ratings'); + $table->bigInteger('borrowing_time')->nullable(); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('items'); + } +}; diff --git a/src/database/migrations/2023_12_04_125051_create_grants_table.php b/src/database/migrations/2023_12_04_125051_create_grants_table.php new file mode 100644 index 0000000..b2d02c9 --- /dev/null +++ b/src/database/migrations/2023_12_04_125051_create_grants_table.php @@ -0,0 +1,36 @@ +id(); + $table->unsignedBigInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users')->onDelete("cascade"); + $table->unsignedBigInteger('item_id'); + $table->foreign('item_id')->references('id')->on('items')->onDelete("cascade"); + $table->dateTime('borrowed_date'); + $table->dateTime('return_date')->nullable(); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('grants'); + } +}; diff --git a/src/database/migrations/2023_12_04_125056_create_fines_table.php b/src/database/migrations/2023_12_04_125056_create_fines_table.php new file mode 100644 index 0000000..0527ad9 --- /dev/null +++ b/src/database/migrations/2023_12_04_125056_create_fines_table.php @@ -0,0 +1,33 @@ +id(); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('grant_id'); + $table->foreign('grant_id')->references('id')->on('grants')->onDelete("cascade"); + $table->double('amount'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('fines'); + } +}; diff --git a/src/database/migrations/2023_12_04_125105_create_payment_transactions_table.php b/src/database/migrations/2023_12_04_125105_create_payment_transactions_table.php new file mode 100644 index 0000000..26f3a41 --- /dev/null +++ b/src/database/migrations/2023_12_04_125105_create_payment_transactions_table.php @@ -0,0 +1,33 @@ +id(); + $table->unsignedBigInteger('fine_id'); + $table->foreign('fine_id')->references('id')->on('fines')->onDelete("cascade"); + $table->double('paid'); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('payment_transactions'); + } +}; diff --git a/src/database/migrations/2023_12_04_125113_create_reservations_table.php b/src/database/migrations/2023_12_04_125113_create_reservations_table.php new file mode 100644 index 0000000..dd0715d --- /dev/null +++ b/src/database/migrations/2023_12_04_125113_create_reservations_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users')->onDelete("cascade"); + $table->unsignedBigInteger('item_id'); + $table->foreign('item_id')->references('id')->on('items')->onDelete("cascade"); + $table->dateTime('expire_at'); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('reservations'); + } +}; diff --git a/src/database/migrations/2023_12_04_125144_create_item_images_table.php b/src/database/migrations/2023_12_04_125144_create_item_images_table.php new file mode 100644 index 0000000..72bbd9a --- /dev/null +++ b/src/database/migrations/2023_12_04_125144_create_item_images_table.php @@ -0,0 +1,34 @@ +id(); + $table->unsignedBigInteger('item_id'); + $table->foreign('item_id')->references('id')->on('items')->onDelete("cascade"); + $table->string('filename'); + $table->string('path'); + $table->char('modified_kind' ,1)->default('I'); + $table->unsignedBigInteger('modified_user'); + $table->foreign('modified_user')->references('id')->on('users')->onDelete("cascade"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('item_images'); + } +}; diff --git a/src/database/seeders/DatabaseSeeder.php b/src/database/seeders/DatabaseSeeder.php index a9f4519..7c31374 100644 --- a/src/database/seeders/DatabaseSeeder.php +++ b/src/database/seeders/DatabaseSeeder.php @@ -3,20 +3,64 @@ namespace Database\Seeders; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; +use App\Models\LibraryPass; +use App\Models\User; use Illuminate\Database\Seeder; +use App\Traits\CommonLibraryTrait; class DatabaseSeeder extends Seeder { + use CommonLibraryTrait; /** * Seed the application's database. + * Run this seeder with the following command: php artisan db:seed --class=DatabaseSeeder */ public function run(): void { - // \App\Models\User::factory(10)->create(); + //create super admin + $superAdmin = User::create([ + 'first_name' => 'Super', + 'last_name' => 'Admin', + 'email' => 'superadmin@biblio.nl', + 'residence' => 'Zwolle', + 'street' => 'Straat', + 'zip_code' => '1234AB', + 'house_number' => '1', + 'modified_kind' => 'I', + 'modified_user' => 1, + 'created_at' => now(), + 'updated_at' => now(), + ]); - // \App\Models\User::factory()->create([ - // 'name' => 'Test User', - // 'email' => 'test@example.com', - // ]); + LibraryPass::create([ + 'user_id' => $superAdmin->id, + 'barcode' => $this->generateValidLibraryPassBarCode(), + 'is_active' => true, + 'modified_kind' => 'I', + 'modified_user' => $superAdmin->id, + ]); + + //create admin, fill in your own details + $admin = User::create([ + 'first_name' => '', + 'last_name' => '', + 'email' => '', + 'residence' => '', + 'street' => '', + 'zip_code' => '', + 'house_number' => '', + 'modified_kind' => 'I', + 'modified_user' => $superAdmin->id, + 'created_at' => now(), + 'updated_at' => now(), + ]); + + LibraryPass::create([ + 'user_id' => $admin->id, + 'barcode' => $this->generateValidLibraryPassBarCode(), + 'is_active' => true, + 'modified_kind' => 'I', + 'modified_user' => $superAdmin->id, + ]); } }