feat: [boards] 게시판 API 시스템 구현
- BoardController, PostController 추가 - Board, BoardSetting 모델 수정 - BoardService 추가 - FormRequest 클래스 추가 - Swagger 문서 추가 (BoardApi, PostApi) - 게시판 시스템 필드 마이그레이션 추가
This commit is contained in:
124
app/Http/Controllers/Api/V1/BoardController.php
Normal file
124
app/Http/Controllers/Api/V1/BoardController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Boards\BoardStoreRequest;
|
||||
use App\Http\Requests\Boards\BoardUpdateRequest;
|
||||
use App\Services\Boards\BoardService;
|
||||
|
||||
/**
|
||||
* 게시판 API 컨트롤러 (테넌트용)
|
||||
*
|
||||
* 테넌트에서 접근 가능한 게시판:
|
||||
* - 시스템 게시판 (is_system=true) - 읽기만 가능
|
||||
* - 테넌트 게시판 (tenant_id=현재 테넌트) - CRUD 가능
|
||||
*/
|
||||
class BoardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected BoardService $boardService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 접근 가능한 게시판 목록 조회
|
||||
* - 시스템 게시판 + 테넌트 게시판
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return ApiResponse::handle(function () {
|
||||
$filters = request()->only(['board_type', 'search']);
|
||||
|
||||
return $this->boardService->getAccessibleBoards($filters);
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 게시판 상세 조회 (코드 기반)
|
||||
*/
|
||||
public function show(string $code)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($code) {
|
||||
$board = $this->boardService->getBoardByCode($code);
|
||||
|
||||
if (! $board) {
|
||||
abort(404, __('error.board.not_found'));
|
||||
}
|
||||
|
||||
return $board->load('customFields');
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 테넌트 게시판 생성
|
||||
*/
|
||||
public function store(BoardStoreRequest $request)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request) {
|
||||
return $this->boardService->createTenantBoard($request->validated());
|
||||
}, __('message.created'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 테넌트 게시판 수정
|
||||
* - 시스템 게시판은 수정 불가
|
||||
*/
|
||||
public function update(BoardUpdateRequest $request, int $id)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request, $id) {
|
||||
$board = $this->boardService->updateTenantBoard($id, $request->validated());
|
||||
|
||||
if (! $board) {
|
||||
abort(404, __('error.board.not_found'));
|
||||
}
|
||||
|
||||
return $board;
|
||||
}, __('message.updated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 테넌트 게시판 삭제
|
||||
* - 시스템 게시판은 삭제 불가
|
||||
*/
|
||||
public function destroy(int $id)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($id) {
|
||||
$deleted = $this->boardService->deleteTenantBoard($id);
|
||||
|
||||
if (! $deleted) {
|
||||
abort(404, __('error.board.not_found'));
|
||||
}
|
||||
|
||||
return ['deleted' => true];
|
||||
}, __('message.deleted'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 테넌트 게시판 목록만 조회
|
||||
*/
|
||||
public function tenantBoards()
|
||||
{
|
||||
return ApiResponse::handle(function () {
|
||||
$filters = request()->only(['board_type', 'search']);
|
||||
|
||||
return $this->boardService->getTenantBoards($filters);
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 게시판 필드 목록 조회
|
||||
*/
|
||||
public function fields(string $code)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($code) {
|
||||
$board = $this->boardService->getBoardByCode($code);
|
||||
|
||||
if (! $board) {
|
||||
abort(404, __('error.board.not_found'));
|
||||
}
|
||||
|
||||
return $this->boardService->getBoardFields($board->id);
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user