70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
|
# backend/app.py
|
||
|
from flask import Flask, render_template, jsonify, request, send_from_directory
|
||
|
from core.directory_handler import select_directory
|
||
|
from pathlib import Path
|
||
|
from core.profile_manager import ProfileManager
|
||
|
|
||
|
app = Flask(__name__,
|
||
|
template_folder='../frontend/templates',
|
||
|
static_folder='../frontend/static')
|
||
|
|
||
|
# Initialize profile manager
|
||
|
profile_manager = ProfileManager(Path('../data'))
|
||
|
|
||
|
@app.route('/')
|
||
|
def index():
|
||
|
"""Render main page"""
|
||
|
return render_template('index.html')
|
||
|
|
||
|
@app.route('/api/profiles', methods=['GET'])
|
||
|
def get_profiles():
|
||
|
"""Get all profiles"""
|
||
|
return jsonify(profile_manager.get_all_profiles())
|
||
|
|
||
|
@app.route('/api/profiles/<profile_id>', methods=['GET'])
|
||
|
def get_profile(profile_id):
|
||
|
"""Get specific profile"""
|
||
|
profile = profile_manager.get_profile(profile_id)
|
||
|
if profile:
|
||
|
return jsonify(profile)
|
||
|
return jsonify({"error": "Profile not found"}), 404
|
||
|
|
||
|
@app.route('/api/profiles', methods=['POST'])
|
||
|
def create_profile():
|
||
|
"""Create new profile"""
|
||
|
profile_data = request.json
|
||
|
try:
|
||
|
profile = profile_manager.create_profile(profile_data)
|
||
|
return jsonify(profile)
|
||
|
except Exception as e:
|
||
|
return jsonify({"error": str(e)}), 400
|
||
|
|
||
|
@app.route('/api/profiles/<profile_id>', methods=['PUT'])
|
||
|
def update_profile(profile_id):
|
||
|
"""Update existing profile"""
|
||
|
profile_data = request.json
|
||
|
try:
|
||
|
profile = profile_manager.update_profile(profile_id, profile_data)
|
||
|
return jsonify(profile)
|
||
|
except Exception as e:
|
||
|
return jsonify({"error": str(e)}), 400
|
||
|
|
||
|
@app.route('/api/profiles/<profile_id>', methods=['DELETE'])
|
||
|
def delete_profile(profile_id):
|
||
|
"""Delete profile"""
|
||
|
try:
|
||
|
profile_manager.delete_profile(profile_id)
|
||
|
return jsonify({"status": "success"})
|
||
|
except Exception as e:
|
||
|
return jsonify({"error": str(e)}), 400
|
||
|
|
||
|
@app.route('/api/select-directory', methods=['GET'])
|
||
|
def handle_select_directory():
|
||
|
"""Handle directory selection"""
|
||
|
result = select_directory()
|
||
|
if "error" in result:
|
||
|
return jsonify(result), 400
|
||
|
return jsonify(result)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app.run(debug=True, port=5000)
|