2025-11-30 21:05:33 +09:00
|
|
|
<?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'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-27 18:27:19 +09:00
|
|
|
* 게시판 상세 조회 (ID 기반)
|
2025-11-30 21:05:33 +09:00
|
|
|
*/
|
2025-12-27 18:27:19 +09:00
|
|
|
public function show(int $id)
|
2025-11-30 21:05:33 +09:00
|
|
|
{
|
2025-12-27 18:27:19 +09:00
|
|
|
return ApiResponse::handle(function () use ($id) {
|
|
|
|
|
$board = $this->boardService->getBoardDetail($id);
|
2025-11-30 21:05:33 +09:00
|
|
|
|
|
|
|
|
if (! $board) {
|
|
|
|
|
abort(404, __('error.board.not_found'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-27 18:27:19 +09:00
|
|
|
return $board;
|
2025-11-30 21:05:33 +09:00
|
|
|
}, __('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'));
|
|
|
|
|
}
|
|
|
|
|
}
|