diff --git a/App/.idea/sqlDataSources.xml b/App/.idea/sqlDataSources.xml
new file mode 100644
index 0000000..b125209
--- /dev/null
+++ b/App/.idea/sqlDataSources.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/App/.idea/workspace.xml b/App/.idea/workspace.xml
index 3d10e82..b30117d 100644
--- a/App/.idea/workspace.xml
+++ b/App/.idea/workspace.xml
@@ -2,11 +2,11 @@
-
-
+
-
+
+
@@ -18,16 +18,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
@@ -35,42 +98,15 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -107,8 +143,9 @@
-
-
+
+
+
@@ -125,26 +162,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -154,10 +176,11 @@
-
+
+
-
+
@@ -230,27 +253,43 @@
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -331,18 +370,25 @@
-
+
-
-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
+
diff --git a/App/database/__init__.py b/App/database/__init__.py
index 6122e79..cb6eac2 100644
--- a/App/database/__init__.py
+++ b/App/database/__init__.py
@@ -1,3 +1,49 @@
-class DatabaseOperations:
- def __init__(self):
-
\ No newline at end of file
+from cassandra.cluster import Cluster
+from cassandra.auth import PlainTextAuthProvider
+
+
+# Singleton class
+class DatabaseOperations(object):
+ __instance = None
+
+ def __new__(cls, username: str, password: str):
+ if DatabaseOperations.__instance is None:
+ DatabaseOperations.__instance = object.__new__(cls)
+ auth_provider = PlainTextAuthProvider(username=username, password=password)
+ cluster = Cluster(auth_provider=auth_provider)
+ DatabaseOperations.__instance.__session = cluster.connect()
+ DatabaseOperations.__instance.__createTables()
+ return DatabaseOperations.__instance
+
+ def __createTables(self):
+ with open("../../Design/db_script.cql", "r") as sql_script:
+ queries = sql_script.read().splitlines()
+ for query in queries:
+ self.__session.execute(query)
+
+ def registerNewUser(self, user_id: int, username: str, name: str):
+ query = """INSERT INTO YouTubeMDApp.User(user_id, username, name) VALUES (%s, %s, %s);"""
+ self.__session.execute(query, (user_id, username, name))
+
+ def registerPreferences(self, user_id: int, audio_quality: str, audio_format: str, os: str,
+ should_ask_metadata: bool):
+ query = """
+ INSERT INTO YouTubeMDApp.preferences(audio_quality, audio_format, os, should_ask_metadata, user_id)
+ VALUES (%s, %s, %s, %s, %s);
+ """
+ self.__session.execute(query, (audio_quality, audio_format, os, should_ask_metadata, user_id))
+
+ def registerStatistics(self, user_id: int, lang: str, downloads: int, last_time_active):
+ query = """
+ INSERT INTO YouTubeMDApp.Statistics(lang, downloads, last_time_active, user_id) VALUES (%s, %s, %s, %s);
+ """
+ self.__session.execute(query, (lang, downloads, last_time_active, user_id))
+
+ def registerNewSong(self, file_id: str, video_id: str, audio_quality: int, audio_format: int, times_requested: int,
+ is_metadata_by_user: bool):
+ query = """
+ INSERT INTO YouTubeMDApp.music (file_id, video_id, audio_quality, audio_format, times_requested,
+ is_metadata_by_user) VALUES (%s, %s, %s, %s, %s, %s)
+ """
+ self.__session.execute(query, (file_id, video_id, audio_quality, audio_format, times_requested,
+ is_metadata_by_user))
diff --git a/App/db_script_pycharm.ddl b/App/db_script_pycharm.ddl
new file mode 100644
index 0000000..3c24d37
--- /dev/null
+++ b/App/db_script_pycharm.ddl
@@ -0,0 +1,10 @@
+CREATE KEYSPACE IF NOT EXISTS YouTubeMDApp WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
+USE YouTubeMDApp;
+CREATE TABLE IF NOT EXISTS history (user_id int NOT NULL, file_id varchar NOT NULL);
+CREATE TABLE IF NOT EXISTS metadata (title varchar, artist varchar, cover text, duration varchar, music_file_id varchar NOT NULL, PRIMARY KEY (music_file_id));
+CREATE TABLE IF NOT EXISTS music (file_id varchar NOT NULL,video_id varchar, audio_quality int, audio_format int, times_requested int, is_metadata_by_user boolean, PRIMARY KEY (file_id));
+CREATE TABLE IF NOT EXISTS playlist (playlist_id varchar NOT NULL, number_elements int, times_requested int, PRIMARY KEY (playlist_id));
+CREATE TABLE IF NOT EXISTS playlist_has_music (playlist_playlist_id varchar NOT NULL, music_file_id varchar NOT NULL);
+CREATE TABLE IF NOT EXISTS preferences (audio_quality varchar, audio_format varchar, os varchar, should_ask_metadata boolean, user_id int NOT NULL, PRIMARY KEY (user_id));
+CREATE TABLE IF NOT EXISTS "User" (user_id int NOT NULL, username varchar, name text, PRIMARY KEY (user_id));
+CREATE TABLE IF NOT EXISTS Statistics (lang varchar, downloads int, last_time_active datetime, user_id int NOT NULL, PRIMARY KEY(user_id));
\ No newline at end of file
diff --git a/App/requirements.txt b/App/requirements.txt
index 2861b8a..d948e9a 100644
--- a/App/requirements.txt
+++ b/App/requirements.txt
@@ -1,3 +1,4 @@
+cassandra-driver
telegram
pip
python-telegram-bot
diff --git a/Design/DB_STRUCTURE/db_script.cql b/Design/DB_STRUCTURE/db_script.cql
index 6310f30..3c24d37 100644
--- a/Design/DB_STRUCTURE/db_script.cql
+++ b/Design/DB_STRUCTURE/db_script.cql
@@ -1,55 +1,10 @@
-CREATE KEYSPACE IF NOT EXISTS YouTubeMDApp
- WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3}
-
-
-CREATE TABLE IF NOT EXISTS history (
- user_id int NOT NULL,
- file_id varchar NOT NULL
-);
-
-CREATE TABLE IF NOT EXISTS metadata (
- title varchar,
- artist varchar,
- cover text,
- duration varchar,
- music_file_id varchar NOT NULL,
- PRIMARY KEY (music_file_id)
-);
-
-CREATE TABLE IF NOT EXISTS music (
- file_id varchar NOT NULL,
- video_id varchar,
- audio_quality int,
- audio_format int,
- times_requested int,
- is_metadata_by_user boolean,
- PRIMARY KEY (file_id)
-);
-
-CREATE TABLE IF NOT EXISTS playlist (
- playlist_id varchar NOT NULL,
- number_elements int,
- times_requested int,
- PRIMARY KEY (playlist_id)
-);
-
-CREATE TABLE IF NOT EXISTS playlist_has_music (
- playlist_playlist_id varchar NOT NULL,
- music_file_id varchar NOT NULL
-);
-
-CREATE TABLE IF NOT EXISTS preferences (
- audio_quality varchar,
- audio_format varchar,
- os varchar,
- should_ask_metadata boolean,
- user_id int NOT NULL,
- PRIMARY KEY (user_id)
-);
-
-CREATE TABLE IF NOT EXISTS "User" (
- user_id int NOT NULL,
- username varchar,
- name text,
- PRIMARY KEY (user_id)
-);
\ No newline at end of file
+CREATE KEYSPACE IF NOT EXISTS YouTubeMDApp WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
+USE YouTubeMDApp;
+CREATE TABLE IF NOT EXISTS history (user_id int NOT NULL, file_id varchar NOT NULL);
+CREATE TABLE IF NOT EXISTS metadata (title varchar, artist varchar, cover text, duration varchar, music_file_id varchar NOT NULL, PRIMARY KEY (music_file_id));
+CREATE TABLE IF NOT EXISTS music (file_id varchar NOT NULL,video_id varchar, audio_quality int, audio_format int, times_requested int, is_metadata_by_user boolean, PRIMARY KEY (file_id));
+CREATE TABLE IF NOT EXISTS playlist (playlist_id varchar NOT NULL, number_elements int, times_requested int, PRIMARY KEY (playlist_id));
+CREATE TABLE IF NOT EXISTS playlist_has_music (playlist_playlist_id varchar NOT NULL, music_file_id varchar NOT NULL);
+CREATE TABLE IF NOT EXISTS preferences (audio_quality varchar, audio_format varchar, os varchar, should_ask_metadata boolean, user_id int NOT NULL, PRIMARY KEY (user_id));
+CREATE TABLE IF NOT EXISTS "User" (user_id int NOT NULL, username varchar, name text, PRIMARY KEY (user_id));
+CREATE TABLE IF NOT EXISTS Statistics (lang varchar, downloads int, last_time_active datetime, user_id int NOT NULL, PRIMARY KEY(user_id));
\ No newline at end of file