privilegeService = $privilegeService; $this->postService = $postService; $this->inputReader = $inputReader; $this->postViewProxy = $postViewProxy; } public function getMethods() { return ['POST']; } public function getUrl() { return '/api/posts/:postNameOrId'; } public function work($args) { $postNameOrId = $args['postNameOrId']; $post = $this->postService->getByNameOrId($postNameOrId); $formData = new PostEditFormData($this->inputReader); if ($formData->content !== null) $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_CONTENT); if ($formData->thumbnail !== null) $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_THUMBNAIL); if ($formData->safety !== null) $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SAFETY); if ($formData->source !== null) $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SOURCE); if ($formData->tags !== null) $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_TAGS); $this->postService->updatePost($post, $formData); $post = $this->postService->getByNameOrId($postNameOrId); return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); } }