Rename UserFlight to UserBid to match functionality
This commit is contained in:
parent
cc873f1a29
commit
de582f617c
@ -5,7 +5,6 @@ namespace App\Http\Controllers\Api;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
use App\Models\Transformers\FlightTransformer;
|
||||
use App\Repositories\FlightRepository;
|
||||
use App\Http\Resources\Flight as FlightResource;
|
||||
use Prettus\Repository\Exceptions\RepositoryException;
|
||||
@ -33,7 +32,7 @@ class FlightController extends AppBaseController
|
||||
} catch (RepositoryException $e) {
|
||||
return response($e, 503);
|
||||
}
|
||||
|
||||
return FlightResource::collection($flights);
|
||||
//return fractal($flights, new FlightTransformer())->respond();
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,23 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use App\Models\Transformers\PirepTransformer;
|
||||
use App\Http\Resources\Pirep as PirepResource;
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
use App\Repositories\PirepRepository;
|
||||
|
||||
|
||||
class PirepController extends AppBaseController
|
||||
{
|
||||
protected $pirepRepo;
|
||||
|
||||
public function __construct(PirepRepository $pirepRepo)
|
||||
{
|
||||
$this->pirepRepo = $pirepRepo;
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
$pirep = Pirep::find($id);
|
||||
return fractal($pirep, new PirepTransformer())->respond();
|
||||
PirepResource::withoutWrapping();
|
||||
return new PirepResource($this->pirepRepo->find($id));
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
use App\Models\UserFlight;
|
||||
use App\Models\UserBid;
|
||||
use App\Repositories\FlightRepository;
|
||||
use App\Repositories\Criteria\WhereCriteria;
|
||||
|
||||
@ -48,7 +48,7 @@ class FlightController extends AppBaseController
|
||||
|
||||
$flights = $this->flightRepo->paginate();
|
||||
|
||||
$saved_flights = UserFlight::where('user_id', Auth::id())
|
||||
$saved_flights = UserBid::where('user_id', Auth::id())
|
||||
->pluck('flight_id')->toArray();
|
||||
|
||||
return $this->view('flights.index', [
|
||||
@ -69,7 +69,7 @@ class FlightController extends AppBaseController
|
||||
{
|
||||
$flights = $this->flightRepo->searchCriteria($request)->paginate();
|
||||
|
||||
$saved_flights = UserFlight::where('user_id', Auth::id())
|
||||
$saved_flights = UserBid::where('user_id', Auth::id())
|
||||
->pluck('flight_id')->toArray();
|
||||
|
||||
return $this->view('flights.index', [
|
||||
@ -89,7 +89,7 @@ class FlightController extends AppBaseController
|
||||
$cols = ['user_id' => $user_id, 'flight_id' => $flight_id];
|
||||
|
||||
if($action === 'save') {
|
||||
$uf = UserFlight::create($cols);
|
||||
$uf = UserBid::create($cols);
|
||||
$uf->save();
|
||||
|
||||
return response()->json([
|
||||
@ -100,7 +100,7 @@ class FlightController extends AppBaseController
|
||||
|
||||
elseif ($action === 'remove') {
|
||||
try {
|
||||
$uf = UserFlight::where($cols)->first();
|
||||
$uf = UserBid::where($cols)->first();
|
||||
$uf->delete();
|
||||
} catch (Exception $e) { }
|
||||
|
||||
|
19
app/Http/Resources/Pirep.php
Normal file
19
app/Http/Resources/Pirep.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Pirep extends Resource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Transformers;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class PirepTransformer extends TransformerAbstract
|
||||
{
|
||||
public static $aptXform = null;
|
||||
public static $flightXform = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
PirepTransformer::$aptXform = new AirportTransform();
|
||||
PirepTransformer::$flightXform = new FlightTransformer();
|
||||
}
|
||||
|
||||
public function transform(Pirep $pirep)
|
||||
{
|
||||
$p = [
|
||||
'id' => $pirep->id,
|
||||
'route_code' => $pirep->route_code,
|
||||
'route_leg' => $pirep->route_leg,
|
||||
'level' => $pirep->level,
|
||||
'route' => $pirep->route,
|
||||
'source' => $pirep->source,
|
||||
'status' => $pirep->status,
|
||||
'raw_data' => $pirep->raw_data,
|
||||
'flight_time' => $pirep->flight_time,
|
||||
'aircraft' => [],
|
||||
'dpt' => PirepTransformer::$aptXform->transform($pirep->dpt_airport),
|
||||
'arr' => PirepTransformer::$aptXform->transform($pirep->arr_airport),
|
||||
'user' => [
|
||||
'id' => $pirep->user->id,
|
||||
'pilot_id' => $pirep->user->pilot_id(),
|
||||
],
|
||||
];
|
||||
|
||||
if ($pirep->flight_id) {
|
||||
$p['flight'] = PirepTransformer::$flightXform->transform($pirep->flight);
|
||||
}
|
||||
|
||||
return $p;
|
||||
}
|
||||
}
|
@ -140,7 +140,7 @@ class User extends Authenticatable
|
||||
|
||||
public function flights()
|
||||
{
|
||||
return $this->hasMany('App\Models\UserFlight', 'user_id');
|
||||
return $this->hasMany('App\Models\UserBid', 'user_id');
|
||||
}
|
||||
|
||||
public function pireps()
|
||||
|
@ -7,13 +7,11 @@ use Eloquent as Model;
|
||||
/**
|
||||
* @package App\Models
|
||||
*/
|
||||
class UserFlight extends Model
|
||||
class UserBid extends Model
|
||||
{
|
||||
public $table = 'user_flights';
|
||||
public $timestamps = false;
|
||||
public $table = 'user_bids';
|
||||
|
||||
public $fillable
|
||||
= [
|
||||
public $fillable = [
|
||||
'user_id',
|
||||
'flight_id',
|
||||
];
|
@ -107,10 +107,10 @@ class CreateUsersTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('users');
|
||||
Schema::drop('permission_role');
|
||||
Schema::drop('permissions');
|
||||
Schema::drop('role_user');
|
||||
Schema::drop('roles');
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('permission_role');
|
||||
Schema::dropIfExists('permissions');
|
||||
Schema::dropIfExists('role_user');
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,6 @@ class CreatePasswordResetsTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('password_resets');
|
||||
Schema::dropIfExists('password_resets');
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,6 @@ class CreateAirlinesTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('airlines');
|
||||
Schema::dropIfExists('airlines');
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ class CreateAircraftsTable extends Migration
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('aircraft');
|
||||
Schema::dropIfExists('aircraft');
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,6 @@ class CreateFaresTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('fares');
|
||||
Schema::dropIfExists('fares');
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,9 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateAirportsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('airports', function (Blueprint $table) {
|
||||
// $table->bigIncrements('id');
|
||||
$table->string('id', 5)->primary();
|
||||
$table->string('iata', 5)->nullable();
|
||||
$table->string('icao', 5);
|
||||
@ -30,13 +23,8 @@ class CreateAirportsTable extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('airports');
|
||||
Schema::dropIfExists('airports');
|
||||
}
|
||||
}
|
||||
|
@ -47,14 +47,6 @@ class CreateFlightsTable extends Migration
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('user_flights', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('user_id', false, true);
|
||||
$table->uuid('flight_id');
|
||||
|
||||
$table->index('user_id');
|
||||
$table->index(['user_id', 'flight_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,6 +58,5 @@ class CreateFlightsTable extends Migration
|
||||
{
|
||||
Schema::drop('flights');
|
||||
Schema::drop('flight_fields');
|
||||
Schema::drop('user_flights');
|
||||
}
|
||||
}
|
@ -33,6 +33,6 @@ class CreateRanksTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('ranks');
|
||||
Schema::dropIfExists('ranks');
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +71,10 @@ class CreateSubfleetsTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('subfleets');
|
||||
Schema::drop('subfleet_expenses');
|
||||
Schema::drop('subfleet_fare');
|
||||
Schema::drop('subfleet_flight');
|
||||
Schema::drop('subfleet_rank');
|
||||
Schema::dropIfExists('subfleets');
|
||||
Schema::dropIfExists('subfleet_expenses');
|
||||
Schema::dropIfExists('subfleet_fare');
|
||||
Schema::dropIfExists('subfleet_flight');
|
||||
Schema::dropIfExists('subfleet_rank');
|
||||
}
|
||||
}
|
@ -107,11 +107,11 @@ class CreatePirepsTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('pireps');
|
||||
Schema::drop('pirep_comments');
|
||||
Schema::drop('pirep_expenses');
|
||||
Schema::drop('pirep_fares');
|
||||
Schema::drop('pirep_fields');
|
||||
Schema::drop('pirep_field_values');
|
||||
Schema::dropIfExists('pireps');
|
||||
Schema::dropIfExists('pirep_comments');
|
||||
Schema::dropIfExists('pirep_expenses');
|
||||
Schema::dropIfExists('pirep_fares');
|
||||
Schema::dropIfExists('pirep_fields');
|
||||
Schema::dropIfExists('pirep_field_values');
|
||||
}
|
||||
}
|
@ -79,6 +79,6 @@ class CreateSettingsTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('settings');
|
||||
Schema::dropIfExists('settings');
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ flight_fields:
|
||||
name: cost index
|
||||
value: 100
|
||||
|
||||
user_flights:
|
||||
user_bids:
|
||||
- id: 100
|
||||
user_id: 1
|
||||
flight_id: flightid_1
|
||||
|
Loading…
Reference in New Issue
Block a user