2017-12-13 06:58:27 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2018-01-20 01:46:30 +08:00
|
|
|
use App\Repositories\SubfleetRepository;
|
2018-01-11 08:40:01 +08:00
|
|
|
use App\Services\UserService;
|
2018-01-03 04:37:52 +08:00
|
|
|
use Auth;
|
2017-12-13 06:58:27 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
use App\Repositories\UserRepository;
|
|
|
|
|
|
|
|
use App\Models\UserBid;
|
|
|
|
|
2018-01-11 08:40:01 +08:00
|
|
|
use App\Http\Resources\Subfleet as SubfleetResource;
|
2017-12-13 06:58:27 +08:00
|
|
|
use App\Http\Resources\Flight as FlightResource;
|
|
|
|
use App\Http\Resources\User as UserResource;
|
|
|
|
|
|
|
|
|
2018-01-06 00:45:34 +08:00
|
|
|
class UserController extends RestController
|
2017-12-13 06:58:27 +08:00
|
|
|
{
|
2018-01-20 01:46:30 +08:00
|
|
|
protected $subfleetRepo,
|
|
|
|
$userRepo,
|
|
|
|
$userSvc;
|
2017-12-13 06:58:27 +08:00
|
|
|
|
2018-01-11 08:40:01 +08:00
|
|
|
public function __construct(
|
2018-01-20 01:46:30 +08:00
|
|
|
SubfleetRepository $subfleetRepo,
|
2018-01-11 08:40:01 +08:00
|
|
|
UserRepository $userRepo,
|
|
|
|
UserService $userSvc
|
|
|
|
) {
|
2018-01-20 01:46:30 +08:00
|
|
|
$this->subfleetRepo = $subfleetRepo;
|
2017-12-13 06:58:27 +08:00
|
|
|
$this->userRepo = $userRepo;
|
2018-01-11 08:40:01 +08:00
|
|
|
$this->userSvc = $userSvc;
|
2017-12-13 06:58:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the profile for the currently auth'd user
|
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2018-01-03 04:37:52 +08:00
|
|
|
return new UserResource(Auth::user());
|
2017-12-13 06:58:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the profile for the passed-in user
|
|
|
|
*/
|
|
|
|
public function get($id)
|
|
|
|
{
|
|
|
|
return new UserResource($this->userRepo->find($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all of the bids for the passed-in user
|
2018-01-11 08:40:01 +08:00
|
|
|
* @param $id
|
|
|
|
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
2017-12-13 06:58:27 +08:00
|
|
|
*/
|
|
|
|
public function bids($id)
|
|
|
|
{
|
|
|
|
$flights = UserBid::where(['user_id' => $id])->get()
|
|
|
|
->pluck('flight');
|
|
|
|
|
|
|
|
return FlightResource::collection($flights);
|
|
|
|
}
|
|
|
|
|
2018-01-11 08:40:01 +08:00
|
|
|
/**
|
|
|
|
* Return the fleet that this user is allowed to
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
|
|
|
*/
|
|
|
|
public function fleet(Request $request)
|
|
|
|
{
|
|
|
|
if($request->id === null) {
|
|
|
|
$id = Auth::user()->id;
|
|
|
|
} else {
|
|
|
|
$id = $request->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = $this->userRepo->find($id);
|
|
|
|
$subfleets = $this->userSvc->getAllowableSubfleets($user);
|
|
|
|
|
|
|
|
return SubfleetResource::collection($subfleets);
|
|
|
|
}
|
|
|
|
|
2017-12-13 06:58:27 +08:00
|
|
|
}
|