ml-archive / nodes-php-backend

Nodes backend package
http://nodesagency.com
MIT License
11 stars 5 forks source link

Wrong data return when using backend user as API #107

Closed joscdk closed 7 years ago

joscdk commented 8 years ago

route

Route::group(['namespace'  => 'NStack\Controllers\Api\Project',
              'prefix'     => 'admin/deployments',
              'middleware' => ['backend.api.auth'],
], function () {
    Route::get('/', 'DeploymentsController@index');
});

controller

return $this->response->collection($queue, new DeploymentQueueTransformer)->setStatusCode(200);

response

[
  {
    "id": 46,
    "project_id": 10010093,
  },
  {
    "id": 45,
    "project_id": 10010092,
  }
]

The JSON is in a parent array, and Transformer isn't used.

Casperhr commented 8 years ago

@rugaard can you have a look at this

pcoutinho commented 7 years ago

From my investigation I conclude that this issue is cause by the usage of /admin as an API endpoint. API routes are registered with the API route helpers (like api_get()).

Since the routes in question are being registered through the Route facade, all the Dingo setup is not being made, resulting in custom adapters and transformers not being used.

@Casperhr @rugaard can you please verify?

rugaard commented 7 years ago

@Skyback You're pretty much accurate. It was never intended to use transformers for a "backend endpoint". There you should simply use response()->json() to return JSON.

When you're using the api_ methods the routes are - as you say - registered with Dingo, which is setup to return the structure with the data as root.

pcoutinho commented 7 years ago

@rugaard Thanks for the confirmation. Will close this issue since it's due to bad implementation.