fix some edge cases
This commit is contained in:
@@ -46,6 +46,7 @@ class AirportController extends Controller
|
|||||||
|
|
||||||
//add pagination
|
//add pagination
|
||||||
$per_page = $request->input('per_page', 10);
|
$per_page = $request->input('per_page', 10);
|
||||||
|
$per_page = (empty($per_page)) ? 10 : $per_page;
|
||||||
$page = $request->input('page', 1);
|
$page = $request->input('page', 1);
|
||||||
$paginator = new LengthAwarePaginator(
|
$paginator = new LengthAwarePaginator(
|
||||||
$airportsCollection->forPage($page, $per_page),
|
$airportsCollection->forPage($page, $per_page),
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class FlightController extends Controller
|
|||||||
* @apiDescription List all defined flights
|
* @apiDescription List all defined flights
|
||||||
*
|
*
|
||||||
* @apiParam (query params) {number} [page=1] page to fetch
|
* @apiParam (query params) {number} [page=1] page to fetch
|
||||||
* @apiParam (query param) {number} [per_page=10] number of results to fetch per page
|
* @apiParam (query params) {number} [per_page=10] number of results to fetch per page
|
||||||
*
|
*
|
||||||
* @apiExample {curl} example
|
* @apiExample {curl} example
|
||||||
* curl -i http://localhost:8080/flights?page=1&per_page=10
|
* curl -i http://localhost:8080/flights?page=1&per_page=10
|
||||||
@@ -38,6 +38,7 @@ class FlightController extends Controller
|
|||||||
|
|
||||||
//add pagination
|
//add pagination
|
||||||
$per_page = $request->input('per_page', 10);
|
$per_page = $request->input('per_page', 10);
|
||||||
|
$per_page = (empty($per_page)) ? 10 : $per_page;
|
||||||
$page = $request->input('page', 1);
|
$page = $request->input('page', 1);
|
||||||
$paginator = new LengthAwarePaginator(
|
$paginator = new LengthAwarePaginator(
|
||||||
$flightCollection->forPage($page, $per_page),
|
$flightCollection->forPage($page, $per_page),
|
||||||
@@ -100,6 +101,6 @@ class FlightController extends Controller
|
|||||||
$deleted = $flight->delete();
|
$deleted = $flight->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(null, 204);
|
return response()->json(['message' => "flight $id has been removed"], 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class TripController extends Controller
|
|||||||
* @apiDescription This api returns a paginated list of trips found
|
* @apiDescription This api returns a paginated list of trips found
|
||||||
*
|
*
|
||||||
* @apiParam (query params) {number} [page=1] page to fetch
|
* @apiParam (query params) {number} [page=1] page to fetch
|
||||||
* @apiParam (query param) {number} [per_page=10] number of results to fetch per page
|
* @apiParam (query params) {number} [per_page=10] number of results to fetch per page
|
||||||
*
|
*
|
||||||
* @apiExample {curl} example
|
* @apiExample {curl} example
|
||||||
* curl -i http://localhost:8080/trips?page=1&per_page=10
|
* curl -i http://localhost:8080/trips?page=1&per_page=10
|
||||||
@@ -48,6 +48,7 @@ class TripController extends Controller
|
|||||||
|
|
||||||
//add pagination
|
//add pagination
|
||||||
$per_page = $request->input('per_page', 10);
|
$per_page = $request->input('per_page', 10);
|
||||||
|
$per_page = (empty($per_page)) ? 10 : $per_page;
|
||||||
$page = $request->input('page', 1);
|
$page = $request->input('page', 1);
|
||||||
$paginator = new LengthAwarePaginator(
|
$paginator = new LengthAwarePaginator(
|
||||||
$tripsCollection->forPage($page, $per_page),
|
$tripsCollection->forPage($page, $per_page),
|
||||||
@@ -96,8 +97,8 @@ class TripController extends Controller
|
|||||||
* @apiGroup Trips
|
* @apiGroup Trips
|
||||||
* @apiDescription send a destination to this endpoint to add a flight to the trip
|
* @apiDescription send a destination to this endpoint to add a flight to the trip
|
||||||
*
|
*
|
||||||
* @apiParam (form data) {string} destination the destination of the new flight
|
* @apiParam {string} destination the destination of the new flight
|
||||||
* @apiParam (url) {number} id the id of the trip to fetch
|
* @apiParam {number} id the id of the trip to fetch
|
||||||
*
|
*
|
||||||
* @apiExample {curl} example
|
* @apiExample {curl} example
|
||||||
* curl -i http://localhost:8080/trips/1/flights
|
* curl -i http://localhost:8080/trips/1/flights
|
||||||
|
|||||||
@@ -59,6 +59,20 @@ class AirportsCest
|
|||||||
$I->assertCount(2, $data->data, json_encode($data));
|
$I->assertCount(2, $data->data, json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function listAirportsDoesNotReturn500WhenPerPageIsInvalid(AcceptanceTester $I)
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
$I->sendGET($this->uri, $params);
|
||||||
|
$r = $I->grabResponse();
|
||||||
|
|
||||||
|
$I->seeResponseCodeIs(200, $r);
|
||||||
|
$I->seeResponseIsJson();
|
||||||
|
}
|
||||||
|
|
||||||
public function getAirportReturnsTripJson(AcceptanceTester $I)
|
public function getAirportReturnsTripJson(AcceptanceTester $I)
|
||||||
{
|
{
|
||||||
$I->sendGET($this->uri, []);
|
$I->sendGET($this->uri, []);
|
||||||
|
|||||||
@@ -59,6 +59,20 @@ class FlightsCest
|
|||||||
$I->assertCount(2, $data->data, json_encode($data));
|
$I->assertCount(2, $data->data, json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function listFlightsDoesNotReturn500WhenPerPageIsInvalid(AcceptanceTester $I)
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
$I->sendGET($this->uri, $params);
|
||||||
|
$r = $I->grabResponse();
|
||||||
|
|
||||||
|
$I->seeResponseCodeIs(200, $r);
|
||||||
|
$I->seeResponseIsJson();
|
||||||
|
}
|
||||||
|
|
||||||
public function listFlightsReturns0ItemWhenPageIsBeyondEndOfCollection(AcceptanceTester $I)
|
public function listFlightsReturns0ItemWhenPageIsBeyondEndOfCollection(AcceptanceTester $I)
|
||||||
{
|
{
|
||||||
$params = [
|
$params = [
|
||||||
|
|||||||
@@ -59,6 +59,20 @@ class TripsCest
|
|||||||
$I->assertCount(2, $data->data, json_encode($data));
|
$I->assertCount(2, $data->data, json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function listTripsDoesNotReturn500WhenPerPageIsInvalid(AcceptanceTester $I)
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
$I->sendGET($this->uri, $params);
|
||||||
|
$r = $I->grabResponse();
|
||||||
|
|
||||||
|
$I->seeResponseCodeIs(200, $r);
|
||||||
|
$I->seeResponseIsJson();
|
||||||
|
}
|
||||||
|
|
||||||
public function getTripReturnsTripJson(AcceptanceTester $I)
|
public function getTripReturnsTripJson(AcceptanceTester $I)
|
||||||
{
|
{
|
||||||
$I->sendGET($this->uri, []);
|
$I->sendGET($this->uri, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user