Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

Adapt attributes #104

Merged
merged 8 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
YII_ENV: test

php:
version: 8.0.11
version: 8.1.8
ini:
xdebug.mode: coverage

Expand All @@ -33,7 +33,7 @@ build:
override:
- command: |
./yii serve 127.0.0.1:8080 > ./runtime/yii.log 2>&1 &
vendor/bin/codecept run acceptance --coverage-xml --env github-ci
vendor/bin/codecept run --coverage-xml --env github-ci
on_node: 1
coverage:
file: runtime/tests/_output/coverage.xml
Expand Down
23 changes: 17 additions & 6 deletions src/Blog/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
use Psr\Http\Message\ResponseInterface as Response;
use Yiisoft\DataResponse\DataResponseFactoryInterface;
use OpenApi\Annotations as OA;
use Yiisoft\RequestModel\Attribute\Query;
use Yiisoft\RequestModel\Attribute\Route;

/**
* @OA\Tag(
* name="blog",
* description="Blog"
* )
* @OA\Parameter(
* @OA\Schema(
* type="int",
* example="2"
* ),
* in="query",
* name="page",
* parameter="PageRequest"
* )
*/
final class BlogController
{
Expand Down Expand Up @@ -72,9 +83,9 @@ public function __construct(
* ),
* )
*/
public function index(PageRequest $request, PaginatorFormatter $paginatorFormatter): Response
public function index(PaginatorFormatter $paginatorFormatter, #[Query('page')] int $page = 1): Response
{
$paginator = $this->blogService->getPosts($request->getPage());
$paginator = $this->blogService->getPosts($page);
$posts = [];
foreach ($paginator->read() as $post) {
$posts[] = $this->postFormatter->format($post);
Expand Down Expand Up @@ -135,12 +146,12 @@ public function index(PageRequest $request, PaginatorFormatter $paginatorFormatt
* ),
* )
*/
public function view(ViewPostRequest $request): Response
public function view(#[Route('id')] int $id): Response
{
return $this->responseFactory->createResponse(
[
'post' => $this->postFormatter->format(
$this->blogService->getPost($request->getId())
$this->blogService->getPost($id)
),
]
);
Expand Down Expand Up @@ -208,10 +219,10 @@ public function create(EditPostRequest $postRequest, UserRequest $userRequest):
* )
* )
*/
public function update(EditPostRequest $postRequest): Response
public function update(EditPostRequest $postRequest, #[Route('id')] int $id): Response
{
$post = $this->postBuilder->build(
$this->blogService->getPost($postRequest->getId()),
$this->blogService->getPost($id),
$postRequest
);

Expand Down
33 changes: 0 additions & 33 deletions src/Blog/PageRequest.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Blog/ViewPostRequest.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\DataResponse\DataResponseFactoryInterface;
use Yiisoft\Router\CurrentRoute;
use Yiisoft\RequestModel\Attribute\Route;

/**
* @OA\Tag(
Expand Down Expand Up @@ -114,12 +114,12 @@ public function list(): ResponseInterface
* ),
* )
*/
public function get(CurrentRoute $currentRoute): ResponseInterface
public function get(#[Route('id')] int $id): ResponseInterface
{
/**
* @var User $user
*/
$user = $this->userRepository->findByPK($currentRoute->getArgument('id'));
$user = $this->userRepository->findByPK($id);
if ($user === null) {
throw new NotFoundException();
}
Expand Down