feat: 시스템 게시판 API 추가 (/api/v1/system-boards)
- SystemBoardController: 시스템 게시판 목록/상세/필드 조회
- SystemPostController: 시스템 게시글 CRUD + 댓글 CRUD
- BoardService: getSystemBoardByCode(), getTenantBoardByCode() 추가
- PostService: 시스템/테넌트 게시판 전용 메서드 추가
- routes/api.php: /system-boards/* 엔드포인트 12개 추가
- SystemBoardApi.php: Swagger 문서
시스템 게시판 (is_system=true, tenant_id=null)과
테넌트 게시판 (is_system=false, tenant_id={current})의
board_code 중복 가능성으로 인해 별도 엔드포인트로 분리
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
66
app/Http/Controllers/Api/V1/SystemBoardController.php
Normal file
66
app/Http/Controllers/Api/V1/SystemBoardController.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Boards\BoardService;
|
||||
|
||||
/**
|
||||
* 시스템 게시판 API 컨트롤러
|
||||
*
|
||||
* 시스템 게시판 (is_system=true, tenant_id=null):
|
||||
* - 본사에서 생성/관리하는 게시판
|
||||
* - 모든 테넌트에서 읽기 가능
|
||||
* - URL: /api/v1/system-boards/{code}
|
||||
*/
|
||||
class SystemBoardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected BoardService $boardService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 목록 조회
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return ApiResponse::handle(function () {
|
||||
$filters = request()->only(['board_type', 'search']);
|
||||
|
||||
return $this->boardService->getSystemBoards($filters);
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 상세 조회 (code 기반)
|
||||
*/
|
||||
public function show(string $code)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($code) {
|
||||
$board = $this->boardService->getSystemBoardByCode($code);
|
||||
|
||||
if (! $board) {
|
||||
abort(404, __('error.board.not_found'));
|
||||
}
|
||||
|
||||
return $board->load('customFields');
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 필드 목록 조회
|
||||
*/
|
||||
public function fields(string $code)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($code) {
|
||||
$board = $this->boardService->getSystemBoardByCode($code);
|
||||
|
||||
if (! $board) {
|
||||
abort(404, __('error.board.not_found'));
|
||||
}
|
||||
|
||||
return $this->boardService->getBoardFields($board->id);
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
}
|
||||
152
app/Http/Controllers/Api/V1/SystemPostController.php
Normal file
152
app/Http/Controllers/Api/V1/SystemPostController.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Boards\CommentStoreRequest;
|
||||
use App\Http\Requests\Boards\PostStoreRequest;
|
||||
use App\Http\Requests\Boards\PostUpdateRequest;
|
||||
use App\Services\Boards\PostService;
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 API 컨트롤러
|
||||
*
|
||||
* URL: /api/v1/system-boards/{code}/posts
|
||||
* - {code}: 시스템 게시판 코드 (board_code)
|
||||
*/
|
||||
class SystemPostController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected PostService $postService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 목록 조회
|
||||
*/
|
||||
public function index(string $code)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($code) {
|
||||
$filters = request()->only(['search', 'is_notice', 'status']);
|
||||
$perPage = (int) request()->get('per_page', 15);
|
||||
|
||||
return $this->postService->getPostsBySystemBoardCode($code, $filters, $perPage);
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 상세 조회
|
||||
*/
|
||||
public function show(string $code, int $id)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($code, $id) {
|
||||
$post = $this->postService->getPostBySystemBoardCodeAndId($code, $id);
|
||||
|
||||
if (! $post) {
|
||||
abort(404, __('error.post.not_found'));
|
||||
}
|
||||
|
||||
// 조회수 증가
|
||||
$post->increment('views');
|
||||
|
||||
// 커스텀 필드 값 추가
|
||||
$post->custom_field_values = $this->postService->getCustomFieldValues($id);
|
||||
|
||||
return $post;
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 작성
|
||||
*/
|
||||
public function store(PostStoreRequest $request, string $code)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request, $code) {
|
||||
return $this->postService->createPostBySystemBoardCode($code, $request->validated());
|
||||
}, __('message.created'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 수정
|
||||
*/
|
||||
public function update(PostUpdateRequest $request, string $code, int $id)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request, $code, $id) {
|
||||
$post = $this->postService->updatePostBySystemBoardCode($code, $id, $request->validated());
|
||||
|
||||
if (! $post) {
|
||||
abort(404, __('error.post.not_found'));
|
||||
}
|
||||
|
||||
return $post;
|
||||
}, __('message.updated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 삭제
|
||||
*/
|
||||
public function destroy(string $code, int $id)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($code, $id) {
|
||||
$deleted = $this->postService->deletePostBySystemBoardCode($code, $id);
|
||||
|
||||
if (! $deleted) {
|
||||
abort(404, __('error.post.not_found'));
|
||||
}
|
||||
|
||||
return ['deleted' => true];
|
||||
}, __('message.deleted'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 댓글 목록 조회
|
||||
*/
|
||||
public function comments(string $code, int $postId)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($postId) {
|
||||
return $this->postService->getComments($postId);
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 댓글 작성
|
||||
*/
|
||||
public function storeComment(CommentStoreRequest $request, string $code, int $postId)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request, $postId) {
|
||||
return $this->postService->createComment($postId, $request->validated());
|
||||
}, __('message.created'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 댓글 수정
|
||||
*/
|
||||
public function updateComment(CommentStoreRequest $request, string $code, int $postId, int $commentId)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request, $commentId) {
|
||||
$comment = $this->postService->updateComment($commentId, $request->validated());
|
||||
|
||||
if (! $comment) {
|
||||
abort(404, __('error.comment.not_found'));
|
||||
}
|
||||
|
||||
return $comment;
|
||||
}, __('message.updated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 게시판 게시글 댓글 삭제
|
||||
*/
|
||||
public function destroyComment(string $code, int $postId, int $commentId)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($commentId) {
|
||||
$deleted = $this->postService->deleteComment($commentId);
|
||||
|
||||
if (! $deleted) {
|
||||
abort(404, __('error.comment.not_found'));
|
||||
}
|
||||
|
||||
return ['deleted' => true];
|
||||
}, __('message.deleted'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user