diff --git a/app/AboutMe/Actions/GetAboutMeAction.php b/app/AboutMe/Actions/GetAboutMeAction.php new file mode 100644 index 0000000..224f5d3 --- /dev/null +++ b/app/AboutMe/Actions/GetAboutMeAction.php @@ -0,0 +1,27 @@ +getAboutMeQuery)(); + } +} diff --git a/app/AboutMe/Api/V1/ApiResources/AboutMeJsonResource.php b/app/AboutMe/Api/V1/ApiResources/AboutMeJsonResource.php new file mode 100644 index 0000000..2105a2b --- /dev/null +++ b/app/AboutMe/Api/V1/ApiResources/AboutMeJsonResource.php @@ -0,0 +1,26 @@ + $this->resource->uuid, + 'type' => 'aboutMe', + 'attributes' => [ + 'content' => $this->resource->content, + ], + ]; + } +} diff --git a/app/AboutMe/Api/V1/Controllers/AboutMeController.php b/app/AboutMe/Api/V1/Controllers/AboutMeController.php new file mode 100644 index 0000000..52c40ea --- /dev/null +++ b/app/AboutMe/Api/V1/Controllers/AboutMeController.php @@ -0,0 +1,30 @@ +getAboutMeAction)() + ); + } +} diff --git a/app/AboutMe/Factories/AboutMeFactory.php b/app/AboutMe/Factories/AboutMeFactory.php new file mode 100644 index 0000000..7545800 --- /dev/null +++ b/app/AboutMe/Factories/AboutMeFactory.php @@ -0,0 +1,28 @@ + $this->faker->paragraphs(nb: 10, asText: true), + ]; + } +} diff --git a/app/AboutMe/Models/AboutMe.php b/app/AboutMe/Models/AboutMe.php new file mode 100644 index 0000000..c5b55e8 --- /dev/null +++ b/app/AboutMe/Models/AboutMe.php @@ -0,0 +1,44 @@ + EfficientUuid::class, + ]; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'uuid', + 'content', + ]; +} diff --git a/app/AboutMe/Queries/GetAboutMeQuery.php b/app/AboutMe/Queries/GetAboutMeQuery.php new file mode 100644 index 0000000..e253892 --- /dev/null +++ b/app/AboutMe/Queries/GetAboutMeQuery.php @@ -0,0 +1,31 @@ +aboutMe->newQuery()->first(); + + /** @var AboutMe|null $aboutMe */ + return $aboutMe ?? $this->aboutMe; + } +} diff --git a/app/AboutMe/Routes/api.php b/app/AboutMe/Routes/api.php new file mode 100644 index 0000000..c7650c2 --- /dev/null +++ b/app/AboutMe/Routes/api.php @@ -0,0 +1,7 @@ +get(uri: '/', action: [AboutMeController::class, '__invoke']); diff --git a/app/AboutMe/Tests/Feature/AboutMeTest.php b/app/AboutMe/Tests/Feature/AboutMeTest.php new file mode 100644 index 0000000..da75379 --- /dev/null +++ b/app/AboutMe/Tests/Feature/AboutMeTest.php @@ -0,0 +1,37 @@ +create(); + + $response = $this->getJson(route($this->aboutMeRouteName)); + + $response->assertExactJson([ + 'data' => [ + 'id' => $aboutMe->uuid, + 'type' => 'aboutMe', + 'attributes' => [ + 'content' => $aboutMe->content, + ], + ], + ]); + + $response->assertOk(); + } + +} diff --git a/app/Blog/Models/BlogPost.php b/app/Blog/Models/BlogPost.php index 0206c82..fbbd951 100644 --- a/app/Blog/Models/BlogPost.php +++ b/app/Blog/Models/BlogPost.php @@ -2,7 +2,7 @@ namespace DavorMinchorov\Blog\Models; -use DavorMinchorov\Blog\Factories\BlogPostFactory; +use DavorMinchorov\Blog\Factories\AboutMeFactory; use DavorMinchorov\Blog\QueryBuilders\BlogPostQueryBuilder; use Dyrynda\Database\Casts\EfficientUuid; use Dyrynda\Database\Support\GeneratesUuid; @@ -15,7 +15,7 @@ /** * DavorMinchorov\Blog\Models\BlogPost * - * @method static BlogPostFactory factory(...$parameters) + * @method static AboutMeFactory factory(...$parameters) * @method static BlogPostQueryBuilder|BlogPost newModelQuery() * @method static BlogPostQueryBuilder|BlogPost newQuery() * @method static BlogPostQueryBuilder|BlogPost query() @@ -25,7 +25,6 @@ * @method static BlogPostQueryBuilder|BlogPost whereUuid($uuid, $uuidColumn = null) * @mixin Eloquent * @property mixed $uuid - * @property mixed $user_uuid * @property string $title * @property string $slug * @property string $excerpt diff --git a/config/modules.php b/config/modules.php index 26e6edc..ed4779a 100644 --- a/config/modules.php +++ b/config/modules.php @@ -44,6 +44,15 @@ 'api_namespace' => 'DavorMinchorov\Contact\Api\V1\Controllers', ], + 'aboutMe' => [ + 'name' => 'AboutMe', + 'api_routes_path' => 'app/AboutMe/Routes/api.php', + 'api_prefix' => 'v1/about-me', + 'api_route_name_prefix' => 'v1.aboutMe', + 'api_middleware' => ['api'], + 'api_namespace' => 'DavorMinchorov\AboutMe\Api\V1\Controllers', + ], + 'blog' => [ 'name' => 'Blog', 'api_routes_path' => 'app/Blog/Routes/api.php', diff --git a/database/migrations/2021_11_13_173212_create_about_me_table.php b/database/migrations/2021_11_13_173212_create_about_me_table.php new file mode 100644 index 0000000..2cb4af0 --- /dev/null +++ b/database/migrations/2021_11_13_173212_create_about_me_table.php @@ -0,0 +1,33 @@ +id(); + $table->efficientUuid(column: 'uuid'); + $table->text(column: 'content'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists(table: 'about_me'); + } +} diff --git a/phpunit.xml b/phpunit.xml index c8b2d2c..a7ef9ea 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -14,6 +14,9 @@ ./app/Blog/Tests/Feature + + ./app/AboutMe/Tests/Feature +