Fix PirepComment response; 201 to 200 (#654)

This commit is contained in:
Nabeel S
2020-04-01 01:05:09 -04:00
committed by GitHub
parent e8037c7d69
commit 261984ee90
6 changed files with 44 additions and 15 deletions

View File

@@ -168,8 +168,18 @@ class PirepController extends Controller
*/ */
public function get($id) public function get($id)
{ {
$with = [
'acars',
'arr_airport',
'dpt_airport',
'comments',
'flight',
'simbrief',
'user',
];
$pirep = $this->pirepRepo $pirep = $this->pirepRepo
->with(['acars', 'arr_airport', 'dpt_airport', 'comments', 'flight', 'simbrief', 'user']) ->with($with)
->find($id); ->find($id);
return new PirepResource($pirep); return new PirepResource($pirep);

View File

@@ -68,7 +68,7 @@ class Pirep extends Resource
$res['arr_airport'] = new Airport($this->arr_airport); $res['arr_airport'] = new Airport($this->arr_airport);
$res['position'] = Acars::make($this->whenLoaded('position')); $res['position'] = Acars::make($this->whenLoaded('position'));
$res['comments'] = PirepComment::make($this->whenLoaded('comments')); $res['comments'] = PirepComment::collection($this->whenLoaded('comments'));
$res['user'] = User::make($this->whenLoaded('user')); $res['user'] = User::make($this->whenLoaded('user'));
$res['flight'] = Flight::make($this->whenLoaded('flight')); $res['flight'] = Flight::make($this->whenLoaded('flight'));

View File

@@ -4,6 +4,9 @@ namespace App\Http\Resources;
use App\Contracts\Resource; use App\Contracts\Resource;
/**
* @mixin \App\Models\PirepComment
*/
class PirepComment extends Resource class PirepComment extends Resource
{ {
/** /**
@@ -15,6 +18,10 @@ class PirepComment extends Resource
*/ */
public function toArray($request) public function toArray($request)
{ {
if (!$this->user) {
return [];
}
$user = $this->user; $user = $this->user;
return [ return [

View File

@@ -5,8 +5,10 @@ namespace App\Models;
use App\Contracts\Model; use App\Contracts\Model;
/** /**
* @property string pirep_id * @property string $pirep_id
* @property int user_id * @property int $user_id
* @property Pirep $pirep
* @property User $user
*/ */
class PirepComment extends Model class PirepComment extends Model
{ {

View File

@@ -56,7 +56,16 @@ class AcarsRepository extends Repository
*/ */
public function getPositions($live_time = 0) public function getPositions($live_time = 0)
{ {
$q = Pirep::with(['aircraft', 'airline', 'arr_airport', 'dpt_airport', 'position', 'user']) $with = [
'aircraft',
'airline',
'arr_airport',
'dpt_airport',
'position',
'user',
];
$q = Pirep::with($with)
->where(['state' => PirepState::IN_PROGRESS]); ->where(['state' => PirepState::IN_PROGRESS]);
if ($live_time !== null && $live_time > 0) { if ($live_time !== null && $live_time > 0) {

View File

@@ -3,6 +3,7 @@
use App\Models\Enums\PirepState; use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus; use App\Models\Enums\PirepStatus;
use App\Models\PirepFare; use App\Models\PirepFare;
use App\Models\PirepFieldValue;
use App\Repositories\SettingRepository; use App\Repositories\SettingRepository;
use App\Support\Utils; use App\Support\Utils;
@@ -247,7 +248,7 @@ class AcarsTest extends TestCase
]; ];
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(200);
$pirep = $response->json('data'); $pirep = $response->json('data');
// See that the fields and fares were set // See that the fields and fares were set
@@ -259,7 +260,7 @@ class AcarsTest extends TestCase
$this->assertEquals($fare->capacity, $saved_fare['count']); $this->assertEquals($fare->capacity, $saved_fare['count']);
// Check saved fields // Check saved fields
$saved_fields = \App\Models\PirepFieldValue::where('pirep_id', $pirep['id'])->get(); $saved_fields = PirepFieldValue::where('pirep_id', $pirep['id'])->get();
$this->assertCount(1, $saved_fields); $this->assertCount(1, $saved_fields);
$field = $saved_fields->first(); $field = $saved_fields->first();
@@ -334,7 +335,7 @@ class AcarsTest extends TestCase
]; ];
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(200);
$pirep = $response->json('data'); $pirep = $response->json('data');
/** /**
@@ -388,13 +389,13 @@ class AcarsTest extends TestCase
]; ];
$response = $this->post($uri, $pirep_create); $response = $this->post($uri, $pirep_create);
$response->assertStatus(201); $response->assertStatus(200);
// Get the PIREP ID // Get the PIREP ID
$body = $response->json(); $body = $response->json();
$pirep_id = $body['data']['id']; $pirep_id = $body['data']['id'];
$this->assertHasKeys($body['data'], ['airline', 'arr_airport', 'dpt_airport', 'position']); $this->assertHasKeys($body['data'], ['airline', 'arr_airport', 'dpt_airport']);
$this->assertNotNull($pirep_id); $this->assertNotNull($pirep_id);
$this->assertEquals($body['data']['user_id'], $this->user->id); $this->assertEquals($body['data']['user_id'], $this->user->id);
@@ -550,7 +551,7 @@ class AcarsTest extends TestCase
]; ];
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(200);
// Get the PIREP ID // Get the PIREP ID
$body = $response->json(); $body = $response->json();
@@ -616,7 +617,7 @@ class AcarsTest extends TestCase
// Try refiling with a valid aircraft // Try refiling with a valid aircraft
$pirep['aircraft_id'] = $subfleetA['aircraft']->random()->id; $pirep['aircraft_id'] = $subfleetA['aircraft']->random()->id;
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(200);
} }
/** /**
@@ -657,7 +658,7 @@ class AcarsTest extends TestCase
]; ];
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(200);
} }
/** /**
@@ -671,7 +672,7 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(200);
$pirep_id = $response->json()['data']['id']; $pirep_id = $response->json()['data']['id'];
@@ -869,7 +870,7 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/prefile'; $uri = '/api/pireps/prefile';
$response = $this->post($uri, $pirep); $response = $this->post($uri, $pirep);
$response->assertStatus(201); $response->assertStatus(200);
$pirep_id = $response->json()['data']['id']; $pirep_id = $response->json()['data']['id'];
// try readding // try readding