diff --git a/be/app/Http/Resources/AttachmentResource.php b/be/app/Http/Resources/AttachmentResource.php new file mode 100644 index 0000000..00ae34b --- /dev/null +++ b/be/app/Http/Resources/AttachmentResource.php @@ -0,0 +1,28 @@ + $this->id, + 'content_type' => $this->content_type, + 'disk_name' => $this->disk_name, + 'extension' => $this->estimated_time, + 'name' => $this->original_name, + 'file_size' => $this->file_size, + 'path' => $this->path, + + ]; + } +} diff --git a/be/app/Http/Resources/MasterTaskCollection.php b/be/app/Http/Resources/MasterTaskCollection.php new file mode 100644 index 0000000..7762053 --- /dev/null +++ b/be/app/Http/Resources/MasterTaskCollection.php @@ -0,0 +1,25 @@ + $this->collection, + 'status' => 200, + ]; + } + +} diff --git a/be/app/Http/Resources/MasterTaskResource.php b/be/app/Http/Resources/MasterTaskResource.php new file mode 100644 index 0000000..bf0ced3 --- /dev/null +++ b/be/app/Http/Resources/MasterTaskResource.php @@ -0,0 +1,33 @@ + $this->id, + 'name' => $this->title, + 'description' => $this->description, + 'duration' => $this->estimated_time, + 'time_worked' => $this->tracked_time, + 'is_finished' => $this->is_finished, + 'starts_at' => $this->created_at, + 'deadline' => $this->deadline, + 'project_code' => $this->project->code, + 'team_id' => $this->team->id, + 'employees' => UserResource::collection($this->usersOutsideTeam), + 'subtasks' => SubTaskResource::collection($this->subtasks), + 'files' => AttachmentResource::collection($this->attachments), + ]; + } +} diff --git a/be/app/Http/Resources/SubTaskResource.php b/be/app/Http/Resources/SubTaskResource.php new file mode 100644 index 0000000..68a7838 --- /dev/null +++ b/be/app/Http/Resources/SubTaskResource.php @@ -0,0 +1,33 @@ + $this->id, + 'description' => $this->mastertask->description, + 'project_code' => $this->mastertask->project->code, + 'master_task_id' => $this->mastertask->id, + 'master_task' => $this->mastertask->title, + 'team_id' => $this->mastertask->team->id, + 'team' => $this->mastertask->team, + 'employee_id' => $this->user->id, + 'duration' => $this->estimated_time, + 'spent_time' => $this->tracked_time, + 'is_finished' => $this->is_finished, + 'timeblocks' => TimeblockResource::collection($this->timeblocks), + ]; + + } +} diff --git a/be/app/Http/Resources/TimeblockResource.php b/be/app/Http/Resources/TimeblockResource.php new file mode 100644 index 0000000..63d55a4 --- /dev/null +++ b/be/app/Http/Resources/TimeblockResource.php @@ -0,0 +1,24 @@ + $this->id, + 'start' => $this->start, + 'end' => $this->end, + ]; + + } +} diff --git a/be/app/Models/Attachment.php b/be/app/Models/Attachment.php index 5ad608d..31debad 100644 --- a/be/app/Models/Attachment.php +++ b/be/app/Models/Attachment.php @@ -11,8 +11,8 @@ class Attachment extends Model public $timestamps = true; - public function subtask() + public function mastertask() { - return $this->belongsTo(SubTask::class); + return $this->belongsTo(MasterTask::class, 'master_task_id'); } } diff --git a/be/app/Models/MasterTask.php b/be/app/Models/MasterTask.php index db4ecbe..cdd6466 100644 --- a/be/app/Models/MasterTask.php +++ b/be/app/Models/MasterTask.php @@ -30,4 +30,14 @@ class MasterTask extends Model { return $this->belongsTo(Team::class); } + + // vracia userov, ktori su priradeni k subtasku ale nepatria do teamu + public function getUsersOutsideTeamAttribute() + { + $users = $this->subtasks->pluck('user')->unique(); + + return $users->filter(function ($user) { + return !in_array($this->team->id, $user->teams->pluck('id')->unique()->toArray()); + }); + } } diff --git a/be/app/Models/Project.php b/be/app/Models/Project.php index 2b76a5e..b3e3d46 100644 --- a/be/app/Models/Project.php +++ b/be/app/Models/Project.php @@ -18,6 +18,6 @@ class Project extends Model public function mastertasks() { - return $this->hasMany(MasterTask::class); + return $this->hasMany(MasterTask::class, 'master_task_id'); } } diff --git a/be/app/Models/SubTask.php b/be/app/Models/SubTask.php index 4736f8a..a2ffa16 100644 --- a/be/app/Models/SubTask.php +++ b/be/app/Models/SubTask.php @@ -13,12 +13,12 @@ class SubTask extends Model public function mastertask() { - return $this->belongsTo(MasterTask::class); + return $this->belongsTo(MasterTask::class, 'master_task_id'); } public function user() { - return $this->belongsTo(MasterTask::class); + return $this->belongsTo(User::class); } public function timeblocks() diff --git a/be/app/Models/Timeblock.php b/be/app/Models/Timeblock.php index fe0cc3c..7390e40 100644 --- a/be/app/Models/Timeblock.php +++ b/be/app/Models/Timeblock.php @@ -13,6 +13,6 @@ class Timeblock extends Model public function subtask() { - return $this->belongsTo(SubTask::class); + return $this->belongsTo(SubTask::class, 'sub_task_id'); } } diff --git a/be/app/Models/Timesheet.php b/be/app/Models/Timesheet.php index b61a4fc..71ae475 100644 --- a/be/app/Models/Timesheet.php +++ b/be/app/Models/Timesheet.php @@ -13,7 +13,7 @@ class Timesheet extends Model public function subtask() { - return $this->belongsTo(SubTask::class); + return $this->belongsTo(SubTask::class, 'sub_task_id'); } public function user() diff --git a/be/database/factories/MasterTaskFactory.php b/be/database/factories/MasterTaskFactory.php index 856f5e7..892678d 100644 --- a/be/database/factories/MasterTaskFactory.php +++ b/be/database/factories/MasterTaskFactory.php @@ -33,6 +33,7 @@ class MasterTaskFactory extends Factory 'project_id' => $project->id, 'team_id' => $team->id, 'title' => 'Master task ' . fake()->words(2, true), + 'description' => fake()->paragraphs(3, true), 'estimated_time' => fake()->numberBetween(20,100), 'tracked_time' => fake()->numberBetween(4,20), 'deadline' => fake()->date(), diff --git a/be/database/factories/SubTaskFactory.php b/be/database/factories/SubTaskFactory.php index ae7ec72..85643be 100644 --- a/be/database/factories/SubTaskFactory.php +++ b/be/database/factories/SubTaskFactory.php @@ -19,10 +19,10 @@ class SubTaskFactory extends Factory */ public function definition() { - $client = \App\Models\Client::all()->random(); + $user = \App\Models\User::all()->random(); return [ - 'user_id' => $client->id, + 'user_id' => $user->id, 'estimated_time' => fake()->numberBetween(1,16), 'tracked_time' => fake()->numberBetween(4,20), 'is_finished' => 0, diff --git a/be/database/migrations/2023_01_24_205922_add_description_to_master_task.php b/be/database/migrations/2023_01_24_205922_add_description_to_master_task.php new file mode 100644 index 0000000..70cf729 --- /dev/null +++ b/be/database/migrations/2023_01_24_205922_add_description_to_master_task.php @@ -0,0 +1,32 @@ +longText('description')->after('title'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('master_task', function (Blueprint $table) { + // + }); + } +}; diff --git a/be/routes/api.php b/be/routes/api.php index 5e6e9de..36af5ce 100644 --- a/be/routes/api.php +++ b/be/routes/api.php @@ -1,10 +1,13 @@ group(function () { Route::get('/test', function () { - dd('here'); + $subtask = \App\Models\SubTask::with('mastertask')->find(1); + + dd($subtask); }); });