Skip to content

Commit

Permalink
Update v0.0.2 (#84)
Browse files Browse the repository at this point in the history
* Bump ramsey/composer-install from 2 to 3 (#39)

Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 2 to 3.
- [Release notes](https://github.com/ramsey/composer-install/releases)
- [Commits](ramsey/composer-install@v2...v3)

---
updated-dependencies:
- dependency-name: ramsey/composer-install
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump phpunit/phpunit from 10.5.7 to 10.5.11 (#37)

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 10.5.7 to 10.5.11.
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.5.11/ChangeLog-10.5.md)
- [Commits](sebastianbergmann/phpunit@10.5.7...10.5.11)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump laravel/pint from 1.13.8 to 1.14.0 (#36)

Bumps [laravel/pint](https://github.com/laravel/pint) from 1.13.8 to 1.14.0.
- [Release notes](https://github.com/laravel/pint/releases)
- [Changelog](https://github.com/laravel/pint/blob/main/CHANGELOG.md)
- [Commits](laravel/pint@v1.13.8...v1.14.0)

---
updated-dependencies:
- dependency-name: laravel/pint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump einaregilsson/beanstalk-deploy from 14 to 22 (#30)

Bumps [einaregilsson/beanstalk-deploy](https://github.com/einaregilsson/beanstalk-deploy) from 14 to 22.
- [Release notes](https://github.com/einaregilsson/beanstalk-deploy/releases)
- [Commits](einaregilsson/beanstalk-deploy@v14...v22)

---
updated-dependencies:
- dependency-name: einaregilsson/beanstalk-deploy
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump actions/checkout from 3 to 4 (#16)

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump aws-actions/configure-aws-credentials from 1 to 4 (#15)

Bumps [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) from 1 to 4.
- [Release notes](https://github.com/aws-actions/configure-aws-credentials/releases)
- [Changelog](https://github.com/aws-actions/configure-aws-credentials/blob/main/CHANGELOG.md)
- [Commits](aws-actions/configure-aws-credentials@v1...v4)

---
updated-dependencies:
- dependency-name: aws-actions/configure-aws-credentials
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump aws-actions/amazon-ecr-login from 1 to 2 (#14)

Bumps [aws-actions/amazon-ecr-login](https://github.com/aws-actions/amazon-ecr-login) from 1 to 2.
- [Release notes](https://github.com/aws-actions/amazon-ecr-login/releases)
- [Changelog](https://github.com/aws-actions/amazon-ecr-login/blob/main/CHANGELOG.md)
- [Commits](aws-actions/amazon-ecr-login@v1...v2)

---
updated-dependencies:
- dependency-name: aws-actions/amazon-ecr-login
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Update README.md

* Update README.md

* 로그인 관련 기능 수정 (#43)

* Update .env.example

* Update Account resource's namespace

* Update user name, not unique

* Update run-tests.yml

* Fix code format

* Fix routes, post controller

* 팩토리&시드 추가 (#48)

* Fix styling

* Update Post model

* Create API Healthcheck

* Update UserFactory

* Update UserSeeder

* Fix UserSeeders

* Fix typo

* Create PostFactory

* Create PostSeeder

* 게시판 오류 수정  (#49)

* Update IndexResource collection

* Update ShowResource

* Update Post Model

* Bump psalm/plugin-laravel from 2.8.0 to 2.10.1

Bumps [psalm/plugin-laravel](https://github.com/psalm/psalm-plugin-laravel) from 2.8.0 to 2.10.1.
- [Release notes](https://github.com/psalm/psalm-plugin-laravel/releases)
- [Commits](psalm/psalm-plugin-laravel@v2.8.0...v2.10.1)

---
updated-dependencies:
- dependency-name: psalm/plugin-laravel
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump mockery/mockery from 1.6.7 to 1.6.9

Bumps [mockery/mockery](https://github.com/mockery/mockery) from 1.6.7 to 1.6.9.
- [Release notes](https://github.com/mockery/mockery/releases)
- [Changelog](https://github.com/mockery/mockery/blob/1.6.x/CHANGELOG.md)
- [Commits](mockery/mockery@1.6.7...1.6.9)

---
updated-dependencies:
- dependency-name: mockery/mockery
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update run-tests.yml

* Bump league/flysystem-aws-s3-v3 from 3.24.0 to 3.25.1

Bumps [league/flysystem-aws-s3-v3](https://github.com/thephpleague/flysystem-aws-s3-v3) from 3.24.0 to 3.25.1.
- [Commits](thephpleague/flysystem-aws-s3-v3@3.24.0...3.25.1)

---
updated-dependencies:
- dependency-name: league/flysystem-aws-s3-v3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump mockery/mockery from 1.6.9 to 1.6.11

Bumps [mockery/mockery](https://github.com/mockery/mockery) from 1.6.9 to 1.6.11.
- [Release notes](https://github.com/mockery/mockery/releases)
- [Changelog](https://github.com/mockery/mockery/blob/1.6.x/CHANGELOG.md)
- [Commits](mockery/mockery@1.6.9...1.6.11)

---
updated-dependencies:
- dependency-name: mockery/mockery
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* 게시판 수정 사항 (#56)

* Update Resources, created_at

* Create Post edit

* Create PostPolicy

* Fix PostEditResource

* Create lang (localization)

* Update post response message

* Create ko language

* Fix post edit routes

* Update Post factory, user

* Publish laravel-errors

* Create custom error

* Update redirectTo

* Fix post model, fillable

* Fix styling

---------

Co-authored-by: kimchanhyung98 <kimchanhyung98@users.noreply.github.com>

* Bump laravel/pint from 1.14.0 to 1.15.0

Bumps [laravel/pint](https://github.com/laravel/pint) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/laravel/pint/releases)
- [Changelog](https://github.com/laravel/pint/blob/main/CHANGELOG.md)
- [Commits](laravel/pint@v1.14.0...v1.15.0)

---
updated-dependencies:
- dependency-name: laravel/pint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump league/flysystem-aws-s3-v3 from 3.25.1 to 3.26.0

Bumps [league/flysystem-aws-s3-v3](https://github.com/thephpleague/flysystem-aws-s3-v3) from 3.25.1 to 3.26.0.
- [Commits](thephpleague/flysystem-aws-s3-v3@3.25.1...3.26.0)

---
updated-dependencies:
- dependency-name: league/flysystem-aws-s3-v3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump psalm/plugin-laravel from 2.10.1 to 2.11.0

Bumps [psalm/plugin-laravel](https://github.com/psalm/psalm-plugin-laravel) from 2.10.1 to 2.11.0.
- [Release notes](https://github.com/psalm/psalm-plugin-laravel/releases)
- [Commits](psalm/psalm-plugin-laravel@v2.10.1...v2.11.0)

---
updated-dependencies:
- dependency-name: psalm/plugin-laravel
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump laravel/framework from 10.48.3 to 10.48.4

Bumps [laravel/framework](https://github.com/laravel/framework) from 10.48.3 to 10.48.4.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/11.x/CHANGELOG.md)
- [Commits](laravel/framework@v10.48.3...v10.48.4)

---
updated-dependencies:
- dependency-name: laravel/framework
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump laravel/sail from 1.28.1 to 1.29.1

Bumps [laravel/sail](https://github.com/laravel/sail) from 1.28.1 to 1.29.1.
- [Release notes](https://github.com/laravel/sail/releases)
- [Changelog](https://github.com/laravel/sail/blob/1.x/CHANGELOG.md)
- [Commits](laravel/sail@v1.28.1...v1.29.1)

---
updated-dependencies:
- dependency-name: laravel/sail
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump phpunit/phpunit from 10.5.11 to 10.5.16

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 10.5.11 to 10.5.16.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.5.16/ChangeLog-10.5.md)
- [Commits](sebastianbergmann/phpunit@10.5.11...10.5.16)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* 게시글 검색 기능 추가 (#65)

* Bump zircote/swagger-php from 4.8.4 to 4.8.5 (#46)

Bumps [zircote/swagger-php](https://github.com/zircote/swagger-php) from 4.8.4 to 4.8.5.
- [Release notes](https://github.com/zircote/swagger-php/releases)
- [Changelog](https://github.com/zircote/swagger-php/blob/master/Changelog.md)
- [Commits](zircote/swagger-php@4.8.4...4.8.5)

---
updated-dependencies:
- dependency-name: zircote/swagger-php
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump laravel/sail from 1.28.1 to 1.28.2 (#47)

Bumps [laravel/sail](https://github.com/laravel/sail) from 1.28.1 to 1.28.2.
- [Release notes](https://github.com/laravel/sail/releases)
- [Changelog](https://github.com/laravel/sail/blob/1.x/CHANGELOG.md)
- [Commits](laravel/sail@v1.28.1...v1.28.2)

---
updated-dependencies:
- dependency-name: laravel/sail
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump phpunit/phpunit from 10.5.11 to 10.5.12 (#44)

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 10.5.11 to 10.5.12.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.5.12/ChangeLog-10.5.md)
- [Commits](sebastianbergmann/phpunit@10.5.11...10.5.12)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump laravel/framework from 10.46.0 to 10.47.0 (#45)

Bumps [laravel/framework](https://github.com/laravel/framework) from 10.46.0 to 10.47.0.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/10.x/CHANGELOG.md)
- [Commits](laravel/framework@v10.46.0...v10.47.0)

---
updated-dependencies:
- dependency-name: laravel/framework
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Add laravel/scout package

* Update .env.example

* Update post seeding

* Add algolia/algoliasearch-client-php package

* Create Post searchable

* Update post type

* Update post index(search)

* Fix apple login, jwtConfig construct

- Lcobucci\JWT\Configuration is not instantiable
- Run 'php artisan route:list'

* Add dedoc/scramble package

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump zircote/swagger-php from 4.8.4 to 4.8.7 (#61)

Bumps [zircote/swagger-php](https://github.com/zircote/swagger-php) from 4.8.4 to 4.8.7.
- [Release notes](https://github.com/zircote/swagger-php/releases)
- [Changelog](https://github.com/zircote/swagger-php/blob/master/Changelog.md)
- [Commits](zircote/swagger-php@4.8.4...4.8.7)

---
updated-dependencies:
- dependency-name: zircote/swagger-php
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Bump dependabot/fetch-metadata from 1.6.0 to 2.0.0 (#53)

Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.6.0 to 2.0.0.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](dependabot/fetch-metadata@v1.6.0...v2.0.0)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@gmail.com>

* Fix package update interval

* 게시글 예외 처리 (#66)

* Update PostController, exception

* Update PostController, transaction

* Create Post FormRequest

* Fix PostSeeder

* Update Post ShowResource, is_edit

Check if edits are possible

* Update UserFactory, email_verified_at null

* Update MessageResource

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: kimchanhyung98 <kimchanhyung98@users.noreply.github.com>
  • Loading branch information
4 people authored May 21, 2024
1 parent eae2abf commit d94f79e
Show file tree
Hide file tree
Showing 55 changed files with 1,748 additions and 1,383 deletions.
31 changes: 21 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password

# Mail
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

# Cache
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
Expand All @@ -45,6 +35,16 @@ MEMCACHED_HOST=127.0.0.1
SESSION_DRIVER=file
SESSION_LIFETIME=120

# Mail
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

# Broadcast
BROADCAST_DRIVER=log
#BROADCAST_DRIVER=pusher
Expand Down Expand Up @@ -74,6 +74,14 @@ SAIL_XDEBUG_CONFIG="client_host=<host-ip-address>"
WWWUSER="www-data"
WWWGROUP=1000

# Laravel Scout
SCOUT_DRIVER=algolia
SCOUT_PREFIX=
SCOUT_QUEUE=false
SCOUT_IDENTIFY=false
#ALGOLIA_APP_ID=
#ALGOLIA_SECRET=

# Laravel Vite
VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
Expand All @@ -83,6 +91,9 @@ VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

# Apple Login
APPLE_TEAM_ID=
APPLE_KEY_ID=
# bundle id (com.company.app)
APPLE_CLIENT_ID=
APPLE_CLIENT_SECRET=
APPLE_REDIRECT_URI=
Expand Down
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
labels:
- "dependencies"

- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
labels:
- "dependencies"
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.0.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3]
laravel: [10.*, 11.*]
php: [8.3] # [8.2, 8.3]
laravel: [10.*] # [10.*, 11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ brew install php@8.3 composer
composer install
sail up # or ./vendor/bin/sail up
sail artisan migrate --seed
sail artisan scout:import "App\Models\Post"
```

## OpenAPI

Scramble - Laravel OpenAPI(Swagger) Generator 를 사용하여 API 문서를 확인할 수 있습니다.
- localhost/docs/api
12 changes: 4 additions & 8 deletions app/Http/Controllers/Account/AppleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ class AppleController extends Controller
{
public const string PROVIDER = 'apple';

private function __construct(
public Configuration $jwtConfig
) {
// construct
}

/**
* SocialLogin (Apple)
*
Expand Down Expand Up @@ -73,16 +67,18 @@ public function __invoke(Request $request)
*/
private function getToken($redirectUri): void
{
$jwtConfig = app(Configuration::class);

config()->set('services.apple.redirect', $redirectUri);
$now = CarbonImmutable::now();
$token = $this->jwtConfig->builder()
$token = $jwtConfig->builder()
->issuedBy(config('services.apple.team_id'))
->issuedAt($now)
->expiresAt($now->addHour())
->permittedFor('https://appleid.apple.com')
->relatedTo(config('services.apple.client_id'))
->withHeader('kid', config('services.apple.key_id'))
->getToken($this->jwtConfig->signer(), $this->jwtConfig->signingKey());
->getToken($jwtConfig->signer(), $jwtConfig->signingKey());

config()->set('services.apple.client_secret', $token->toString());
}
Expand Down
13 changes: 13 additions & 0 deletions app/Http/Controllers/ErrorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ErrorController extends Controller
{
public function __invoke(Request $request)
{
abort($request->code ?? 500, $request->message ?? null);
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/HealthCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Post;
use Illuminate\Http\JsonResponse;

class HealthCheckController extends Controller
Expand All @@ -11,6 +12,8 @@ class HealthCheckController extends Controller
*/
public function __invoke(): JsonResponse
{
return response()->json(['status' => 'healthy']);
return response()->json([
'status' => ! Post::first() ? 'unhealthy' : 'healthy',
]);
}
}
113 changes: 80 additions & 33 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,122 @@

namespace App\Http\Controllers;

use App\Http\Requests\Post\IndexRequest;
use App\Http\Requests\Post\StoreRequest;
use App\Http\Requests\Post\UpdateRequest;
use App\Http\Resources\MessageResource;
use App\Http\Resources\Post\EditResource;
use App\Http\Resources\Post\IndexResource;
use App\Http\Resources\Post\MessageResource;
use App\Http\Resources\Post\ShowResource;
use App\Models\Board\Post;
use Illuminate\Http\Request;
use App\Models\Post;
use Exception;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;

class PostController extends Controller
{
public function index(): IndexResource
public function index(IndexRequest $request): AnonymousResourceCollection
{
return new IndexResource(
Post::with('user')->paginate(10)
return IndexResource::collection(
Post::search($request->q)
// ->when($request->type, fn ($query, $type) => $query->where('type', $type))
// ->query(fn (Builder $query) => $query->with('user:id,nickname'))
->when($request->type, function ($query, $type) {
return $query->where('type', $type);
})->query(function ($query) {
return $query->with('user:id,nickname');
})->paginate(10)
);
}

public function store(Request $request): MessageResource
public function store(StoreRequest $request): MessageResource
{
$post = Post::create([
'user_id' => Auth::id(),
'type' => $request->type ?? null,
'title' => $request->title,
'contents' => $request->contents,
'is_open' => $request->is_open ?? false,
]);
try {
DB::beginTransaction();
$post = Post::create([
'user_id' => Auth::id(),
'type' => $request->type ?? 'free',
'title' => $request->title,
'contents' => $request->contents,
'is_open' => $request->is_open ?? false,
]);
DB::commit();

$post->searchable();
} catch (Exception $e) {
DB::rollBack();
logger($e->getMessage());
abort(500);
}

return new MessageResource([
'id' => $post->id,
'message' => '게시글이 등록되었습니다.',
'message' => __('post.store'),
]);
}

public function show(Post $post): ShowResource
{
$post->increment('hit');
try {
$post->increment('hit');
} catch (Exception $e) {
logger($e->getMessage());
}

return new ShowResource($post);
}

public function update(Request $request, Post $post): MessageResource
public function edit(Post $post): EditResource
{
if ($post->user_id !== Auth::id()) {
abort(403, '게시글 작성자만 수정할 수 있습니다.');
}
Gate::authorize('update', $post);

$post->update([
'type' => $request->type ?? null,
'title' => $request->title,
'contents' => $request->contents,
'is_open' => $request->is_open ?? false,
]);
return new EditResource($post);
}

public function update(UpdateRequest $request, Post $post): MessageResource
{
Gate::authorize('update', $post);

try {
DB::beginTransaction();
$post->update([
'type' => $request->type,
'title' => $request->title,
'contents' => $request->contents,
'is_open' => $request->is_open,
]);
DB::commit();

$post->searchable();
} catch (Exception $e) {
DB::rollBack();
logger($e->getMessage());
abort(500);
}

return new MessageResource([
'id' => $post->id,
'message' => '게시글이 수정되었습니다.',
'message' => __('post.update'),
]);
}

public function destroy(Post $post): MessageResource
{
if ($post->user_id !== Auth::id()) {
abort(403, '게시글 작성자만 삭제할 수 있습니다.');
}
Gate::authorize('delete', $post);

try {
$post->delete();

$post->delete();
$post->unsearchable();
} catch (Exception $e) {
logger($e->getMessage());
abort(500);
}

return new MessageResource([
'id' => 0,
'message' => '게시글이 삭제되었습니다.',
'message' => __('post.destroy'),
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class Authenticate extends Middleware
*/
protected function redirectTo(Request $request): ?string
{
return $request->expectsJson() ? null : route('login');
return $request->expectsJson() ? null : 'errors/401';
}
}
21 changes: 21 additions & 0 deletions app/Http/Requests/Post/IndexRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Requests\Post;

use Illuminate\Foundation\Http\FormRequest;

class IndexRequest extends FormRequest
{
public function rules(): array
{
return [
'q' => ['nullable', 'string', 'min:2', 'max:100'],
'type' => ['nullable', 'string', 'in:free,notice,faq'],
];
}

public function authorize(): bool
{
return true;
}
}
23 changes: 23 additions & 0 deletions app/Http/Requests/Post/StoreRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Requests\Post;

use Illuminate\Foundation\Http\FormRequest;

class StoreRequest extends FormRequest
{
public function rules(): array
{
return [
'type' => ['nullable', 'string', 'in:free,notice,faq'],
'title' => ['required', 'string', 'min:2', 'max:100'],
'contents' => ['required', 'string', 'min:2'],
'is_open' => ['nullable', 'boolean'],
];
}

public function authorize(): bool
{
return true;
}
}
Loading

0 comments on commit d94f79e

Please sign in to comment.