feat(Category): 기본 카테고리 보호 및 ID 재정렬
- is_default 컬럼 추가 (기존 6개 카테고리 = 기본) - 카테고리 ID 재정렬: 기타(1), 유튜브(2), X(3), 앨범(4), 팬사인회(5), 콘서트(6) - 일정 테이블 category_id 동기화 - 기본 카테고리 삭제 불가 (백엔드 + 프론트엔드) - 일정 사용 중인 카테고리 삭제 불가
This commit is contained in:
parent
2ad5341f9c
commit
8e3cab9b10
2 changed files with 33 additions and 7 deletions
|
|
@ -1103,7 +1103,24 @@ router.delete(
|
|||
return res.status(404).json({ error: "카테고리를 찾을 수 없습니다." });
|
||||
}
|
||||
|
||||
// TODO: 해당 카테고리를 사용하는 일정이 있는지 확인
|
||||
// 기본 카테고리는 삭제 불가
|
||||
if (existing[0].is_default === 1) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "기본 카테고리는 삭제할 수 없습니다." });
|
||||
}
|
||||
|
||||
// 해당 카테고리를 사용하는 일정이 있는지 확인
|
||||
const [usedSchedules] = await pool.query(
|
||||
"SELECT COUNT(*) as count FROM schedules WHERE category_id = ?",
|
||||
[id]
|
||||
);
|
||||
if (usedSchedules[0].count > 0) {
|
||||
return res.status(400).json({
|
||||
error: `해당 카테고리를 사용하는 일정이 ${usedSchedules[0].count}개 있어 삭제할 수 없습니다.`,
|
||||
});
|
||||
}
|
||||
|
||||
await pool.query("DELETE FROM schedule_categories WHERE id = ?", [id]);
|
||||
|
||||
res.json({ message: "카테고리가 삭제되었습니다." });
|
||||
|
|
|
|||
|
|
@ -266,12 +266,21 @@ function AdminScheduleCategory() {
|
|||
>
|
||||
<Edit3 size={18} />
|
||||
</button>
|
||||
{category.is_default ? (
|
||||
<span
|
||||
className="p-2 text-gray-300 cursor-not-allowed"
|
||||
title="기본 카테고리는 삭제할 수 없습니다"
|
||||
>
|
||||
<Trash2 size={18} />
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
onClick={(e) => { e.stopPropagation(); openDeleteDialog(category); }}
|
||||
className="p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors"
|
||||
>
|
||||
<Trash2 size={18} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</Reorder.Item>
|
||||
))}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue