mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
GET teams - resources
This commit is contained in:
1 parent
7c45871646
commit
876a67604d
6 files changed
+105
-76
No files matched your search
@@ -17,77 +17,4 @@ class TeamController extends Controller
|
|||||||
$this->middleware('api');
|
$this->middleware('api');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get()
|
|
||||||
{
|
|
||||||
return json_decode('{
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "Team 111",
|
|
||||||
"employees": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "Rastislav",
|
|
||||||
"surname": "Kuttner"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"name": "Lenka",
|
|
||||||
"surname": "Nemeckova"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Peter",
|
|
||||||
"surname": "Bucan"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"name": "Team 2",
|
|
||||||
"employees": [
|
|
||||||
{
|
|
||||||
"id": 4,
|
|
||||||
"name": "Peter",
|
|
||||||
"surname": "Bucan"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 5,
|
|
||||||
"name": "Pavel",
|
|
||||||
"surname": "Gajdos"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Team 3",
|
|
||||||
"employees": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "Rastislav",
|
|
||||||
"surname": "Kuttner"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"name": "Lenka",
|
|
||||||
"surname": "Nemeckova"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"name": "Peter",
|
|
||||||
"surname": "Bucan"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"status": 200
|
|
||||||
}');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class TeamCollection 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,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class TeamResource 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->name,
|
||||||
|
'employees' => UserResource::collection($this->users),
|
||||||
|
'created_at' => $this->created_at,
|
||||||
|
'updated_at' => $this->updated_at,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class UserCollection 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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class UserResource 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->firstname,
|
||||||
|
'surname' => $this->lastname,
|
||||||
|
'code' => $this->code,
|
||||||
|
'work_start' => $this->work_start,
|
||||||
|
'work_end' => $this->work_end,
|
||||||
|
'created_at' => $this->created_at,
|
||||||
|
'updated_at' => $this->updated_at,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-3
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use App\Http\Resources\TeamCollection;
|
||||||
|
use App\Models\Team;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\TeamController;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -19,4 +19,6 @@ use App\Http\Controllers\TeamController;
|
|||||||
// return $request->user();
|
// return $request->user();
|
||||||
//});
|
//});
|
||||||
|
|
||||||
Route::get('/v1/teams', [TeamController::class, 'get']);
|
Route::get('/v1/teams', function () {
|
||||||
|
return new TeamCollection(Team::all());
|
||||||
|
});
|
||||||
Reference in new issue
Block a user