@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Log;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
@@ -25,6 +26,10 @@ class FlightController extends AppBaseController
|
||||
return new FlightResource($flight);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
55
app/Http/Controllers/Api/UserController.php
Normal file
55
app/Http/Controllers/Api/UserController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
use App\Repositories\UserRepository;
|
||||
|
||||
use App\Models\UserBid;
|
||||
|
||||
use App\Http\Resources\Flight as FlightResource;
|
||||
use App\Http\Resources\User as UserResource;
|
||||
use App\Http\Resources\UserBid as UserBidResource;
|
||||
|
||||
|
||||
class UserController extends AppBaseController
|
||||
{
|
||||
protected $userRepo;
|
||||
|
||||
public function __construct(UserRepository $userRepo)
|
||||
{
|
||||
$this->userRepo = $userRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the profile for the currently auth'd user
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
UserResource::withoutWrapping();
|
||||
return new UserResource($request->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the profile for the passed-in user
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
UserResource::withoutWrapping();
|
||||
return new UserResource($this->userRepo->find($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the bids for the passed-in user
|
||||
*/
|
||||
public function bids($id)
|
||||
{
|
||||
$flights = UserBid::where(['user_id' => $id])->get()
|
||||
->pluck('flight');
|
||||
|
||||
return FlightResource::collection($flights);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Auth;
|
||||
use Cache;
|
||||
use Closure;
|
||||
use App\Models\User;
|
||||
|
||||
@@ -28,16 +27,8 @@ class ApiAuth
|
||||
|
||||
// Try to find the user via API key. Cache this lookup
|
||||
$api_key = $request->header('Authorization');
|
||||
$user = User::where('apikey', $api_key)->first();
|
||||
/*$user = Cache::remember(
|
||||
config('cache.keys.USER_API_KEY.key') . $api_key,
|
||||
config('cache.keys.USER_API_KEY.time'),
|
||||
function () use ($api_key) {
|
||||
return User::where('apikey', $api_key)->first();
|
||||
}
|
||||
);*/
|
||||
|
||||
if(!$user) {
|
||||
$user = User::where('api_key', $api_key)->first();
|
||||
if($user === null) {
|
||||
return $this->unauthorized();
|
||||
}
|
||||
|
||||
|
||||
13
app/Http/Resources/Aircraft.php
Normal file
13
app/Http/Resources/Aircraft.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Aircraft extends Resource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
23
app/Http/Resources/Airline.php
Normal file
23
app/Http/Resources/Airline.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Airline extends Resource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'icao' => $this->icao,
|
||||
'iata' => $this->iata,
|
||||
'name' => $this->name,
|
||||
'country' => $this->country,
|
||||
'logo' => $this->logo,
|
||||
#'active' => $this->active,
|
||||
#'created_at' => $this->created_at,
|
||||
#'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,6 @@ use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Airport extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
|
||||
@@ -6,12 +6,6 @@ use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Flight extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
@@ -29,8 +23,10 @@ class Flight extends Resource
|
||||
'flight_time' => $this->flight_time,
|
||||
'notes' => $this->notes,
|
||||
'active' => $this->active,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
|
||||
'subfleet' => Subfleet::collection($this->subfleets),
|
||||
#'created_at' => $this->created_at,
|
||||
#'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Http/Resources/Rank.php
Normal file
26
app/Http/Resources/Rank.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Rank extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'name' => $this->name,
|
||||
#'auto_approve_acars' => $this->auto_approve_acars,
|
||||
#'auto_approve_manual' => $this->auto_approve_manual,
|
||||
#'auto_promote' => $this->auto_promote,
|
||||
#'created_at' => $this->created_at,
|
||||
#'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
24
app/Http/Resources/Subfleet.php
Normal file
24
app/Http/Resources/Subfleet.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Subfleet extends Resource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'airline_id' => $this->airline_id,
|
||||
'name' => $this->name,
|
||||
'type' => $this->type,
|
||||
'fuel_type' => $this->fuel_type,
|
||||
'cargo_capacity' => $this->cargo_capacity,
|
||||
'fuel_capacity' => $this->fuel_capacity,
|
||||
'gross_weight' => $this->gross_weight,
|
||||
|
||||
'aircraft' => Aircraft::collection($this->aircraft),
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Resources/User.php
Normal file
31
app/Http/Resources/User.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class User extends Resource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'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,
|
||||
'active' => $this->active,
|
||||
|
||||
'airline' => Airline::make($this->airline),
|
||||
'bids' => UserBid::collection($this->bids),
|
||||
'rank' => Rank::make($this->rank),
|
||||
];
|
||||
}
|
||||
}
|
||||
20
app/Http/Resources/UserBid.php
Normal file
20
app/Http/Resources/UserBid.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class UserBid extends Resource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'flight_id' => $this->flight_id,
|
||||
'flight' => Flight::collection($this->whenLoaded('flight'))
|
||||
#'created_at' => $this->created_at,
|
||||
#'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user