Flight history #807

This commit is contained in:
Nabeel Shahzad
2020-09-08 09:29:46 -04:00
parent 5dcbd01c00
commit e2bcd72e39
4 changed files with 67 additions and 4 deletions

View File

@@ -6,7 +6,8 @@ use Illuminate\Validation\Validator;
use Prettus\Repository\Eloquent\BaseRepository;
/**
* @mixin \Prettus\Repository\Eloquent\BaseRepository
* @mixin Model
* @mixin BaseRepository
*/
abstract class Repository extends BaseRepository
{

View File

@@ -7,9 +7,6 @@ use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Models\User;
/**
* Class PirepRepository
*/
class PirepRepository extends Repository
{
protected $fieldSearchable = [

View File

@@ -4,11 +4,13 @@ namespace App\Services;
use App\Contracts\Service;
use App\Models\Aircraft;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Repositories\PirepRepository;
class AircraftService extends Service
{
/** @var PirepRepository */
private $pirepRepo;
public function __construct(PirepRepository $pirepRepo)
@@ -16,6 +18,26 @@ class AircraftService extends Service
$this->pirepRepo = $pirepRepo;
}
/**
* Get a list of the PIREPs that have been flown by this aircraft
*
* @param Aircraft $aircraft
* @param int $count
*
* @return Pirep[] Collection of PIREPs
*/
public function getFlightHistory(Aircraft $aircraft, $count = 5)
{
return $this->pirepRepo
->orderBy('created_at', 'desc')
->limit($count)
->where([
'aircraft_id' => $aircraft->id,
'state' => PirepState::ACCEPTED,
])
->get();
}
/**
* Recalculate all aircraft stats and hours
*/