Skip to content

Commit

Permalink
project and relations
Browse files Browse the repository at this point in the history
  • Loading branch information
rigonlucas committed Sep 8, 2024
1 parent 6de6431 commit 58f3bd7
Show file tree
Hide file tree
Showing 33 changed files with 367 additions and 95 deletions.
12 changes: 6 additions & 6 deletions app/Http/Controllers/V1/Project/UploadProjectFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Core\Application\File\Shared\Gateways\FileCommandInterface;
use Core\Application\Project\Shared\Gateways\ProjectMapperInterface;
use Core\Application\Shared\Inputs\FiletInput;
use Core\Domain\Enum\File\ContextFileEnum;
use Core\Domain\Enum\File\ExtensionsEnum;
use Core\Domain\Enum\File\TypeFileEnum;
use Core\Domain\Enum\File\FileContextEnum;
use Core\Domain\Enum\File\FileExtensionsEnum;
use Core\Domain\Enum\File\FileTypeEnum;
use Core\Domain\ValueObjects\BytesValueObject;
use Core\Presentation\Http\Errors\ErrorPresenter;
use Core\Services\Framework\FrameworkContract;
Expand All @@ -32,10 +32,10 @@ public function __invoke(UploadProjectFileRequest $request, string $uuid)
$uploadedFile = $request->file('file');
$input = new FiletInput(
name: $uploadedFile->name,
type: TypeFileEnum::DOCUMENT,
type: FileTypeEnum::DOCUMENT,
size: new BytesValueObject($uploadedFile->getSize()),
extension: ExtensionsEnum::from($uploadedFile->getClientOriginalExtension()),
contextFile: ContextFileEnum::PROJECT,
extension: FileExtensionsEnum::from($uploadedFile->getClientOriginalExtension()),
contextFile: FileContextEnum::PROJECT,
uuid: Uuid::fromString($uuid)
);
try {
Expand Down
13 changes: 13 additions & 0 deletions app/Models/FlowStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Support\Models\HasCreatedByUser;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -13,10 +14,12 @@ class FlowStep extends Model
use HasFactory;
use SoftDeletes;
use HasUuids;
use HasCreatedByUser;

public $incrementing = false;
protected $primaryKey = 'uuid';
protected $keyType = 'string';
protected $table = 'flow_steps';

protected $fillable = [
'uuid',
Expand All @@ -30,4 +33,14 @@ public function flow(): BelongsTo
{
return $this->belongsTo(Flow::class, 'flow_uuid', 'uuid');
}

public function nextStep(): BelongsTo
{
return $this->belongsTo(FlowStep::class, 'flow_step_uuid', 'uuid');
}

public function integration(): BelongsTo
{
return $this->belongsTo(FlowStepIntegration::class, '', 'uuid');
}
}
20 changes: 20 additions & 0 deletions app/Models/FlowStepIntegration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class FlowStepIntegration extends Model
{
use HasFactory;
use SoftDeletes;
use HasUuids;

public $incrementing = false;
protected $primaryKey = 'uuid';
protected $keyType = 'string';
protected $table = 'flow_steps';
}
29 changes: 25 additions & 4 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace App\Models;

use App\Support\Models\HasCreatedByUser;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
use Ramsey\Uuid\UuidInterface;

Expand All @@ -26,6 +29,7 @@ class Project extends Model
use HasFactory;
use SoftDeletes;
use HasUuids;
use HasCreatedByUser;

public $incrementing = false;
/**
Expand All @@ -46,13 +50,30 @@ class Project extends Model
'uuid',
];

public function createdByUser(): BelongsTo
public function account(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_user_uuid');
return $this->belongsTo(Account::class, 'account_uuid');
}

public function account(): BelongsTo
public function files(): HasMany
{
return $this->belongsTo(Account::class, 'account_uuid');
return $this->hasMany(ProjectFile::class, 'project_uuid', 'uuid');
}

public function cards(): HasMany
{
return $this->hasMany(ProjectCard::class, 'project_uuid', 'uuid');
}

public function tasks(): HasManyThrough
{
return $this->hasManyThrough(
Task::class,
ProjectTask::class,
'project_uuid',
'uuid',
'uuid',
'task_uuid'
);
}
}
2 changes: 2 additions & 0 deletions app/Models/ProjectCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Support\Models\HasCreatedByUser;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -13,6 +14,7 @@ class ProjectCard extends Model
use HasFactory;
use SoftDeletes;
use HasUuids;
use HasCreatedByUser;

public $incrementing = false;
protected $primaryKey = 'uuid';
Expand Down
23 changes: 10 additions & 13 deletions app/Models/ProjectFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace App\Models;

use Core\Domain\Enum\File\ContextFileEnum;
use Core\Domain\Enum\File\ExtensionsEnum;
use Core\Domain\Enum\File\StatusFileEnum;
use Core\Domain\Enum\File\TypeFileEnum;
use App\Support\Models\HasCreatedByUser;
use Core\Domain\Enum\File\FileContextEnum;
use Core\Domain\Enum\File\FileExtensionsEnum;
use Core\Domain\Enum\File\FileStatusEnum;
use Core\Domain\Enum\File\FileTypeEnum;
use Core\Domain\ValueObjects\BytesValueObject;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -19,19 +20,20 @@
* @property mixed|UuidInterface $account_uuid
* @property mixed|string $file_name
* @property mixed|string $file_path
* @property TypeFileEnum|mixed $file_type
* @property FileTypeEnum|mixed $file_type
* @property BytesValueObject|mixed $file_size
* @property ExtensionsEnum|mixed $file_extension
* @property FileExtensionsEnum|mixed $file_extension
* @property mixed $project_uuid
* @property mixed $created_by_user_uuid
* @property ContextFileEnum|mixed $context
* @property StatusFileEnum|mixed $status
* @property FileContextEnum|mixed $context
* @property FileStatusEnum|mixed $status
*/
class ProjectFile extends Model
{
use HasFactory;
use SoftDeletes;
use HasUuids;
use HasCreatedByUser;

public $incrementing = false;
protected $table = 'project_files';
Expand All @@ -51,11 +53,6 @@ class ProjectFile extends Model
'status',
];

public function createdByUser(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_user_uuid');
}

public function account(): BelongsTo
{
return $this->belongsTo(Account::class, 'account_uuid');
Expand Down
2 changes: 2 additions & 0 deletions app/Models/ProjectTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Models;

use App\Support\Models\HasCreatedByUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ProjectTask extends Model
{
use HasFactory;
use HasCreatedByUser;

protected $table = 'project_tasks';

Expand Down
2 changes: 2 additions & 0 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Support\Models\HasCreatedByUser;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -13,6 +14,7 @@ class Task extends Model
use HasFactory;
use SoftDeletes;
use HasUuids;
use HasCreatedByUser;

public $incrementing = false;
protected $primaryKey = 'uuid';
Expand Down
14 changes: 14 additions & 0 deletions app/Support/Models/HasCreatedByUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Support\Models;

use App\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

trait HasCreatedByUser
{
public function createdByUser(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_user_uuid');
}
}
12 changes: 6 additions & 6 deletions core/Application/Shared/Inputs/FiletInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Core\Application\Shared\Inputs;

use Core\Domain\Enum\File\ContextFileEnum;
use Core\Domain\Enum\File\ExtensionsEnum;
use Core\Domain\Enum\File\TypeFileEnum;
use Core\Domain\Enum\File\FileContextEnum;
use Core\Domain\Enum\File\FileExtensionsEnum;
use Core\Domain\Enum\File\FileTypeEnum;
use Core\Domain\ValueObjects\BytesValueObject;
use Ramsey\Uuid\UuidInterface;

Expand All @@ -13,10 +13,10 @@

public function __construct(
public string $name,
public TypeFileEnum $type,
public FileTypeEnum $type,
public BytesValueObject $size,
public ExtensionsEnum $extension,
public ContextFileEnum $contextFile,
public FileExtensionsEnum $extension,
public FileContextEnum $contextFile,
public UuidInterface $uuid
) {
}
Expand Down
34 changes: 17 additions & 17 deletions core/Domain/Entities/File/Root/FileEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Core\Domain\Entities\File\Root;

use Core\Domain\Entities\Shared\User\Root\UserEntity;
use Core\Domain\Enum\File\ContextFileEnum;
use Core\Domain\Enum\File\ExtensionsEnum;
use Core\Domain\Enum\File\StatusFileEnum;
use Core\Domain\Enum\File\TypeFileEnum;
use Core\Domain\Enum\File\FileContextEnum;
use Core\Domain\Enum\File\FileExtensionsEnum;
use Core\Domain\Enum\File\FileStatusEnum;
use Core\Domain\Enum\File\FileTypeEnum;
use Core\Domain\ValueObjects\BytesValueObject;
use Core\Domain\ValueObjects\File\FilePathValueObjectInterface;
use InvalidArgumentException;
Expand All @@ -22,12 +22,12 @@ class FileEntity
private string $ulidFileName;
private string $name;
private FilePathValueObjectInterface $filePathValueObject;
private TypeFileEnum $type;
private FileTypeEnum $type;
private BytesValueObject $size;
private ExtensionsEnum $extension;
private FileExtensionsEnum $extension;
private UserEntity $userEntity;
private ContextFileEnum $context;
private StatusFileEnum $status;
private FileContextEnum $context;
private FileStatusEnum $status;

private function __construct()
{
Expand Down Expand Up @@ -65,12 +65,12 @@ public function setFilePathValueObject(FilePathValueObjectInterface $filePathVal
$this->filePathValueObject = $filePathValueObject;
}

public function getType(): TypeFileEnum
public function getType(): FileTypeEnum
{
return $this->type;
}

public function setType(TypeFileEnum $type): void
public function setType(FileTypeEnum $type): void
{
$this->type = $type;
}
Expand All @@ -85,32 +85,32 @@ public function setSize(BytesValueObject $size): void
$this->size = $size;
}

public function getContext(): ContextFileEnum
public function getContext(): FileContextEnum
{
return $this->context;
}

public function setContext(ContextFileEnum $context): void
public function setContext(FileContextEnum $context): void
{
$this->context = $context;
}

public function getStatus(): StatusFileEnum
public function getStatus(): FileStatusEnum
{
return $this->status;
}

public function setStatus(StatusFileEnum $status): void
public function setStatus(FileStatusEnum $status): void
{
$this->status = $status;
}

public function getExtension(): ExtensionsEnum
public function getExtension(): FileExtensionsEnum
{
return $this->extension;
}

public function setExtension(ExtensionsEnum $extension): void
public function setExtension(FileExtensionsEnum $extension): void
{
$this->extension = $extension;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function setEntityUuid(UuidInterface $entityUuid): FileEntity

public function confirmUpload(): void
{
$this->status = StatusFileEnum::FINISHED;
$this->status = FileStatusEnum::FINISHED;
}

public function getUuid(): UuidInterface
Expand Down
Loading

0 comments on commit 58f3bd7

Please sign in to comment.