Add calls and API to get user's fleet, determined by rank #35
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Services\UserService;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -9,17 +10,21 @@ use App\Repositories\UserRepository;
|
||||
|
||||
use App\Models\UserBid;
|
||||
|
||||
use App\Http\Resources\Subfleet as SubfleetResource;
|
||||
use App\Http\Resources\Flight as FlightResource;
|
||||
use App\Http\Resources\User as UserResource;
|
||||
|
||||
|
||||
class UserController extends RestController
|
||||
{
|
||||
protected $userRepo;
|
||||
protected $userRepo, $userSvc;
|
||||
|
||||
public function __construct(UserRepository $userRepo)
|
||||
{
|
||||
public function __construct(
|
||||
UserRepository $userRepo,
|
||||
UserService $userSvc
|
||||
) {
|
||||
$this->userRepo = $userRepo;
|
||||
$this->userSvc = $userSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,6 +47,8 @@ class UserController extends RestController
|
||||
|
||||
/**
|
||||
* Return all of the bids for the passed-in user
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
||||
*/
|
||||
public function bids($id)
|
||||
{
|
||||
@@ -51,4 +58,23 @@ class UserController extends RestController
|
||||
return FlightResource::collection($flights);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,9 @@ Route::group(['middleware' => ['api.auth']], function ()
|
||||
|
||||
# This is the info of the user whose token is in use
|
||||
Route::get('user', 'UserController@index');
|
||||
Route::get('user/fleet', 'UserController@fleet');
|
||||
|
||||
Route::get('users/{id}', 'UserController@get');
|
||||
Route::get('users/{id}/bids', 'UserController@bids');
|
||||
Route::get('users/{id}/fleet', 'UserController@fleet');
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use App\Facades\Utils;
|
||||
use App\Models\User;
|
||||
@@ -53,6 +54,18 @@ class UserService extends BaseService
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the subfleets this user is allowed access to,
|
||||
* based on their current rank
|
||||
* @param $user
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllowableSubfleets($user)
|
||||
{
|
||||
$subfleets = $user->rank->subfleets();
|
||||
return $subfleets->with('aircraft')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the user's state. PENDING to ACCEPTED, etc
|
||||
* Send out an email
|
||||
|
||||
Reference in New Issue
Block a user