Urejevalnik pesmi (feature #1)
This commit is contained in:
@@ -154,6 +154,62 @@ def search_songs():
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
|
||||
@app.route('/api/get_song_details', methods=['GET'])
|
||||
def get_song_details():
|
||||
"""Vrne podrobnosti trenutno naložene pesmi"""
|
||||
if _projector_app is None:
|
||||
return jsonify({'status': 'error', 'message': 'Aplikacija ni inicijalizirana'})
|
||||
|
||||
if not _projector_app.song_number_last:
|
||||
return jsonify({'status': 'error', 'message': 'Nobena pesem ni naložena'})
|
||||
|
||||
try:
|
||||
song_id = int(_projector_app.song_number_last)
|
||||
_projector_app.cursor.execute("SELECT id, title, lyrics FROM songs WHERE id=?", (song_id,))
|
||||
result = _projector_app.cursor.fetchone()
|
||||
if result:
|
||||
return jsonify({
|
||||
'status': 'ok',
|
||||
'song': {
|
||||
'id': result[0],
|
||||
'title': result[1],
|
||||
'lyrics': result[2]
|
||||
}
|
||||
})
|
||||
else:
|
||||
return jsonify({'status': 'error', 'message': 'Pesem ni najdena v bazi'})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'error', 'message': str(e)})
|
||||
|
||||
|
||||
@app.route('/api/update_song', methods=['POST'])
|
||||
def update_song():
|
||||
"""Posodobi naslov in besedilo pesmi"""
|
||||
if _projector_app is None:
|
||||
return jsonify({'status': 'error', 'message': 'Aplikacija ni inicijalizirana'})
|
||||
|
||||
data = request.get_json()
|
||||
song_id = data.get('id')
|
||||
title = data.get('title', '').strip()
|
||||
lyrics = data.get('lyrics', '').strip()
|
||||
|
||||
if not song_id or not title or not lyrics:
|
||||
return jsonify({'status': 'error', 'message': 'Manjkajoči podatki'})
|
||||
|
||||
try:
|
||||
_projector_app.cursor.execute("UPDATE songs SET title=?, lyrics=? WHERE id=?", (title, lyrics, song_id))
|
||||
_projector_app.conn.commit()
|
||||
|
||||
# Osvežimo trenutno pesem, če je to ta, ki smo jo pravkar uredili
|
||||
if str(_projector_app.song_number_last) == str(song_id):
|
||||
_projector_app.song_number = str(song_id)
|
||||
_projector_app.load_song()
|
||||
|
||||
return jsonify({'status': 'ok'})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'error', 'message': str(e)})
|
||||
|
||||
|
||||
def run_server(host='127.0.0.1', port=5000):
|
||||
"""Zaženi Flask server"""
|
||||
app.run(host=host, port=port, debug=False, use_reloader=False, threaded=True)
|
||||
|
||||
Reference in New Issue
Block a user