Fix bug with showing only last selected stop.

This commit is contained in:
Kacper Donat 2020-01-12 19:55:24 +01:00
parent 11356a84a2
commit 4fa901dc1b
2 changed files with 10 additions and 3 deletions

View File

@ -11,6 +11,8 @@ use Nelmio\ApiDocBundle\Annotation\Model;
use Swagger\Annotations as SWG; use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use function Kadet\Functional\ref;
use function Kadet\Functional\Transforms\property;
/** /**
* Class DeparturesController * Class DeparturesController
@ -63,8 +65,8 @@ class DeparturesController extends Controller
{ {
$stops = $stops $stops = $stops
->getManyById($request->query->get('stop')) ->getManyById($request->query->get('stop'))
->flatMap([ $departures, 'getForStop' ]) ->flatMap(ref([ $departures, 'getForStop' ]))
; ->sortBy(property('departure'));
return $this->json($stops->values()->slice(0, (int)$request->query->get('limit', 8))); return $this->json($stops->values()->slice(0, (int)$request->query->get('limit', 8)));
} }

View File

@ -108,6 +108,11 @@ class Departure implements Fillable
$this->scheduled = $scheduled; $this->scheduled = $scheduled;
} }
public function getDeparture(): Carbon
{
return $this->estimated ?? $this->scheduled;
}
public function getStop(): Stop public function getStop(): Stop
{ {
return $this->stop; return $this->stop;