diff --git a/seeder/__pycache__/fakerData.cpython-311.pyc b/seeder/__pycache__/fakerData.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..331d84891777226ec2ff4dac67041556d6db06fb Binary files /dev/null and b/seeder/__pycache__/fakerData.cpython-311.pyc differ diff --git a/seeder/fakerData.py b/seeder/fakerData.py new file mode 100644 index 0000000000000000000000000000000000000000..d96f4f6642637cf63f8a90bb5888b55b4bbc768e --- /dev/null +++ b/seeder/fakerData.py @@ -0,0 +1,32 @@ +from faker import Faker +import random + +fake = Faker() + +def generateFakeUser(): + return { + 'email': fake.email(), + 'username': fake.user_name(), + 'password': '$2y$10$zB1TCZSYw3NXIXuu5tu.bO5Pnc7jaZSu/TC62aQ6I42sYM1bD4HJa', + 'first_name': fake.first_name(), + 'last_name': fake.last_name(), + 'status': fake.random_element(elements=(0, 1)), + 'role_id': 2 + } + +def generateFakePodcast(): + return { + 'title': fake.catch_phrase(), + 'description': fake.paragraph(), + 'creator_name': fake.name(), + 'category_id': random.randint(1, 5) + } + +def generateFakeEpisode(podcastId): + return { + 'podcast_id': podcastId, + 'category_id': random.randint(1, 5), + 'title': fake.catch_phrase(), + 'description': fake.paragraph(), + 'duration': random.randint(1, 100) * 60 + } \ No newline at end of file diff --git a/seeder/seeder.py b/seeder/seeder.py new file mode 100644 index 0000000000000000000000000000000000000000..62e0e5e32a99c8a63d5b8cebc65d76d691dfab5b --- /dev/null +++ b/seeder/seeder.py @@ -0,0 +1,111 @@ +import mysql.connector +from fakerData import generateFakeUser, generateFakePodcast, generateFakeEpisode +import random + +class DatabaseSeeder: + def __init__(self, connection): + self.connection = connection + + def seedUsers(self, num): + cursor = self.connection.cursor() + + for _ in range(num): + while True: + fakeUser = generateFakeUser() + try: + cursor.execute(""" + INSERT INTO users (email, username, password, first_name, last_name, status, role_id) + VALUES (%s, %s, %s, %s, %s, %s, %s) + """, ( + fakeUser['email'], + fakeUser['username'], + fakeUser['password'], + fakeUser['first_name'], + fakeUser['last_name'], + fakeUser['status'], + fakeUser['role_id'] + )) + break + except mysql.connector.errors.IntegrityError as e: + continue + + self.connection.commit() + cursor.close() + + print("Users seeds done!") + + def seedPodcasts(self, num): + cursor = self.connection.cursor() + + for _ in range(num): + while True: + fakePodcast = generateFakePodcast() + try: + cursor.execute(""" + INSERT INTO podcasts (title, description, creator_name, category_id) + VALUES (%s, %s, %s, %s) + """, ( + fakePodcast['title'], + fakePodcast['description'], + fakePodcast['creator_name'], + fakePodcast['category_id'] + )) + break + except mysql.connector.errors.IntegrityError as e: + continue + + self.connection.commit() + cursor.close() + + print("Podcasts seeds done!") + + def seedEpisodes(self, num): + cursor = self.connection.cursor() + + cursor.execute("SELECT podcast_id FROM podcasts") + podcast_ids = [row[0] for row in cursor.fetchall()] + + for _ in range(num): + podcast_id = random.choice(podcast_ids) + + while True: + fakeEpisode = generateFakeEpisode(podcast_id) + try: + cursor.execute(""" + INSERT INTO episodes (podcast_id, category_id, title, description, duration, audio_url) + VALUES (%s, %s, %s, %s, %s, %s) + """, ( + fakeEpisode['podcast_id'], + fakeEpisode['category_id'], + fakeEpisode['title'], + fakeEpisode['description'], + fakeEpisode['duration'], + '', + )) + break + except mysql.connector.errors.IntegrityError as e: + continue + + self.connection.commit() + cursor.close() + + print("Episodes seeds done!") + +# Replace with your actual database connection details +db_connection = mysql.connector.connect( + host='127.0.0.1', + user='podcastify', + port='3307', + password='podcastify', + database='podcastify' +) + +# Instantiate the seeder +seeder = DatabaseSeeder(db_connection) + +seeder.seedUsers(10000) +seeder.seedPodcasts(10000) +seeder.seedEpisodes(10000) + +# Close the connection +db_connection.close() diff --git a/src/app/controllers/EpisodeController.php b/src/app/controllers/EpisodeController.php index c96355fad2af9478bb9fa40676e1369ddaad7ad7..2aee56fae38d069165a68ccfd78a80027997de3b 100644 --- a/src/app/controllers/EpisodeController.php +++ b/src/app/controllers/EpisodeController.php @@ -71,7 +71,7 @@ class EpisodeController extends BaseController $this->episode_service->updateEpisode($episode_id, $title, $description, $image_url, $audio_url); - $response = array("success" => true, "redirect_url" => "/episode/$id", "status_message" => "Changes Saved."); + $response = array("success" => true, "redirect_url" => "/episode/$id", "status_message" => "Changes Saved"); http_response_code(ResponseHelper::HTTP_STATUS_OK); header('Content-Type: application/json'); @@ -82,7 +82,7 @@ class EpisodeController extends BaseController Middleware::checkIsAdmin(); $this->episode_service->deleteEpisode($id); - $response = array("success" => true, "redirect_url" => "/episode", "status_message" => "Episode Successfully Deleted."); + $response = array("success" => true, "redirect_url" => "/episode", "status_message" => "Episode Successfully Deleted"); http_response_code(ResponseHelper::HTTP_STATUS_OK); header('Content-Type: application/json'); @@ -135,7 +135,7 @@ class EpisodeController extends BaseController $this->episode_service->addEpisode($podcast_title, 1, $title, $description, 60, $image_file, $audio_file); - $response = array("success" => true, "redirect_url" => "/episode", "status_message" => "Episode Successfully Added."); + $response = array("success" => true, "redirect_url" => "/episode", "status_message" => "Episode Successfully Added"); http_response_code(ResponseHelper::HTTP_STATUS_OK); header('Content-Type: application/json'); diff --git a/src/app/controllers/PodcastController.php b/src/app/controllers/PodcastController.php index d326d5da6f3b0c0fcaf033cc1af91059f7c1720b..6b679deb658aedeb9215022913e9a92fd400e8ea 100644 --- a/src/app/controllers/PodcastController.php +++ b/src/app/controllers/PodcastController.php @@ -151,7 +151,7 @@ class PodcastController extends BaseController list($data['total_rows'], $data['podcasts']) = $this->podcast_service->getPodcastBySearch($q, $sort_method, $sort_key, $filter_names, $filter_categories, $page, PodcastController::MAX_PODCAST_PER_PAGE); - $data['is_ajax'] = true; + $data['is_ajax'] = false; $this->view('pages/podcast/index', $data); http_response_code(ResponseHelper::HTTP_STATUS_OK); diff --git a/src/app/controllers/RegisterController.php b/src/app/controllers/RegisterController.php index 2c37f31fe28716047671202bfe4f4cf92f554b19..a7e059518c2bdaecdbd5ca2aa4ec89bfdc765eee 100644 --- a/src/app/controllers/RegisterController.php +++ b/src/app/controllers/RegisterController.php @@ -28,7 +28,7 @@ class RegisterController extends BaseController { $userService->register($_POST['email'], $_POST['username'], $hashedPassword, $_POST['first_name'], $_POST['last_name']); - $response = array("success" => true, "redirect_url" => "/login", "status_message" => "Register Successful."); + $response = array("success" => true, "redirect_url" => "/login", "status_message" => "Register Successful"); // Set the Content-Type header to indicate JSON header('Content-Type: application/json'); diff --git a/src/app/models/Category.php b/src/app/models/Category.php index de080ef0c26954bf0a9a20a34b312548bf37375a..2ddae42554d7533794cf65986126e0285141ef2b 100644 --- a/src/app/models/Category.php +++ b/src/app/models/Category.php @@ -15,7 +15,7 @@ class Category { $result = $this->db->fetchAll(); if (!$result) { - throw new Exception("No category in database."); + throw new Exception("No category in database"); } return $result; @@ -29,7 +29,7 @@ class Category { $result = $this->db->fetch(); if ($this->db->rowCount() == 0) { - throw new Exception("Category with ID $id not found."); + throw new Exception("Category with ID $id not found"); } return $result; } @@ -42,7 +42,7 @@ class Category { $result = $this->db->fetch(); if ($this->db->rowCount() == 0) { - throw new Exception("Category with name $name not found."); + throw new Exception("Category with name $name not found"); } return $result; diff --git a/src/public/js/auth/register.js b/src/public/js/auth/register.js index f5704568955587b44da62f2d964d291eb82b3ef9..6522dd43a8a1b338f10eec81a1084d429614391a 100644 --- a/src/public/js/auth/register.js +++ b/src/public/js/auth/register.js @@ -168,7 +168,7 @@ const submitRegisterForm = async (e) => { xhr.onload = function () { const response = JSON.parse(xhr.responseText); - if (xhr.status === 200) { + if (xhr.status === 201) { if (response.success) { showNotificationSuccess(response.status_message); diff --git a/src/public/js/episode/media_player.js b/src/public/js/episode/media_player.js index 1c3d4100bf2ca2334176bece63ff7f431fd21a67..1b3fb547f15c7797837fe9fe725a84e9d1407af9 100644 --- a/src/public/js/episode/media_player.js +++ b/src/public/js/episode/media_player.js @@ -136,7 +136,7 @@ audioPlayer.addEventListener("timeupdate", function () { audioPlayer.addEventListener("error", function (e) { console.error("Error loading audio:", e.message); - showNotificationDanger("No Audio File Found."); + showNotificationDanger("No Audio File Found"); }); sliderSmall.addEventListener("input", function () { diff --git a/src/public/js/home/home.js b/src/public/js/home/home.js index b507bebbb457fbbd7239f59652008df6be4ca025..c23ad9f6875a52e909f143930fcbf85a4ed72725 100644 --- a/src/public/js/home/home.js +++ b/src/public/js/home/home.js @@ -72,7 +72,7 @@ window.onload = () => { }; xhrPodcast.onerror = function () { - showNotificationDanger("Request failed."); + showNotificationDanger("Request failed"); }; xhrPodcast.send();