feat: ✨ Possiblity to join a room
This commit is contained in:
parent
788b81402b
commit
f3d606ee7d
15
main.py
15
main.py
@ -12,7 +12,7 @@ bootstrap = Bootstrap5(app)
|
|||||||
|
|
||||||
database = sqlite3.connect("database.db", check_same_thread=False)
|
database = sqlite3.connect("database.db", check_same_thread=False)
|
||||||
cursor = database.cursor()
|
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'])
|
@app.route("/", methods=['GET', 'POST'])
|
||||||
def main():
|
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)
|
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()
|
roomSearch = cursor.execute("SELECT * FROM rooms WHERE roomid = ?", (roomid,)).fetchone()
|
||||||
if roomSearch:
|
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:
|
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()
|
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")
|
return render_template("index.html")
|
||||||
|
|
||||||
@app.route('/search/<string:roomid>', methods=['GET', 'POST'])
|
@app.route('/search/<string:roomid>', methods=['GET', 'POST'])
|
||||||
def main_app(roomid):
|
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
|
# handle the POST request
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
search = request.form.get('search')
|
search = request.form.get('search')
|
||||||
result = searchSpotify(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
|
# otherwise handle the GET request
|
||||||
return render_template("search.html")
|
return render_template("search.html", roomid=roomid, playlistName=playlistName)
|
||||||
|
|
||||||
@app.route('/add/<string:roomid>/<string:trackid>', methods=['GET'])
|
@app.route('/add/<string:roomid>/<string:trackid>', methods=['GET'])
|
||||||
def add_to_playlist(roomid, trackid):
|
def add_to_playlist(roomid, trackid):
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container text-center">
|
<div class="container text-center">
|
||||||
|
<h2>Welcome</h2>
|
||||||
|
<p>Choose the music that will play tonight.</p>
|
||||||
|
<p>Info: You're in room: <b>{{ roomid }} </b>, the playlist is called: <b>{{ playlistName }} </b></p>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="form-inline text-center">
|
<div class="form-inline text-center">
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
title: "{{ response }}",
|
title: "{{ response }}",
|
||||||
text: "{{ comment }}",
|
text: "{{ comment }}",
|
||||||
icon: "{{ type }}",
|
icon: "{{ type }}",
|
||||||
confirmButtonText: "Join another room",
|
confirmButtonText: "Let's get in!",
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
window.location = "/search/{{ roomid }}";
|
window.location = "/search/{{ roomid }}";
|
||||||
})
|
})
|
||||||
|
@ -6,7 +6,10 @@
|
|||||||
{{ bootstrap.load_css() }}
|
{{ bootstrap.load_css() }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container text-center">
|
||||||
|
<h2>Welcome</h2>
|
||||||
|
<p>Choose the music that will play tonight.</p>
|
||||||
|
<p>Info: You're in room: <b>{{ roomid }} </b>, the playlist is called: <b>{{ playlistName }} </b></p>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="form-inline text-center">
|
<div class="form-inline text-center">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user