api-platform.com

How to add an extra information on api-platform result

邮差的信 提交于 2020-08-09 07:02:36
问题 I'am using symfony and api platform. I have a ressource with : /** * @ApiResource() */ class Credit { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="integer") */ private $value; } the result of /api/credits is : { "@context": "/api/contexts/Credit", "@id": "/api/credits", "@type": "hydra:Collection", "hydra:member": [ { "@id": "/api/credits/1", "@type": "Credit", "id": 1, "value": 200, "createdAt": "2019-03" }, { "@id": "/api

API Platform - Which approach should I use for creating custom operation without entity

痴心易碎 提交于 2020-05-10 18:52:18
问题 I'm new to API Platform. I think it's great but I cannot find any example how to create custom endpoint that isn't based on any entity. There are a lot of examples based on an entity and usually they are all about CRUD. But what about custom operations? I need to create custom search through database with some custom parameters which aren't related to any entity. E.g. I want to receive POST request something like this: { "from": "Paris", "to": "Berlin" } This data isn't saved to db and I

API Platform - Which approach should I use for creating custom operation without entity

陌路散爱 提交于 2020-05-10 18:51:27
问题 I'm new to API Platform. I think it's great but I cannot find any example how to create custom endpoint that isn't based on any entity. There are a lot of examples based on an entity and usually they are all about CRUD. But what about custom operations? I need to create custom search through database with some custom parameters which aren't related to any entity. E.g. I want to receive POST request something like this: { "from": "Paris", "to": "Berlin" } This data isn't saved to db and I

API Platform - Which approach should I use for creating custom operation without entity

蓝咒 提交于 2020-05-10 18:48:35
问题 I'm new to API Platform. I think it's great but I cannot find any example how to create custom endpoint that isn't based on any entity. There are a lot of examples based on an entity and usually they are all about CRUD. But what about custom operations? I need to create custom search through database with some custom parameters which aren't related to any entity. E.g. I want to receive POST request something like this: { "from": "Paris", "to": "Berlin" } This data isn't saved to db and I

Validation in custom operation controller

て烟熏妆下的殇ゞ 提交于 2020-04-30 06:49:06
问题 I'm trying to do a validation only on a custom operation on api platform but it doesn't work. I would like to change the password only if there is no error in the validation but in any case the password is changed. If I remove the validation groups from the validation annotations it works. for example if i replace @Assert\NotBlank(groups={"put-reset-password"}) with @Assert\NotBlank the validation pass. This is the code of the entity : "CHANGE-PASSWORD"={ "method"="PUT", "path"="/users/change

filter query on multiple fields in single query

无人久伴 提交于 2020-03-25 18:39:13
问题 My setup is Symfony 5 with the latest API-Platform version running on PHP 7.3. So I would like to be able to query both on name and username (maybe even email). Do I need to write a custom resolver? This is what I've tried so far but this results in a WHERE name = $name AND username = $name. query SearchUsers ($name: String!) { users(name: $name, username: $name) { edges { cursor node { id username email avatar } } } } My entity: /** * @ApiResource * @ApiFilter(SearchFilter::class, properties

filter query on multiple fields in single query

ε祈祈猫儿з 提交于 2020-03-25 18:38:17
问题 My setup is Symfony 5 with the latest API-Platform version running on PHP 7.3. So I would like to be able to query both on name and username (maybe even email). Do I need to write a custom resolver? This is what I've tried so far but this results in a WHERE name = $name AND username = $name. query SearchUsers ($name: String!) { users(name: $name, username: $name) { edges { cursor node { id username email avatar } } } } My entity: /** * @ApiResource * @ApiFilter(SearchFilter::class, properties

Why do I receive “This value should be of type string” when using a DateTime constraint on Symfony 5?

时光总嘲笑我的痴心妄想 提交于 2020-03-09 05:41:07
问题 I have the following entity (only attached the relevant parts): use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * @ApiResource(mercure=true) * @ORM\Entity(repositoryClass="App\Repository\EventRepository") */ class Event { /** * @ORM\Column(type="datetime") * @Assert\DateTime * @Assert\NotNull */ private $createdAt; public function __construct() { $this->createdAt = new \DateTime(); } public function

How to set normalization groups based on user's role and request method

删除回忆录丶 提交于 2020-03-04 20:01:10
问题 I am creating a sandbox app as Api-platform practice and I have the following problem to address: Let's consider following REST endpoint for user entity: DISCLAIMER in the code examples there are a little more attributes but the whole concept applies regarding that Collection-get(aka. /api/users) - only available for admin users(all attributes available, maybe we exclude hashed password) POST - everyone should have access to following attributes: username, email, plainPassword(not persisted