1
私は、コントローラのメソッドの束を持っており、今では次のようになります。この場合のDTOの使い方は?
class ItemController
{
public function getItems(Request $request)
{
return $this->itemService->getItems($this->getUser(), $request->get('category_id'));
}
public function getItem(int $id, Request $request)
{
return $this->itemService->getItem($this->getUser(), $id, $request->get('category_id'));
}
public function patchItem(ItemDTO $item, Request $request)
{
return $this->itemService->patchItem($this->getUser(), $item, $request->get('category_id'));
}
}
私は、リモート・インタフェースに多くのパラメータを転送し、私のItemDTOにcategoryId
、id
とuser
を追加避けたいです。私のItemDTOに多くのフィールドがある場合は良いアプローチですか、私は2つだけを使用しますか?このように:
public function getItem(int $id, Request $request)
{
$itemDTO = new ItemDTO($this->getUser(), $id, $request->get('category_id')); //here $title and others is empty
return $this->itemService->getItem($itemDTO);
}
そして、このように私のDTO:各メソッドの
class ItemDTO
{
final public $user;
final public $id;
final public $categoryId;
final public $title;
//...
public function __construct($user = null, $id = null, $categoryId = null, $title = null, ...)
{
//assign variables
}
}
たぶん私は必要なの別々のDTO?また、DTOには$pageNumber
,$pageSize
などのフィールドが含まれていますか?良いアプローチですか?