Skip to content
Snippets Groups Projects
Commit d34cf7e7 authored by Rava Maulana's avatar Rava Maulana
Browse files

feat: added episode to session on play

parent d9e39de6
Branches
No related merge requests found
...@@ -15,6 +15,8 @@ services: ...@@ -15,6 +15,8 @@ services:
restart: always restart: always
ports: ports:
- 3308:3307 - 3308:3307
expose:
- 3307
hostname: tubes-php-db hostname: tubes-php-db
env_file: .env env_file: .env
volumes: volumes:
......
<?php
class PostPlayEpisodeController
{
public function call()
{
session_start();
if (!isset($_SESSION["user_id"])) {
http_response_code(403);
header("Content-Type: application/json");
echo json_encode(["message" => "unauthorized"]);
return;
}
// Check for podcast id
if (!isset($_POST["idEpisode"])) {
http_response_code(400);
header("Content-Type: application/json");
echo json_encode(["message" => "missing episode id"]);
return;
}
$_SESSION["eps_id"] = $_POST["idEpisode"];
http_response_code(200);
header("Content-Type: application/json");
echo json_encode(["message" => "success"]);
}
}
...@@ -28,6 +28,7 @@ class App ...@@ -28,6 +28,7 @@ class App
$router->delete("public/dashboard/podcast", new DeletePodcastController()); $router->delete("public/dashboard/podcast", new DeletePodcastController());
$router->get("public/podcast", new GetPodcastPageController()); $router->get("public/podcast", new GetPodcastPageController());
$router->post("public/episode/play", new PostPlayEpisodeController());
$router->post("public/logout", new LogoutController()); $router->post("public/logout", new LogoutController());
......
...@@ -22,6 +22,7 @@ require_once __DIR__ . "/controllers/dashboard/post_edit_podcast.php"; ...@@ -22,6 +22,7 @@ require_once __DIR__ . "/controllers/dashboard/post_edit_podcast.php";
require_once __DIR__ . "/controllers/dashboard/delete_podcast.php"; require_once __DIR__ . "/controllers/dashboard/delete_podcast.php";
require_once __DIR__ . "/controllers/podcast/get_page.php"; require_once __DIR__ . "/controllers/podcast/get_page.php";
require_once __DIR__ . "/controllers/episode/post_play_episode.php";
require_once __DIR__ . "/controllers/logout/logout.php"; require_once __DIR__ . "/controllers/logout/logout.php";
......
...@@ -2,16 +2,27 @@ ...@@ -2,16 +2,27 @@
// Get DOM elements // Get DOM elements
const playButtonsEl = document.querySelectorAll(".play-button"); const playButtonsEl = document.querySelectorAll(".play-button");
const addLibraryButtonEl = document.getElementById("add-library-btn") const addLibraryButtonEl = document.getElementById("add-library-btn");
const libraryChoicesEl = document.getElementById("library-choices") const libraryChoicesEl = document.getElementById("library-choices");
const overlayEl = document.getElementById("overlay-library") const overlayEl = document.getElementById("overlay-library");
// Handle play episode // Handle play episode
Array.from(playButtonsEl).forEach((el) => { Array.from(playButtonsEl).forEach((el) => {
el.addEventListener("click", (e) => { el.addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
console.log(`play episode id: ${el.dataset.id}`); const formData = new FormData();
formData.append("idEpisode", el.dataset.id);
const xhr = new XMLHttpRequest();
xhr.open("POST", "/public/episode/play");
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
}
};
xhr.send(formData);
}); });
}); });
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment