diff --git a/backend/app.py b/backend/app.py index 0297c7b..99270b4 100644 --- a/backend/app.py +++ b/backend/app.py @@ -134,5 +134,86 @@ def index(): ''' + +# Blog posts data file +BLOG_DATA_FILE = os.path.join(DATA_DIR, 'blog_posts.json') + +def load_blog_posts(): + try: + if os.path.exists(BLOG_DATA_FILE): + with open(BLOG_DATA_FILE, 'r') as f: + return json.load(f) + except: + pass + return [] + +def save_blog_posts(posts): + with open(BLOG_DATA_FILE, 'w') as f: + json.dump(posts, f, indent=2) + +blog_posts = load_blog_posts() + +def get_next_blog_id(): + if not blog_posts: + return 1 + return max(p['id'] for p in blog_posts) + 1 + +@app.route('/api/blog-posts', methods=['GET']) +def get_blog_posts(): + return jsonify(blog_posts) + +@app.route('/api/blog-posts/', methods=['GET']) +def get_blog_post(post_id): + post = next((p for p in blog_posts if p['id'] == post_id), None) + if not post: + return jsonify({'error': 'Post not found'}), 404 + return jsonify(post) + +@app.route('/api/blog-posts', methods=['POST']) +def create_blog_post(): + data = request.get_json() + title = data.get('title') + if not title: + return jsonify({'error': 'Title required'}), 400 + new_post = { + 'id': get_next_blog_id(), + 'title': title, + 'content': data.get('content', ''), + 'journeyId': data.get('journeyId'), + 'image': data.get('image'), + 'created_at': datetime.now().isoformat() + } + blog_posts.append(new_post) + save_blog_posts(blog_posts) + return jsonify(new_post), 201 + +@app.route('/api/blog-posts/', methods=['PUT']) +def update_blog_post(post_id): + post = next((p for p in blog_posts if p['id'] == post_id), None) + if not post: + return jsonify({'error': 'Post not found'}), 404 + data = request.get_json() + if 'title' in data: + post['title'] = data['title'] + if 'content' in data: + post['content'] = data['content'] + if 'journeyId' in data: + post['journeyId'] = data['journeyId'] + if 'image' in data: + post['image'] = data['image'] + save_blog_posts(blog_posts) + return jsonify(post) + +@app.route('/api/blog-posts/', methods=['DELETE']) +def delete_blog_post(post_id): + global blog_posts + post = next((p for p in blog_posts if p['id'] == post_id), None) + if not post: + return jsonify({'error': 'Post not found'}), 404 + blog_posts = [p for p in blog_posts if p['id'] != post_id] + save_blog_posts(blog_posts) + return jsonify({'message': 'Post deleted'}) + + if __name__ == '__main__': app.run(debug=True, port=5000) \ No newline at end of file diff --git a/backend/data/blog_posts.json b/backend/data/blog_posts.json new file mode 100644 index 0000000..64c8603 --- /dev/null +++ b/backend/data/blog_posts.json @@ -0,0 +1,10 @@ +[ + { + "id": 1, + "title": "test", + "content": "sfsfsfsaf", + "journeyId": "1", + "image": null, + "created_at": "2026-03-27T19:49:49.410806" + } +] \ No newline at end of file diff --git a/blog-list.html b/blog-list.html new file mode 100644 index 0000000..6727027 --- /dev/null +++ b/blog-list.html @@ -0,0 +1,233 @@ + + + + + + Blog – Journey Mapper + + + + + + + + + + + + + + + + +
+
+

Blog Posts

+ New Post +
+
+ +
+
+ + + + \ No newline at end of file diff --git a/blog-post-edit.html b/blog-post-edit.html new file mode 100644 index 0000000..cc95d24 --- /dev/null +++ b/blog-post-edit.html @@ -0,0 +1,347 @@ + + + + + + Blog Post – Journey Mapper + + + + + + + + + + + + + + + + +
+
+

Edit Post

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
or
+ +
+
+
+ + + Cancel +
+
+
+
+ +
+ + + + \ No newline at end of file diff --git a/map-page.html b/map-page.html index 4af8e23..5fd2e73 100644 --- a/map-page.html +++ b/map-page.html @@ -532,7 +532,7 @@

Journey Mapper