74 lines
1.9 KiB
PHP
74 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
try {
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
require_once __DIR__ . '/../db_conn.php';
|
|
$pdo = db_conn();
|
|
|
|
$payload = [];
|
|
$rawBody = file_get_contents('php://input');
|
|
if (is_string($rawBody) && $rawBody !== '') {
|
|
$decoded = json_decode($rawBody, true);
|
|
if (is_array($decoded)) {
|
|
$payload = $decoded;
|
|
}
|
|
}
|
|
|
|
// id 또는 comment_id 파라미터 지원
|
|
$commentIdRaw = $payload['id'] ?? $payload['comment_id'] ?? $_POST['id'] ?? $_POST['comment_id'] ?? null;
|
|
$commentId = is_numeric($commentIdRaw) ? (int)$commentIdRaw : 0;
|
|
if ($commentId <= 0) {
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => '삭제할 댓글 ID가 올바르지 않습니다.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
$memberId = (string)($_SESSION['member_id'] ?? '');
|
|
$sysCompCode = (string)($_SESSION['sys_comp_code'] ?? '');
|
|
|
|
if ($memberId === '') {
|
|
http_response_code(401);
|
|
echo json_encode(['success' => false, 'message' => 'not_logged_in'], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
if ($sysCompCode === '') {
|
|
http_response_code(401);
|
|
echo json_encode(['success' => false, 'message' => 'sys_comp_code_missing'], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
// edu_comments 테이블에서 DELETE (본인 댓글만)
|
|
$stmt = $pdo->prepare(
|
|
'DELETE FROM edu_comments WHERE id = ? AND member_id = ? AND sys_comp_code = ?'
|
|
);
|
|
$stmt->execute([$commentId, $memberId, $sysCompCode]);
|
|
|
|
if ($stmt->rowCount() === 0) {
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => '삭제할 댓글이 없거나 권한이 없습니다.',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'data' => ['id' => $commentId],
|
|
], JSON_UNESCAPED_UNICODE);
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => 'server_error',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
}
|