DB 스키마 + 백엔드 로직 + API 레이어를 구현.
- board_reaction_types/board_reactions 테이블 신규, boards.use_reaction·
active_reaction_types, board_posts.reaction_counts 컬럼 추가
- ReactionType(다국어 JSON+폴백)/Reaction 모델, Repository 2종(인터페이스 주입)
- ReactionService: 등록/전환/해제 통합, DB::transaction 원자 카운트,
use_reaction·비활성유형·본인글·slug 스코프 차단, before/after_react 훅
- POST boards/{slug}/posts/{postId}/react(회원) + GET admin/reaction-types
- ReactPostRequest + AvailableReactionType Rule, PostResource/BoardResource 확장
- 반응 활동 로그(add/change/remove) + ko/en 다국어 + API 레퍼런스 문서
- 테스트 30건(Unit/Feature, 87 assertions) green, 마이그레이션 왕복 안전성 검증
프론트엔드 화면·ja 언어팩·CHANGELOG·버전 bump 는 후속 단계(4~5)에서 진행.
69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Sirsoft\Board\Http\Requests\User;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Modules\Sirsoft\Board\Repositories\Contracts\BoardRepositoryInterface;
|
|
use Modules\Sirsoft\Board\Rules\AvailableReactionType;
|
|
|
|
/**
|
|
* 게시글 반응 요청 폼 검증
|
|
*
|
|
* `reaction_type_id` 가 존재하는 활성 유형이면서 대상 게시판이 켠 유형인지
|
|
* 검증합니다. 게시판의 활성 유형 code 목록(`active_reaction_types`)을 조회해
|
|
* `AvailableReactionType` Rule 에 전달합니다.
|
|
*/
|
|
class ReactPostRequest extends FormRequest
|
|
{
|
|
/**
|
|
* 권한 체크는 라우트의 auth:sanctum 미들웨어에서 수행됩니다.
|
|
*
|
|
* @return bool 항상 true
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 요청에 적용할 검증 규칙
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$slug = (string) ($this->route('slug') ?? '');
|
|
$board = app(BoardRepositoryInterface::class)->findBySlug($slug);
|
|
$activeCodes = $board?->active_reaction_types ?? [];
|
|
|
|
return [
|
|
'reaction_type_id' => ['required', 'integer', new AvailableReactionType($activeCodes)],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 검증 오류 메시지 커스터마이징
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'reaction_type_id.required' => __('sirsoft-board::validation.reaction.reaction_type_id.required'),
|
|
'reaction_type_id.integer' => __('sirsoft-board::validation.reaction.reaction_type_id.integer'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 검증할 필드의 이름을 커스터마이징
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'reaction_type_id' => __('sirsoft-board::validation.attributes.reaction.reaction_type_id'),
|
|
];
|
|
}
|
|
}
|