diff --git a/app/Http/Controllers/Api/Admin/BoardController.php b/app/Http/Controllers/Api/Admin/BoardController.php index 4e741844..0d9d78e5 100644 --- a/app/Http/Controllers/Api/Admin/BoardController.php +++ b/app/Http/Controllers/Api/Admin/BoardController.php @@ -58,7 +58,8 @@ public function stats(): JsonResponse */ public function show(int $id): JsonResponse { - $board = $this->boardService->getBoardById($id, true); + // systemOnly=false: 테넌트 게시판도 조회 가능 + $board = $this->boardService->getBoardById($id, true, false); if (! $board) { return response()->json([ @@ -109,7 +110,7 @@ public function store(Request $request): JsonResponse } /** - * 게시판 수정 + * 게시판 수정 (시스템/테넌트 공통) */ public function update(Request $request, int $id): JsonResponse { @@ -126,15 +127,35 @@ public function update(Request $request, int $id): JsonResponse 'is_active' => 'nullable|boolean', ]); - // 코드 중복 체크 (자신 제외) - if ($this->boardService->isCodeExists($validated['board_code'], $id)) { + // 기존 게시판 조회 (systemOnly=false) + $board = $this->boardService->getBoardById($id, true, false); + + if (! $board) { return response()->json([ 'success' => false, - 'message' => '이미 사용 중인 게시판 코드입니다.', - ], 422); + 'message' => '게시판을 찾을 수 없습니다.', + ], 404); } - $this->boardService->updateBoard($id, $validated); + // 코드 중복 체크 (자신 제외, 시스템/테넌트 구분) + if ($board->is_system) { + if ($this->boardService->isCodeExists($validated['board_code'], $id)) { + return response()->json([ + 'success' => false, + 'message' => '이미 사용 중인 게시판 코드입니다.', + ], 422); + } + } else { + if ($this->boardService->isTenantCodeExists($validated['board_code'], $board->tenant_id, $id)) { + return response()->json([ + 'success' => false, + 'message' => '해당 테넌트에서 이미 사용 중인 게시판 코드입니다.', + ], 422); + } + } + + // 시스템/테넌트 공통 수정 메서드 사용 + $this->boardService->updateAnyBoard($id, $validated); return response()->json([ 'success' => true, diff --git a/app/Http/Controllers/BoardController.php b/app/Http/Controllers/BoardController.php index 21b7a531..59c5b6f1 100644 --- a/app/Http/Controllers/BoardController.php +++ b/app/Http/Controllers/BoardController.php @@ -35,7 +35,8 @@ public function create(): View */ public function edit(int $id): View { - $board = $this->boardService->getBoardById($id, true); + // systemOnly=false: 테넌트 게시판도 수정 가능 + $board = $this->boardService->getBoardById($id, true, false); if (! $board) { abort(404, '게시판을 찾을 수 없습니다.'); diff --git a/app/Services/BoardService.php b/app/Services/BoardService.php index 07c34ffc..8dd0d1ef 100644 --- a/app/Services/BoardService.php +++ b/app/Services/BoardService.php @@ -76,14 +76,19 @@ public function getActiveBoardList(): Collection /** * 특정 게시판 조회 + * + * @param bool $systemOnly true면 시스템 게시판만, false면 모든 게시판 */ - public function getBoardById(int $id, bool $withTrashed = false): ?Board + public function getBoardById(int $id, bool $withTrashed = false, bool $systemOnly = true): ?Board { $query = Board::query() - ->systemOnly() - ->with('fields') + ->with(['fields', 'tenant:id,code,company_name']) ->withCount('fields'); + if ($systemOnly) { + $query->systemOnly(); + } + if ($withTrashed) { $query->withTrashed(); } diff --git a/resources/views/menus/index.blade.php b/resources/views/menus/index.blade.php index a6a9582f..5a0b510f 100644 --- a/resources/views/menus/index.blade.php +++ b/resources/views/menus/index.blade.php @@ -89,6 +89,9 @@ class="bg-gray-800 hover:bg-gray-900 text-white px-4 py-2 rounded-lg transition