Skip to content

Commit

Permalink
fix baserproject#1980 API 関連フィールド 単一データ取得 (baserproject#1986)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <HungDV2022>
  • Loading branch information
HungDV2022 committed Mar 12, 2023
1 parent 942635f commit d6c4997
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use BcCustomContent\Service\CustomLinksServiceInterface;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\ORM\Exception\PersistenceFailedException;

/**
Expand All @@ -38,10 +39,28 @@ public function index(CustomLinksServiceInterface $service)
* 単一データAPI
*
* @param CustomLinksServiceInterface $service
* @param int $id
*
* @checked
* @noTodo
* @unitTest
*/
public function view(CustomLinksServiceInterface $service)
public function view(CustomLinksServiceInterface $service, int $id)
{
//todo 単一データAPI
$this->request->allowMethod('get');
$customLink = $message = null;
try {
$customLink = $service->get($id);
} catch (RecordNotFoundException $e) {
$this->setResponse($this->response->withStatus(404));
$message = __d('baser_core', 'データが見つかりません');
}

$this->set([
'customLink' => $customLink,
'message' => $message
]);
$this->viewBuilder()->setOption('serialize', ['message', 'customLink']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BcCustomContent\Test\Scenario\CustomFieldsScenario;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
use Cake\TestSuite\IntegrationTestTrait;

Expand Down Expand Up @@ -90,7 +91,16 @@ public function test_index()
*/
public function test_view()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//データを生成
$this->loadFixtureScenario(CustomFieldsScenario::class);
//APIを呼ぶ
$this->get('/baser/api/bc-custom-content/custom_links/view/1.json?token=' . $this->accessToken);
//ステータスを確認
$this->assertResponseOk();
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertNotNull($result->customLink);
$this->assertEquals('求人分類', $result->customLink->custom_field->title);
}

/**
Expand Down

0 comments on commit d6c4997

Please sign in to comment.