Skip to content

Commit 0487ae2

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

14 files changed

Lines changed: 407 additions & 2 deletions

app/Enums/Concerns/HasOptions.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ trait HasOptions
77
public static function options(): array
88
{
99
return collect(self::cases())
10-
->map(fn ($case) => [
10+
->map(fn($case) => [
1111
'value' => $case->value,
1212
'label' => $case->label(),
1313
])
1414
->toArray();
1515
}
16+
17+
public static function values(): array
18+
{
19+
return array_column(self::cases(), 'value');
20+
}
1621
}

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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 OwenIt\Auditing\Auditable as AuditableTrait;
9+
use OwenIt\Auditing\Contracts\Auditable;
10+
11+
class LegalAnalysisFile extends Model implements Auditable
12+
{
13+
use AuditableTrait;
14+
15+
protected $fillable = [
16+
'legal_analysis_id',
17+
'file_id',
18+
'status_id',
19+
];
20+
21+
protected $casts = [
22+
'status_id' => FileStatus::class,
23+
];
24+
25+
public function analysis(): BelongsTo
26+
{
27+
return $this->belongsTo(LegalAnalysis::class);
28+
}
29+
30+
public function file(): BelongsTo
31+
{
32+
return $this->belongsTo(File::class);
33+
}
34+
}

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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use App\Enums\FileStatus;
6+
use App\Models\File;
7+
use App\Models\LegalAnalysis;
8+
use App\Models\LegalAnalysisFile;
9+
use Illuminate\Database\Eloquent\Factories\Factory;
10+
11+
/**
12+
* @extends Factory<LegalAnalysisFile>
13+
*/
14+
class LegalAnalysisFileFactory extends Factory
15+
{
16+
/**
17+
* Define the model's default state.
18+
*
19+
* @return array<string, mixed>
20+
*/
21+
public function definition(): array
22+
{
23+
return [
24+
'legal_analysis_id' => LegalAnalysis::inRandomOrder()->first()?->id ?? LegalAnalysis::factory(),
25+
'file_id' => File::inRandomOrder()->first()?->id ?? File::factory(),
26+
'status_id' => $this->faker->randomElement(FileStatus::values()),
27+
];
28+
}
29+
}
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: 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_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+
$table->unique(['legal_analysis_id', 'file_id']);
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*/
27+
public function down(): void
28+
{
29+
Schema::dropIfExists('legal_analysis_files');
30+
}
31+
};

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
}

0 commit comments

Comments
 (0)