diff --git a/app/Http/Resources/User.php b/app/Http/Resources/User.php index 757e7937..2df6fee8 100644 --- a/app/Http/Resources/User.php +++ b/app/Http/Resources/User.php @@ -3,32 +3,36 @@ namespace App\Http\Resources; use App\Contracts\Resource; +use App\Http\Resources\Flight as FlightResource; +/** + * @mixin \App\Models\User + */ class User extends Resource { public function toArray($request) { - return [ + $res = [ 'id' => $this->id, 'pilot_id' => $this->pilot_id, + 'avatar' => $this->avatar, 'ident' => $this->ident, 'name' => $this->name, 'email' => $this->email, - 'apikey' => $this->apikey, 'rank_id' => $this->rank_id, 'home_airport' => $this->home_airport_id, 'curr_airport' => $this->curr_airport_id, 'last_pirep_id' => $this->last_pirep_id, - 'flights' => $this->flight, 'flight_time' => $this->flight_time, - 'balance' => $this->balance, 'timezone' => $this->timezone, - 'status' => $this->status, 'state' => $this->state, - - 'airline' => Airline::make($this->airline), - 'bids' => UserBid::collection($this->bids), - 'rank' => Rank::make($this->rank), + 'rank' => Rank::make($this->rank), ]; + + $res['airline'] = Airline::make($this->airline); + $res['bids'] = UserBid::collection($this->whenLoaded('bids')); + $res['flights'] = new FlightResource($this->whenLoaded('flights')); + + return $res; } } diff --git a/app/Models/User.php b/app/Models/User.php index fe10797a..364bae4e 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -21,6 +21,7 @@ use Laratrust\Traits\LaratrustUserTrait; * @property string ident * @property string curr_airport_id * @property string home_airport_id + * @property string avatar * @property Airline airline * @property Flight[] flights * @property int flight_time @@ -142,7 +143,7 @@ class User extends Authenticatable public function getAvatarAttribute() { if (!$this->attributes['avatar']) { - return; + return $this->gravatar(); } return new File([ diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 5b0064cb..de57fdb6 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -263,4 +263,12 @@ class ApiTest extends TestCase $res = $this->get('/api/settings')->assertStatus(200); $settings = $res->json(); } + + public function testGetUser() + { + $this->user = factory(App\Models\User::class)->create(); + $res = $this->get('/api/user')->assertStatus(200); + $user = $res->json('data'); + $this->assertNotNull($user); + } }