Skip to content

Commit

Permalink
feat: override post index action to get blog posts
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Dec 5, 2024
1 parent 789bd7c commit 4d864d9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Enums/StatusEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace CSlant\Blog\Api\Enums;

use Botble\Base\Supports\Enum;

/**
* @method static StatusEnum DRAFT()
* @method static StatusEnum PUBLISHED()
* @method static StatusEnum PENDING()
*/
class StatusEnum extends Enum

Check failure on line 12 in src/Enums/StatusEnum.php

View workflow job for this annotation

GitHub Actions / PHPStan - P8.3

Class CSlant\Blog\Api\Enums\StatusEnum extends unknown class Botble\Base\Supports\Enum.
{
public const PUBLISHED = 'published';
public const DRAFT = 'draft';
public const PENDING = 'pending';
}
29 changes: 29 additions & 0 deletions src/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,37 @@

namespace CSlant\Blog\Api\Http\Controllers;

use CSlant\Blog\Api\Enums\StatusEnum;
use CSlant\Blog\Api\Http\Resources\ListPostResource;
use CSlant\Blog\Core\Http\Controllers\Base\BasePostController;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PostController extends BasePostController
{
/**
* @group Blog API
*
* @param Request $request
*
* @return \Botble\Base\Http\Responses\BaseHttpResponse|\Illuminate\Http\JsonResponse|RedirectResponse|JsonResource
*/
public function index(Request $request)

Check failure on line 21 in src/Http/Controllers/PostController.php

View workflow job for this annotation

GitHub Actions / PHPStan - P8.3

Method CSlant\Blog\Api\Http\Controllers\PostController::index() has invalid return type Botble\Base\Http\Responses\BaseHttpResponse.
{
$data = $this->postRepository

Check failure on line 23 in src/Http/Controllers/PostController.php

View workflow job for this annotation

GitHub Actions / PHPStan - P8.3

Access to an undefined property CSlant\Blog\Api\Http\Controllers\PostController::$postRepository.
->advancedGet([
'with' => ['tags', 'categories', 'author', 'slugable'],
'condition' => ['status' => StatusEnum::PUBLISHED],
'paginate' => [
'per_page' => $request->integer('per_page', 10),
'current_paged' => $request->integer('page', 1),
],
]);

return $this

Check failure on line 33 in src/Http/Controllers/PostController.php

View workflow job for this annotation

GitHub Actions / PHPStan - P8.3

Call to an undefined method CSlant\Blog\Api\Http\Controllers\PostController::httpResponse().
->httpResponse()
->setData(ListPostResource::collection($data))

Check failure on line 35 in src/Http/Controllers/PostController.php

View workflow job for this annotation

GitHub Actions / PHPStan - P8.3

Call to an undefined static method CSlant\Blog\Api\Http\Resources\ListPostResource::collection().
->toApiResponse();
}
}

0 comments on commit 4d864d9

Please sign in to comment.