Skip to content

Commit

Permalink
fix baserproject#2403 アップロードファイルのAPIについてフルパスを取得する仕組み
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Sep 26, 2023
1 parent 4edf8cd commit 8937ceb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions plugins/bc-blog/src/Controller/Api/BlogPostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

use BaserCore\Controller\Api\BcApiController;
use BcBlog\Service\BlogPostsServiceInterface;
use BcBlog\View\Helper\BlogHelper;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\ForbiddenException;
use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use Cake\View\View;

/**
* BlogPostsController
Expand Down Expand Up @@ -83,6 +85,8 @@ public function view(BlogPostsServiceInterface $service, $id)
$blogPost = $message = null;
try {
$blogPost = $service->get($id, $queryParams);
$BlogHelper = new BlogHelper(new View());
$blogPost->eye_catch = $BlogHelper->getEyeCatch($blogPost, ['output' => 'url']);
} catch (RecordNotFoundException $e) {
$this->setResponse($this->response->withStatus(404));
$message = __d('baser_core', 'データが見つかりません。');
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-blog/src/View/Helper/BlogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function __construct(View $view, array $config = [])
public function setContent($blogContentId = null)
{
$blogContentUpdated = false;
$content = false;
if (empty($this->currentBlogContent) || ($blogContentId != $this->currentBlogContent->id)) {
if ($blogContentId) {
if ($this->_View->getRequest()->getQuery('preview') == 'default' && $this->_View->getRequest()->getData()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BcBlog\Test\TestCase\Controller\Api;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\PermissionFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
Expand Down Expand Up @@ -91,7 +92,8 @@ public function test_view()
{
// データを生成
$this->loadFixtureScenario(BlogContentScenario::class, 1, 1, null, 'test', '/test');
BlogPostFactory::make(['id' => '1', 'blog_content_id' => '1', 'title' => 'blog post', 'status' => true])->persist();
BlogPostFactory::make(['id' => '1', 'blog_content_id' => '1', 'title' => 'blog post', 'eye_catch' => 'eye_catch.img', 'status' => true])->persist();
ContentFactory::make(['type' => 'BlogContent', 'entity_id' => 1])->persist();
PermissionFactory::make()->allowGuest('/baser/api/*')->persist();

// APIを呼ぶ
Expand All @@ -101,6 +103,7 @@ public function test_view()
// 戻り値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals(1, $result->blogPost->id);
$this->assertTextContains('/files/blog/1/blog_posts/eye_catch.img', $result->blogPost->eye_catch);
$this->assertEquals(1, $result->blogPost->blog_content_id);

//存在しないBlogPostIDをテスト場合、
Expand Down

0 comments on commit 8937ceb

Please sign in to comment.