api-platform.com - Api Platform using Output with custom Persister
问题描述
I create an ApiResource model class MyCustomModel (not Doctrine Entity) that has a declaration of output.
/**
* @ApiResource(
* itemOperations={},
* collectionOperations={"post"={}},
* output=SomeOutput::class
* )
*/
Because I want to have custom operation made on it (part of data saved to DB via doctrine entity and part sent on queue) I created and registered MyCustomPersister to handle this. Inside this persister I do operations and in the end I return the created doctrine entity SomeEntity (because I want to have access to this entity when building the output - I want to return its id and status) and NOT the $data that was originally passed to persister.
I created SomeOutput class and created SomeOutputDataTransformer classes assuming they will be used to build output for the request and that the SomeEntity I returned form MyCustomPersister will be passed there but they are not used, the Transformer is not used at all. The SomeOutput structure is visible in SwaggerUI as a Response for this request but as result of the request the whole SomeEntity I return in MyCustomPersister is returned.
What am I missing? Where I went wrong? Is there a better concept of doing this?
What I want to achieve is have a non entity ApiResource for which part of it will be saved as entity to DB and part of it sent to queue and in the end I want to return to user 3 out of 5 fields from this newly created entity.
解决方案
推荐阅读
- python - QTextEdit 的 Qt.AlignTop/VCenter/Bottom 属性根本不起作用。我需要做什么?
- string - Impala 将字符串转换为格式为“Fri Mar 02 00:00:00 GMT 2018”的时间戳
- smtp - PHPMailer SMTP 并将邮件副本添加到已发送文件夹
- hl7-fhir - FHIR - 患者(显示)与多个患者(索引/搜索)
- flutter - 在颤动的另一个文本中添加文本值
- python-3.x - 正则表达式提取“:”之后的单词
- wpf - 需要帮助来查找 WPF TreeView 分层模板样式人工制品
- database - 在 wordPress 中自动动态创建页面
- java - Java Money 奇数除法和四舍五入不损失/获得美分
- server - Indy IdTCPServer 问题