diff --git a/app/Http/Requests/OfferPostRequest.php b/app/Http/Requests/OfferPostRequest.php index 98c7beb..7c5cc81 100644 --- a/app/Http/Requests/OfferPostRequest.php +++ b/app/Http/Requests/OfferPostRequest.php @@ -27,7 +27,7 @@ public function rules(): array 'skills' => 'string|nullable', 'experience' => 'string|nullable', 'salary' => 'numeric|nullable', - 'url' => 'url:https|http|nullable' + 'url' => 'url:http,https|nullable' ]; } } diff --git a/app/Listeners/SetTenantIdInSession.php b/app/Listeners/SetTenantIdInSession.php new file mode 100644 index 0000000..0ec75b4 --- /dev/null +++ b/app/Listeners/SetTenantIdInSession.php @@ -0,0 +1,26 @@ +put('tenant_id', $event->user->tenant_id); + } +} diff --git a/app/Models/Company.php b/app/Models/Company.php index 209ef67..c457044 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -2,13 +2,14 @@ namespace App\Models; +use App\Traits\BelongsToTenant; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Model; class Company extends Model { - use HasFactory; + use HasFactory, BelongsToTenant; public function offers(): HasMany { return $this->hasMany(Offer::class)->chaperone(); diff --git a/app/Models/Interview.php b/app/Models/Interview.php index f24c2e9..9f4a176 100644 --- a/app/Models/Interview.php +++ b/app/Models/Interview.php @@ -2,13 +2,14 @@ namespace App\Models; +use App\Traits\BelongsToTenant; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Model; class Interview extends Model { - use HasFactory; + use HasFactory, BelongsToTenant; public function offer() : BelongsTo { return $this->belongsTo(Offer::class); diff --git a/app/Models/Location.php b/app/Models/Location.php index 35b1313..7cb979c 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -2,10 +2,11 @@ namespace App\Models; +use App\Traits\BelongsToTenant; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Location extends Model { - use HasFactory; + use HasFactory, BelongsToTenant; } diff --git a/app/Models/Offer.php b/app/Models/Offer.php index 5860311..022e2f8 100644 --- a/app/Models/Offer.php +++ b/app/Models/Offer.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Traits\BelongsToTenant; use Illuminate\Database\Eloquent\Concerns\HasTimestamps; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -13,7 +14,7 @@ class Offer extends Model { - use HasFactory, SoftDeletes, HasTimestamps; + use HasFactory, SoftDeletes, HasTimestamps, BelongsToTenant; /** * The attributes that are mass assignable. @@ -26,7 +27,8 @@ class Offer extends Model 'skills', 'experience', 'salary', - 'url' + 'url', + 'tenant_id' ]; public function location(): HasOne { diff --git a/app/Models/Platform.php b/app/Models/Platform.php index 24262fe..6a0bf19 100644 --- a/app/Models/Platform.php +++ b/app/Models/Platform.php @@ -2,13 +2,14 @@ namespace App\Models; +use App\Traits\BelongsToTenant; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Model; class Platform extends Model { - use HasFactory; + use HasFactory, BelongsToTenant; public function offers(): HasMany { return $this->hasMany(Offer::class)->chaperone(); diff --git a/app/Models/Scopes/TenantScope.php b/app/Models/Scopes/TenantScope.php new file mode 100644 index 0000000..9c73a08 --- /dev/null +++ b/app/Models/Scopes/TenantScope.php @@ -0,0 +1,20 @@ +has('tenant_id')) { + $builder->where('tenant_id', session()->get('tenant_id')); + } + } +} diff --git a/app/Models/Technology.php b/app/Models/Technology.php index b0de4be..55ee3bb 100644 --- a/app/Models/Technology.php +++ b/app/Models/Technology.php @@ -2,13 +2,14 @@ namespace App\Models; +use App\Traits\BelongsToTenant; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Model; class Technology extends Model { - use HasFactory; + use HasFactory, BelongsToTenant; public function offers(): BelongsToMany { return $this->belongsToMany(Offer::class); diff --git a/app/Models/User.php b/app/Models/User.php index def621f..30cdae0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,13 +3,16 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; + +use App\Traits\BelongsToTenant; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +// #[ScopedBy([TenantScope::class])] class User extends Authenticatable { - use HasFactory, Notifiable; + use HasFactory, Notifiable, BelongsToTenant; /** * The attributes that are mass assignable. diff --git a/app/Traits/BelongsToTenant.php b/app/Traits/BelongsToTenant.php new file mode 100644 index 0000000..0476c17 --- /dev/null +++ b/app/Traits/BelongsToTenant.php @@ -0,0 +1,24 @@ +has('tenant_id')) { + $model->tenant_id = session()->get('tenant_id'); + } + }); + } + + public function tenant() : BelongsTo { + return $this->belongsTo(Tenant::class); + } +} diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php new file mode 100644 index 0000000..da7d809 --- /dev/null +++ b/database/factories/CompanyFactory.php @@ -0,0 +1,28 @@ + + */ +class CompanyFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => fake()->company(), + 'url' => fake()->url(), + 'location_id' => Location::factory(), + 'tenant_id' => Tenant::factory(), + ]; + } +} diff --git a/database/factories/CurrencyFactory.php b/database/factories/CurrencyFactory.php new file mode 100644 index 0000000..fab63ab --- /dev/null +++ b/database/factories/CurrencyFactory.php @@ -0,0 +1,25 @@ + + */ +class CurrencyFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => fake()->name(), + 'symbol' => fake()->randomLetter(), + ]; + } +} diff --git a/database/factories/InterveiwFactory.php b/database/factories/InterveiwFactory.php new file mode 100644 index 0000000..8654cc1 --- /dev/null +++ b/database/factories/InterveiwFactory.php @@ -0,0 +1,28 @@ + + */ +class InterveiwFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'date_time' => fake()->dateTime(), + 'call_details' => fake()->text(), + 'offer_id' => Offer::factory(), + 'tenant_id' => Tenant::factory(), + ]; + } +} diff --git a/database/factories/LocationFactory.php b/database/factories/LocationFactory.php new file mode 100644 index 0000000..d4716df --- /dev/null +++ b/database/factories/LocationFactory.php @@ -0,0 +1,26 @@ + + */ +class LocationFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'country' => fake()->country(), + 'address' => fake()->address(), + 'tenant_id' => Tenant::factory(), + ]; + } +} diff --git a/database/factories/OfferFactory.php b/database/factories/OfferFactory.php new file mode 100644 index 0000000..52110c2 --- /dev/null +++ b/database/factories/OfferFactory.php @@ -0,0 +1,40 @@ + + */ +class OfferFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $tenant = Tenant::factory(); + return [ + 'position' => fake()->sentence(), + 'skills' => fake()->text(), + 'experience' => fake()->text(), + 'salary' => fake()->numberBetween(65000, 180000), + 'url' => fake()->url(), + 'publication_date' => fake()->date(), + 'priority' => fake()->word(), + 'currency_id' => Currency::factory(), + // 'location_id' => Location::factory(), + // 'company_id' => Company::factory(), + // 'platform_id' => Platform::factory(), + 'tenant_id' => Tenant::factory(), + ]; + } +} diff --git a/database/factories/PlatformFactory.php b/database/factories/PlatformFactory.php new file mode 100644 index 0000000..0bbb145 --- /dev/null +++ b/database/factories/PlatformFactory.php @@ -0,0 +1,26 @@ + + */ +class PlatformFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => fake()->company(), + 'url' => fake()->url(), + 'tenant_id' => Tenant::factory(), + ]; + } +} diff --git a/database/factories/TechnologyFactory.php b/database/factories/TechnologyFactory.php new file mode 100644 index 0000000..adab6af --- /dev/null +++ b/database/factories/TechnologyFactory.php @@ -0,0 +1,25 @@ + + */ +class TechnologyFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => fake()->name(), + 'description' => fake()->text(), + ]; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index c6a4f0f..e996697 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -31,7 +31,7 @@ public function definition(): array 'email_verified_at' => now(), 'password' => bcrypt('password'), 'remember_token' => Str::random(10), - 'tenant_uuid' => Tenant::factory(), + 'tenant_id' => Tenant::factory(), ]; } diff --git a/database/migrations/2024_10_06_145949_create_offers_technologies_table.php b/database/migrations/2024_10_06_145949_create_offer_technology_table.php similarity index 81% rename from database/migrations/2024_10_06_145949_create_offers_technologies_table.php rename to database/migrations/2024_10_06_145949_create_offer_technology_table.php index 91436b4..5c698b4 100644 --- a/database/migrations/2024_10_06_145949_create_offers_technologies_table.php +++ b/database/migrations/2024_10_06_145949_create_offer_technology_table.php @@ -11,7 +11,7 @@ */ public function up(): void { - Schema::create('offers_technologies', function (Blueprint $table) { + Schema::create('offer_technology', function (Blueprint $table) { $table->id(); $table->foreignId('offer_id')->constrained()->onDelete('cascade'); $table->foreignId('technology_id')->constrained()->onDelete('cascade'); @@ -24,6 +24,6 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('offers_technologies'); + Schema::dropIfExists('offer_technology'); } }; diff --git a/database/migrations/2024_10_10_021038_add_tenant_to_the_rest_of_tables.php b/database/migrations/2024_10_10_021038_add_tenant_to_the_rest_of_tables.php index 2b8b55a..1897776 100644 --- a/database/migrations/2024_10_10_021038_add_tenant_to_the_rest_of_tables.php +++ b/database/migrations/2024_10_10_021038_add_tenant_to_the_rest_of_tables.php @@ -35,7 +35,7 @@ public function up(): void $table->unsignedBigInteger('tenant_id')->nullable()->index(); }); - Schema::table('offers_technologies', function (Blueprint $table) { + Schema::table('offer_technology', function (Blueprint $table) { $table->unsignedBigInteger('tenant_id')->nullable()->index(); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index d01a0ef..b472bdb 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,9 +2,16 @@ namespace Database\Seeders; +use App\Models\Company; +use App\Models\Currency; +use App\Models\Location; +use App\Models\Offer; +use App\Models\Platform; +use App\Models\Technology; use App\Models\User; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Locale; class DatabaseSeeder extends Seeder { @@ -13,11 +20,24 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // User::factory(10)->create(); + User::factory()->count(10)->create(); + $user = User::factory()->create(); + $tid = $user->tenant_id; + $location = Location::factory()->create(['tenant_id' => $tid]); + $company = Company::factory()->create(['tenant_id' => $tid]); + $platform = Platform::factory()->create(['tenant_id' => $tid]); - User::factory()->create([ - 'name' => 'Test User', - 'email' => 'test@example.com', - ]); + $offers = Offer::factory() + ->count(10) + ->hasAttached( + Technology::factory()->count(4), + ['tenant_id' => $tid] + ) + ->create([ + 'tenant_id' => $tid, + 'company_id' => $company->id, + 'location_id' => $location->id, + 'platform_id' => $platform->id, + ]); } } diff --git a/docker/test_setup.sh b/docker/test_setup.sh index 454b22e..62562cc 100755 --- a/docker/test_setup.sh +++ b/docker/test_setup.sh @@ -9,7 +9,7 @@ echo "creating jobtracker sqlite db" touch ./tests/jobtracker.sqlite echo "Running migration" -php artisan migrate --env=testing +php artisan migrate:fresh --env=testing echo "Running tests" php artisan test --env=testing diff --git a/resources/views/admin/header.blade.php b/resources/views/admin/header.blade.php index d12fe54..11e2e0e 100644 --- a/resources/views/admin/header.blade.php +++ b/resources/views/admin/header.blade.php @@ -5,7 +5,17 @@ Calendario Alertas Contactos - New + + +
\ No newline at end of file diff --git a/resources/views/components/wysiwyg/editor.blade.php b/resources/views/components/wysiwyg/editor.blade.php new file mode 100644 index 0000000..616e247 --- /dev/null +++ b/resources/views/components/wysiwyg/editor.blade.php @@ -0,0 +1,137 @@ + + +
+

A WYSIWYG Editor.

+

Try making some changes here. Add your own text or maybe an image.

+
+ + \ No newline at end of file diff --git a/resources/views/menu/profile.blade.php b/resources/views/menu/profile.blade.php index 303e176..3290511 100644 --- a/resources/views/menu/profile.blade.php +++ b/resources/views/menu/profile.blade.php @@ -1,5 +1,5 @@ @auth -