diff --git a/app.py b/app.py
index cfba79e..d04dff6 100644
--- a/app.py
+++ b/app.py
@@ -40,15 +40,14 @@ def admin_post():
action = request.form.get('action')
album_id = request.form.get('album_id')
- if not action or not album_id:
- if not album_id:
- album_id = 1
- #return jsonify({'error': 'Missing required fields'}), 400
+ if not action:
+ return redirect('/admin')
try:
- album_id = int(album_id)
+ if album_id is not None:
+ album_id = int(album_id)
except ValueError:
- return jsonify({'error': 'Invalid album ID'}), 400
+ return redirect('/admin')
db = next(get_db())
@@ -58,7 +57,7 @@ def admin_post():
year = request.form.get('year')
if not title or not artist or not year:
- return jsonify({'error': 'All fields are required'}), 400
+ return redirect('/admin')
album = db.query(Album).filter(Album.id == album_id).first()
if album:
@@ -66,18 +65,20 @@ def admin_post():
album.artist = artist
album.year = int(year)
db.commit()
- return jsonify({'message': 'Album updated successfully', 'album': album.to_dict()})
+ return redirect('/admin')
else:
- return jsonify({'error': 'Album not found'}), 404
+ return redirect('/admin')
+
+
elif action == 'delete':
album = db.query(Album).filter(Album.id == album_id).first()
if album:
db.delete(album)
db.commit()
- return jsonify({'message': 'Album deleted successfully'})
+ return redirect('/admin')
else:
- return jsonify({'error': 'Album not found'}), 404
+ return redirect('/admin')
elif action == 'add_album':
title = request.form.get('title')
@@ -85,15 +86,16 @@ def admin_post():
year = request.form.get('year')
if not title or not artist or not year:
- return jsonify({'error': 'All fields are required'}), 400
+ return redirect('/admin')
new_album = Album(title=title, artist=artist, year=int(year))
db.add(new_album)
db.commit()
- return jsonify({'message': 'Album added successfully', 'album': new_album.to_dict()})
+ return redirect('/admin')
else:
- return jsonify({'error': 'Invalid action'}), 400
+ return redirect('/admin')
+
if __name__ == '__main__':
app.run(debug=True)
diff --git a/templates/admin.html b/templates/admin.html
index b261738..1d2b133 100644
--- a/templates/admin.html
+++ b/templates/admin.html
@@ -5,10 +5,13 @@
Admin
+ Music Album Catalog Admin Page
+
+
Albums
-
+
| ID |
Title |
diff --git a/templates/index.html b/templates/index.html
index 2dcfb09..021dd4a 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -5,35 +5,24 @@
Music Album Catalog
-
+
Albums
-
+
+
+
+ | Album |
+ Artist |
+ Year |
+
{% for album in albums %}
- - {{ album.title }} by {{ album.artist }} ({{ album.year }})
+
+ | {{ album.title }} |
+ {{ album.artist }} |
+ ({{ album.year }}) |
+
{% endfor %}
-
+
diff --git a/templates/style.css b/templates/style.css
new file mode 100644
index 0000000..2d43dca
--- /dev/null
+++ b/templates/style.css
@@ -0,0 +1,19 @@
+body {
+ font-family: Arial, sans-serif;
+ margin: 20px;
+ }
+
+h1 {
+ color: #333;
+ }
+
+tr {
+ border-top: 1px solid #ddd;
+ border-bottom: 1px solid #ddd;
+ border-left: 1px solid #ddd;
+ border-right: 1px solid #ddd;
+}
+tr:first-child tr {
+ background-color: #D6EEEE;
+}
+tr:hover {background-color: #D6EEEE;}
\ No newline at end of file