api平台过滤器DTO

时间:2018-06-28 10:57:44

标签: symfony symfony4 api-platform.com

我有一个嵌入Event的{​​{1}}实体,我想根据距离排序的纬度,经度和半径来获取过滤的事件+距离。

我首先创建了一个GeoCordinates,并且它与get操作一起工作,但是由于我还希望获得距离,所以我认为最好创建一个DTO DistanceFilter

EventDistance

我基本上遵循https://api-platform.com/docs/core/dto/

所以我有

class EventDistance
{
    /**
     * @var Event
     * @ApiProperty(iri="http://schema.org/Event",
     *     attributes={
     *         "swagger_context"={"type"="object"}
     *     })
     */
    private $event;

    /**
     * @var float
     * @Assert\Type(type="float")
     */
    private $distance;
}

现在我不确定如何继续...

我当然可以从class EventDistanceSubscriber implements EventSubscriberInterface { /** * @var EventRepository */ private $eventRepository; /** * EventDistanceSubscriber constructor. * @param EventRepository $eventRepository */ public function __construct(EventRepository $eventRepository) { $this->eventRepository = $eventRepository; } /** * @return EventRepository */ public function getEventRepository(): EventRepository { return $this->eventRepository; } public static function getSubscribedEvents() { return [ KernelEvents::VIEW => [ 'getEvents', EventPriorities::POST_VALIDATE] ]; } public function getEvents(GetResponseForControllerResultEvent $event) { $request = $event->getRequest(); if ('api_event_distances_get_collection' !== $request->attributes->get('_route')) { return; } $dist = 1; $latitude = 12; $longitude = 35; $events = $this->getEventRepository()->findEventsOrderedByDistance( $longitude, $latitude, $dist); $event->setControllerResult($events); } } 获取参数,但是我想知道是否有一种api平台方式...也许以某种方式使用$request

我还想改进swagger文档,因为使用DistanceFilter我只有

"swagger_context"={"type"="object"}

0 个答案:

没有答案