Skip to content

Commit ab4f863

Browse files
feat: Model de Análise Jurídica
1 parent 2f8ae10 commit ab4f863

13 files changed

Lines changed: 395 additions & 1 deletion

app/Enums/FileStatus.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
use App\Enums\Concerns\HasOptions;
6+
use App\Enums\Contracts\HasLabel;
7+
8+
enum FileStatus: int implements HasLabel
9+
{
10+
use HasOptions;
11+
12+
case VALID = 1;
13+
case INVALID = 2;
14+
15+
public function label(): string
16+
{
17+
return match ($this) {
18+
self::VALID => 'De acordo',
19+
self::INVALID => 'Necessita de ajuste',
20+
};
21+
}
22+
}

app/Models/LegalAnalysis.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Enums\FileStatus;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Database\Eloquent\Relations\HasMany;
9+
use Illuminate\Database\Eloquent\SoftDeletes;
10+
use OwenIt\Auditing\Auditable as AuditableTrait;
11+
use OwenIt\Auditing\Contracts\Auditable;
12+
13+
class LegalAnalysis extends Model implements Auditable
14+
{
15+
use AuditableTrait, SoftDeletes;
16+
17+
protected $table = 'legal_analyses';
18+
19+
protected $fillable = [
20+
'project_id',
21+
'responsible_user_id',
22+
'processed_at',
23+
];
24+
25+
protected $casts = [
26+
'processed_at' => 'datetime',
27+
];
28+
29+
public function project(): BelongsTo
30+
{
31+
return $this->belongsTo(Project::class);
32+
}
33+
34+
public function responsibleUser(): BelongsTo
35+
{
36+
return $this->belongsTo(User::class, 'responsible_user_id');
37+
}
38+
39+
public function files(): HasMany
40+
{
41+
return $this->hasMany(LegalAnalysisFile::class);
42+
}
43+
44+
public function getFileStatus(int $fileId): ?FileStatus
45+
{
46+
$file = $this->files()->where('file_id', $fileId)->first();
47+
48+
return $file ? $file->status_id : null;
49+
}
50+
}

app/Models/LegalAnalysisFile.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Enums\FileStatus;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
9+
class LegalAnalysisFile extends Model
10+
{
11+
protected $fillable = [
12+
'legal_analysis_id',
13+
'file_id',
14+
'status_id',
15+
];
16+
17+
protected $casts = [
18+
'status_id' => FileStatus::class,
19+
];
20+
21+
public function analysis(): BelongsTo
22+
{
23+
return $this->belongsTo(LegalAnalysis::class);
24+
}
25+
26+
public function file(): BelongsTo
27+
{
28+
return $this->belongsTo(File::class);
29+
}
30+
}

app/Models/Project.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Database\Eloquent\Factories\HasFactory;
1313
use Illuminate\Database\Eloquent\Model;
1414
use Illuminate\Database\Eloquent\Relations\BelongsTo;
15+
use Illuminate\Database\Eloquent\Relations\HasOne;
1516
use Illuminate\Database\Eloquent\SoftDeletes;
1617
use Illuminate\Database\Eloquent\Builder;
1718
use OwenIt\Auditing\Auditable as AuditableTrait;
@@ -94,7 +95,7 @@ public function getOpeningNupAttribute()
9495
{
9596
return $this->opening?->opening_nup;
9697
}
97-
98+
9899
public function scopeFilterPhase(Builder $query, ?string $phase): Builder
99100
{
100101
if (!$phase) {
@@ -128,4 +129,9 @@ public function scopeSearch(Builder $query, ?string $search): Builder
128129
});
129130
});
130131
}
132+
133+
public function legalAnalysis(): HasOne
134+
{
135+
return $this->hasOne(LegalAnalysis::class);
136+
}
131137
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use App\Models\LegalAnalysis;
6+
use App\Models\Project;
7+
use App\Models\User;
8+
use Illuminate\Database\Eloquent\Factories\Factory;
9+
10+
/**
11+
* @extends Factory<LegalAnalysis>
12+
*/
13+
class LegalAnalysisFactory extends Factory
14+
{
15+
/**
16+
* Define the model's default state.
17+
*
18+
* @return array<string, mixed>
19+
*/
20+
public function definition(): array
21+
{
22+
return [
23+
'project_id' => Project::inRandomOrder()->first()?->id ?? Project::factory(),
24+
'responsible_user_id' => User::inRandomOrder()->first()?->id ?? User::factory(),
25+
'processed_at' => $this->faker->optional()->dateTime(),
26+
];
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use App\Models\File;
6+
use App\Models\LegalAnalysis;
7+
use App\Models\LegalAnalysisFile;
8+
use Illuminate\Database\Eloquent\Factories\Factory;
9+
10+
/**
11+
* @extends Factory<LegalAnalysisFile>
12+
*/
13+
class LegalAnalysisFileFactory extends Factory
14+
{
15+
/**
16+
* Define the model's default state.
17+
*
18+
* @return array<string, mixed>
19+
*/
20+
public function definition(): array
21+
{
22+
return [
23+
'legal_analysis_id' => LegalAnalysis::inRandomOrder()->first()?->id ?? LegalAnalysis::factory(),
24+
'file_id' => File::inRandomOrder()->first()?->id ?? File::factory(),
25+
'status_id' => $this->faker->numberBetween(1, 2),
26+
];
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('legal_analyses', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignId('project_id')->constrained();
17+
$table->foreignId('responsible_user_id')->constrained('users');
18+
$table->timestamp('processed_at')->nullable();
19+
$table->timestamps();
20+
$table->softDeletes();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*/
27+
public function down(): void
28+
{
29+
Schema::dropIfExists('legal_analyses');
30+
}
31+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('legal_analysis_files', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignId('legal_analysis_id')->constrained();
17+
$table->foreignId('file_id')->constrained();
18+
$table->unsignedTinyInteger('status_id');
19+
$table->timestamps();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
Schema::dropIfExists('legal_analysis_files');
29+
}
30+
};

database/seeders/DatabaseSeeder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function run(): void
2121
NoticeSeeder::class,
2222
UserSeeder::class,
2323
AgentSeeder::class,
24+
LegalAnalysisSeeder::class,
2425
]);
2526
}
2627
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use App\Models\LegalAnalysis;
6+
use App\Models\LegalAnalysisFile;
7+
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
8+
use Illuminate\Database\Seeder;
9+
10+
class LegalAnalysisSeeder extends Seeder
11+
{
12+
/**
13+
* Run the database seeds.
14+
*/
15+
public function run(): void
16+
{
17+
LegalAnalysis::factory()
18+
->count(10)
19+
->create()
20+
->each(function ($analysis) {
21+
// para cada análise, cria arquivos relacionados
22+
LegalAnalysisFile::factory()
23+
->count(rand(1, 5))
24+
->create([
25+
'legal_analysis_id' => $analysis->id,
26+
]);
27+
});
28+
}
29+
}

0 commit comments

Comments
 (0)