diff --git a/be/app/Http/Controllers/TeamController.php b/be/app/Http/Controllers/TeamController.php index e60ae7e..8b2a103 100644 --- a/be/app/Http/Controllers/TeamController.php +++ b/be/app/Http/Controllers/TeamController.php @@ -17,77 +17,4 @@ class TeamController extends Controller $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 -}'); - } } diff --git a/be/app/Http/Resources/TeamCollection.php b/be/app/Http/Resources/TeamCollection.php new file mode 100644 index 0000000..17313fc --- /dev/null +++ b/be/app/Http/Resources/TeamCollection.php @@ -0,0 +1,25 @@ + $this->collection, + 'status' => 200, + ]; + } + +} diff --git a/be/app/Http/Resources/TeamResource.php b/be/app/Http/Resources/TeamResource.php new file mode 100644 index 0000000..446f202 --- /dev/null +++ b/be/app/Http/Resources/TeamResource.php @@ -0,0 +1,26 @@ + $this->id, + 'name' => $this->name, + 'employees' => UserResource::collection($this->users), + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} diff --git a/be/app/Http/Resources/UserCollection.php b/be/app/Http/Resources/UserCollection.php new file mode 100644 index 0000000..8655460 --- /dev/null +++ b/be/app/Http/Resources/UserCollection.php @@ -0,0 +1,21 @@ + $this->collection, + ]; + } +} diff --git a/be/app/Http/Resources/UserResource.php b/be/app/Http/Resources/UserResource.php new file mode 100644 index 0000000..8b2d209 --- /dev/null +++ b/be/app/Http/Resources/UserResource.php @@ -0,0 +1,28 @@ + $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, + ]; + } +} diff --git a/be/routes/api.php b/be/routes/api.php index 79c6173..d4c609e 100644 --- a/be/routes/api.php +++ b/be/routes/api.php @@ -1,8 +1,8 @@ user(); //}); -Route::get('/v1/teams', [TeamController::class, 'get']); +Route::get('/v1/teams', function () { + return new TeamCollection(Team::all()); +});