From f3d606ee7d1f3cf20f24fde82be9e16be52e5d56 Mon Sep 17 00:00:00 2001 From: Louis Gallet Date: Sun, 30 Jun 2024 23:55:59 +0200 Subject: [PATCH] feat: :sparkles: Possiblity to join a room --- main.py | 15 +++++++++------ templates/found.html | 3 +++ templates/index.html | 2 +- templates/search.html | 5 ++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 2a67d82..a7e0173 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ bootstrap = Bootstrap5(app) database = sqlite3.connect("database.db", check_same_thread=False) cursor = database.cursor() -cursor.execute("CREATE TABLE IF NOT EXISTS rooms (roomid TEXT PRIMARY KEY, spotify_id TEXT)") +cursor.execute("CREATE TABLE IF NOT EXISTS rooms (roomid TEXT PRIMARY KEY, spotify_id TEXT, playlist_name TEXT)") @app.route("/", methods=['GET', 'POST']) def main(): @@ -22,23 +22,26 @@ def main(): return render_template("index.html", response="Invalid room id", comment="A room ID should be composed of number and have a lenght of 8 characters", type="error", roomid=roomid) roomSearch = cursor.execute("SELECT * FROM rooms WHERE roomid = ?", (roomid,)).fetchone() if roomSearch: - return render_template("index.html", response="We found your collaborative playlist", comment="It's great news, click the button below to access it.", type="success", roomid=roomid) + return render_template("index.html", response="We found your collaborative playlist", comment="It is a great news, click the button below to access it.", type="success", roomid=roomid) else: - cursor.execute("INSERT INTO rooms (roomid, spotify_id) VALUES (?, ?)", (roomid, "test")) + cursor.execute("INSERT INTO rooms (roomid, spotify_id, playlist_name) VALUES (?, ?, ?)", (roomid, "test", "test")) database.commit() - return render_template("index.html", response="We couldn't find your collaborative playlist", comment="Please check the room id and try again or create one.", type="error", roomid=roomid) + return render_template("index.html", response="We could not find your collaborative playlist", comment="Please check the room id and try again or create one.", type="error", roomid=roomid) return render_template("index.html") @app.route('/search/', methods=['GET', 'POST']) def main_app(roomid): + if len(roomid) != 8 or not cursor.execute("SELECT * FROM rooms WHERE roomid = ?", (roomid,)).fetchone(): + return main() + playlistName = cursor.execute("SELECT playlist_name FROM rooms WHERE roomid = ?", (roomid,)).fetchone()[0] # handle the POST request if request.method == 'POST': search = request.form.get('search') result = searchSpotify(search) - return render_template("found.html", query=search, tracks=result, roomid=roomid) + return render_template("found.html", query=search, tracks=result, roomid=roomid, playlistName=playlistName) # otherwise handle the GET request - return render_template("search.html") + return render_template("search.html", roomid=roomid, playlistName=playlistName) @app.route('/add//', methods=['GET']) def add_to_playlist(roomid, trackid): diff --git a/templates/found.html b/templates/found.html index 9105705..4abb2f2 100644 --- a/templates/found.html +++ b/templates/found.html @@ -8,6 +8,9 @@
+

Welcome

+

Choose the music that will play tonight.

+

Info: You're in room: {{ roomid }} , the playlist is called: {{ playlistName }}

diff --git a/templates/index.html b/templates/index.html index 2d4920e..8f5ecf6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -43,7 +43,7 @@ title: "{{ response }}", text: "{{ comment }}", icon: "{{ type }}", - confirmButtonText: "Join another room", + confirmButtonText: "Let's get in!", }).then(function() { window.location = "/search/{{ roomid }}"; }) diff --git a/templates/search.html b/templates/search.html index 2777ac7..e702982 100644 --- a/templates/search.html +++ b/templates/search.html @@ -6,7 +6,10 @@ {{ bootstrap.load_css() }} -
+
+

Welcome

+

Choose the music that will play tonight.

+

Info: You're in room: {{ roomid }} , the playlist is called: {{ playlistName }}