From 38f948e1b58b6866c76630aa0a7cdce90e3b0cd5 Mon Sep 17 00:00:00 2001 From: Hidayatullah Wildan Ghaly Buchary <16521502@std.stei.itb.ac.id> Date: Sat, 7 Oct 2023 19:48:26 +0700 Subject: [PATCH] feat: add claim and unclaim backend for CHALLENGE --- api/challenge/claim.php | 19 ++++++++++++++++++- api/challenge/unclaim.php | 18 +++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/api/challenge/claim.php b/api/challenge/claim.php index cff683b..d6d1c86 100644 --- a/api/challenge/claim.php +++ b/api/challenge/claim.php @@ -1,3 +1,20 @@ <?php -echo "Hello World!"; \ No newline at end of file +include_once __DIR__."/../session.php"; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + parse_str(file_get_contents('php://input'), $_POST); + $user_id = $_POST['user_id']; + $quest_id = $_POST['quest_id']; + + $conn = Database::getInstance(); + + $sql = "INSERT INTO user_quest (user_id, quest_id) VALUES ($user_id, $quest_id)"; + $result = $conn->query($sql); + + echo $sql; + +} else { + http_response_code(405); + echo "Metode HTTP yang tidak diizinkan"; +} \ No newline at end of file diff --git a/api/challenge/unclaim.php b/api/challenge/unclaim.php index e716e01..dad667f 100644 --- a/api/challenge/unclaim.php +++ b/api/challenge/unclaim.php @@ -1,3 +1,19 @@ <?php -echo "Hello World2!"; \ No newline at end of file +include_once __DIR__."/../session.php"; + +if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { + parse_str(file_get_contents('php://input'), $_DELETE); + $user_id = $_DELETE['user_id']; + $quest_id = $_DELETE['quest_id']; + + $conn = Database::getInstance(); + + $sql = "DELETE FROM user_quest WHERE user_id = $user_id AND quest_id = $quest_id"; + $result = $conn->query($sql); + + echo $sql; +} else { + http_response_code(405); + echo "Metode HTTP yang tidak diizinkan"; +} \ No newline at end of file -- GitLab