diff --git a/app/Http/Controllers/Dashboard/ProjectController.php b/app/Http/Controllers/Dashboard/ProjectController.php index 6e1613a..e119758 100644 --- a/app/Http/Controllers/Dashboard/ProjectController.php +++ b/app/Http/Controllers/Dashboard/ProjectController.php @@ -14,7 +14,9 @@ class ProjectController public function __construct( private ProjectRepository $projectRepository - ) {} + ) { + $this->projectRepository->auth = true; + } public function edit(Project $project): View { diff --git a/app/Http/Requests/ProjectRequest.php b/app/Http/Requests/ProjectRequest.php index 7183a34..1c9e546 100644 --- a/app/Http/Requests/ProjectRequest.php +++ b/app/Http/Requests/ProjectRequest.php @@ -32,6 +32,7 @@ class ProjectRequest extends FormRequest 'project_url' => 'nullable|string', 'project_version' => 'nullable|string', 'description' => 'nullable|string', + 'visible' => 'nullable|in:yes,1,true,on' ]; } } diff --git a/app/Http/Resources/ProjectResource.php b/app/Http/Resources/ProjectResource.php index 1b7e67a..01fd678 100644 --- a/app/Http/Resources/ProjectResource.php +++ b/app/Http/Resources/ProjectResource.php @@ -24,7 +24,7 @@ class ProjectResource extends JsonResource 'author' => $this->author, 'images' => $this->images, 'release_date' => $this->release_date, - 'update_date' => $this->release_date, + 'update_date' => $this->update_date, 'project_url' => $this->project_url, 'project_version' => $this->project_version, 'description' => $this->description, diff --git a/app/Models/Project.php b/app/Models/Project.php index 56a296b..d20a3b4 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Carbon; +use Illuminate\Database\Eloquent\Builder; /** * @property int $id @@ -38,7 +38,8 @@ class Project extends Model 'update_date' => 'datetime:Y-m-d', 'project_url' => 'string', 'project_version' => 'string', - 'description' => 'string' + 'description' => 'string', + 'visible' => 'boolean' ]; public function getReleaseDateAttribute($value): String @@ -64,4 +65,9 @@ class Project extends Model $this->attributes['update_date'] = null; } + public function scopeVisibled(Builder $builder) + { + return $builder->where('visible', true); + } + } diff --git a/app/Repository/ProjectRepository.php b/app/Repository/ProjectRepository.php index 3eb1280..765b215 100644 --- a/app/Repository/ProjectRepository.php +++ b/app/Repository/ProjectRepository.php @@ -8,12 +8,13 @@ use App\Http\Resources\ProjectCollection; use App\Http\Resources\ProjectResource; use App\Models\Project; use App\Repository\Interfaces\ProjectRepository as ProjectRepositoryInterface; -use Illuminate\Support\Carbon; use Illuminate\Support\Collection; class ProjectRepository implements ProjectRepositoryInterface { + public bool $auth = false; + public function __construct( private Project $project ) {} @@ -22,17 +23,23 @@ class ProjectRepository implements ProjectRepositoryInterface { $project = $this->project ->query() - ->orderBy('release_data', 'ASC') - ->get(); - return (new ProjectCollection($project))->collection; + ->orderBy('release_data', 'ASC'); + + if (!$this->auth) + $project->visibled(); + + return (new ProjectCollection($project->get()))->collection; } public function get(int $id): ProjectResource { $project = $this->project - ->query() - ->findOrFail($id); - return new ProjectResource($project); + ->query(); + + if (!$this->auth) + $project->visibled(); + + return new ProjectResource($project->findOrFail($id)); } public function update(Project $project, array $data = []): bool @@ -87,6 +94,12 @@ class ProjectRepository implements ProjectRepositoryInterface else $toSave['update_date'] = null; + if ( + isset($data['visible']) && + in_array($data['visible'], ['yes', 'on', 1, true]) + ) $toSave['visible'] = true; + else $toSave['visible'] = false; + return $toSave; } diff --git a/database/migrations/2022_02_09_075749_create_projects_table.php b/database/migrations/2022_02_09_075749_create_projects_table.php index 692946f..bce3725 100644 --- a/database/migrations/2022_02_09_075749_create_projects_table.php +++ b/database/migrations/2022_02_09_075749_create_projects_table.php @@ -27,6 +27,7 @@ class CreateProjectsTable extends Migration $table->string('project_url', 255)->nullable()->default(null); $table->string('project_version', 20)->nullable()->default(null); $table->text('description')->nullable()->default(null); + $table->boolean('visible')->nullable()->default(false); $table->timestamps(); }); } diff --git a/resources/views/dashboard/projects/edit.blade.php b/resources/views/dashboard/projects/edit.blade.php index d221283..ab34d20 100644 --- a/resources/views/dashboard/projects/edit.blade.php +++ b/resources/views/dashboard/projects/edit.blade.php @@ -68,7 +68,7 @@