fix: modification visuel du frontend au niveau du formulaire de contact pour qu'il s'armonise avec le css global.

fix : update du backend avec ajout de la suppression d'un projet.
This commit is contained in:
toine 2025-10-04 11:03:08 +02:00
parent ef1ba911d9
commit 542e00482b
9 changed files with 68 additions and 15 deletions

View file

@ -20,7 +20,7 @@ app.config["API_KEY"] = os.getenv("API_KEY")
@app.route('/')
def get_home():
return jsonify({
"return": "Welcome to API"
"return": f"Welcome to API."
})
app.register_blueprint(projects_bp)

View file

@ -45,4 +45,14 @@ def create_project():
data['id'] = new_id
added = add_entry(PROJECTS_FILE, data)
return jsonify(added), 201
return jsonify(added), 201
@projects_bp.route('/<project_id>', methods=['DELETE'])
def delete_project(project_id):
projects = load_data(PROJECTS_FILE)
project = next((p for p in projects if str(p.get('id')) == project_id), None)
if project:
deleted = delete_entry(PROJECTS_FILE, project_id)
return jsonify(deleted), 200
return jsonify({"error": "Project not found"}), 404

View file

@ -26,8 +26,16 @@ def update_entry(filename, entry_id, new_entry):
return new_entry
return None
def delete_entry(filename, entry_id):
data = load_json(filename)
new_data = [item for item in data if item.get('id') != entry_id]
save_json(filename, new_data)
return len(data) != len(new_data)
def delete_entry(filename, project_id):
# 1. Charger les données
with open(filename, "r", encoding="utf-8") as f:
projects = json.load(f)
# 2. Filtrer pour supprimer le projet avec l'ID donné
updated_projects = [p for p in projects if p.get('id') != int(project_id)]
# 3. Sauvegarder les données mises à jour
with open(filename, "w", encoding="utf-8") as f:
json.dump(updated_projects, f, indent=2, ensure_ascii=False)
return {"status": "success", "deleted_id": project_id}