ajout de CRUD total pour toute les routes
This commit is contained in:
parent
fec74d9f83
commit
da45beba93
5 changed files with 166 additions and 25 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from flask import Blueprint, jsonify, request, current_app
|
||||
from utils.data_loader import load_data
|
||||
from utils.json_crud import load_json, save_json, add_entry, delete_entry, update_entry
|
||||
from utils.json_crud import load_json, save_json
|
||||
from models.cv_model import CVModel
|
||||
import os
|
||||
|
||||
|
|
@ -15,27 +15,53 @@ def get_cv():
|
|||
return jsonify(cv)
|
||||
|
||||
@cv_bp.route('/', methods=['POST'])
|
||||
def update_cv():
|
||||
#key = request.headers.get('x-api-key')
|
||||
#if key != current_app.config['API_KEY']:
|
||||
# return jsonify({
|
||||
# "error": "Unauthorized"
|
||||
# }), 401
|
||||
def create_or_replace_cv():
|
||||
key = request.headers.get('x-api-key')
|
||||
if key != current_app.config['API_KEY']:
|
||||
return jsonify({"error": "Unauthorized"}), 401
|
||||
|
||||
data = request.json
|
||||
data = request.json or {}
|
||||
new_entry = CVModel(data).to_dict()
|
||||
cv = [new_entry]
|
||||
save_json(CV_FILE, cv)
|
||||
return jsonify(new_entry), 201
|
||||
|
||||
@cv_bp.route('/', methods=['PUT', 'PATCH'])
|
||||
def update_cv():
|
||||
key = request.headers.get('x-api-key')
|
||||
if key != current_app.config['API_KEY']:
|
||||
return jsonify({"error": "Unauthorized"}), 401
|
||||
|
||||
current_list = load_json(CV_FILE) or []
|
||||
current = current_list[0] if current_list else {}
|
||||
payload = request.json or {}
|
||||
updated = {**current, **payload}
|
||||
|
||||
new_entry = CVModel(updated).to_dict()
|
||||
save_json(CV_FILE, [new_entry])
|
||||
return jsonify(new_entry), 200
|
||||
|
||||
@cv_bp.route('/', methods=['DELETE'])
|
||||
def delete_cv():
|
||||
key = request.headers.get('x-api-key')
|
||||
if key != current_app.config['API_KEY']:
|
||||
return jsonify({"error": "Unauthorized"}), 401
|
||||
|
||||
save_json(CV_FILE, [])
|
||||
return jsonify({"status": "success"}), 200
|
||||
|
||||
@cv_bp.route('/skills/', methods=['GET'])
|
||||
def get_skills():
|
||||
cv = load_data('cv.json')
|
||||
if not cv:
|
||||
return jsonify([])
|
||||
skills = cv[0].get('my_skills')
|
||||
return jsonify(skills)
|
||||
|
||||
@cv_bp.route('/about/', methods=['GET'])
|
||||
def get_about():
|
||||
cv = load_data('cv.json')
|
||||
if not cv:
|
||||
return jsonify("")
|
||||
about = cv[0].get('about_text')
|
||||
return jsonify(about)
|
||||
Loading…
Add table
Add a link
Reference in a new issue