mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
GET mastertasks, GET mastertasks/{id} endpointy
This commit is contained in:
1 parent
dfac41f30a
commit
ba6b9e20a5
16 files changed
+210
-12
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class AttachmentResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $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,
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class MasterTaskCollection extends ResourceCollection
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource collection into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'data' => $this->collection,
|
||||||
|
'status' => 200,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class MasterTaskResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $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),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class SubTaskResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $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),
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class TimeblockResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'start' => $this->start,
|
||||||
|
'end' => $this->end,
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,8 @@ class Attachment extends Model
|
|||||||
|
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|
||||||
public function subtask()
|
public function mastertask()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(SubTask::class);
|
return $this->belongsTo(MasterTask::class, 'master_task_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,4 +30,14 @@ class MasterTask extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Team::class);
|
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());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,6 @@ class Project extends Model
|
|||||||
|
|
||||||
public function mastertasks()
|
public function mastertasks()
|
||||||
{
|
{
|
||||||
return $this->hasMany(MasterTask::class);
|
return $this->hasMany(MasterTask::class, 'master_task_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,12 +13,12 @@ class SubTask extends Model
|
|||||||
|
|
||||||
public function mastertask()
|
public function mastertask()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(MasterTask::class);
|
return $this->belongsTo(MasterTask::class, 'master_task_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(MasterTask::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function timeblocks()
|
public function timeblocks()
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ class Timeblock extends Model
|
|||||||
|
|
||||||
public function subtask()
|
public function subtask()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(SubTask::class);
|
return $this->belongsTo(SubTask::class, 'sub_task_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ class Timesheet extends Model
|
|||||||
|
|
||||||
public function subtask()
|
public function subtask()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(SubTask::class);
|
return $this->belongsTo(SubTask::class, 'sub_task_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class MasterTaskFactory extends Factory
|
|||||||
'project_id' => $project->id,
|
'project_id' => $project->id,
|
||||||
'team_id' => $team->id,
|
'team_id' => $team->id,
|
||||||
'title' => 'Master task ' . fake()->words(2, true),
|
'title' => 'Master task ' . fake()->words(2, true),
|
||||||
|
'description' => fake()->paragraphs(3, true),
|
||||||
'estimated_time' => fake()->numberBetween(20,100),
|
'estimated_time' => fake()->numberBetween(20,100),
|
||||||
'tracked_time' => fake()->numberBetween(4,20),
|
'tracked_time' => fake()->numberBetween(4,20),
|
||||||
'deadline' => fake()->date(),
|
'deadline' => fake()->date(),
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ class SubTaskFactory extends Factory
|
|||||||
*/
|
*/
|
||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
$client = \App\Models\Client::all()->random();
|
$user = \App\Models\User::all()->random();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'user_id' => $client->id,
|
'user_id' => $user->id,
|
||||||
'estimated_time' => fake()->numberBetween(1,16),
|
'estimated_time' => fake()->numberBetween(1,16),
|
||||||
'tracked_time' => fake()->numberBetween(4,20),
|
'tracked_time' => fake()->numberBetween(4,20),
|
||||||
'is_finished' => 0,
|
'is_finished' => 0,
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('master_tasks', function (Blueprint $table) {
|
||||||
|
$table->longText('description')->after('title');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('master_task', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
+12
-2
@@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Resources\MasterTaskCollection;
|
||||||
|
use App\Http\Resources\MasterTaskResource;
|
||||||
use App\Http\Resources\ProjectCollection;
|
use App\Http\Resources\ProjectCollection;
|
||||||
use App\Http\Resources\TeamCollection;
|
use App\Http\Resources\TeamCollection;
|
||||||
use App\Http\Resources\TeamResource;
|
use App\Http\Resources\TeamResource;
|
||||||
use App\Http\Resources\UserCollection;
|
use App\Http\Resources\UserCollection;
|
||||||
use App\Http\Resources\UserResource;
|
use App\Http\Resources\UserResource;
|
||||||
|
use App\Models\MasterTask;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\Team;
|
use App\Models\Team;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -37,13 +40,20 @@ Route::get('/v1/employees', function () {
|
|||||||
return new UserCollection(User::all());
|
return new UserCollection(User::all());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Route::get('/v1/employees/{id}', function ($id) {
|
Route::get('/v1/employees/{id}', function ($id) {
|
||||||
return new UserResource(User::find($id));
|
return new UserResource(User::find($id));
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/public/v1/projects', function () {
|
Route::get('/v1/projects', function () {
|
||||||
return new ProjectCollection(Project::all());
|
return new ProjectCollection(Project::all());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::get('/v1/mastertasks', function () {
|
||||||
|
return new MasterTaskCollection( MasterTask::all());
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::get('/v1/mastertasks/{id}', function ($id) {
|
||||||
|
return new MasterTaskResource( MasterTask::find($id));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
+3
-1
@@ -21,7 +21,9 @@ Route::get('/', function () {
|
|||||||
|
|
||||||
Route::prefix('be')->group(function () {
|
Route::prefix('be')->group(function () {
|
||||||
Route::get('/test', function () {
|
Route::get('/test', function () {
|
||||||
dd('here');
|
$subtask = \App\Models\SubTask::with('mastertask')->find(1);
|
||||||
|
|
||||||
|
dd($subtask);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user