56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
from flask import Flask, jsonify, request
|
|
import uuid
|
|
|
|
app = Flask(__name__)
|
|
|
|
disciplines = {}
|
|
|
|
# вывод всех заказов
|
|
@app.route('/disciplines', methods=['GET'])
|
|
def get_disciplines():
|
|
return jsonify(list(disciplines.values()))
|
|
|
|
# получение заказа по uuid
|
|
@app.route('/disciplines/<uuid:discipline_uuid>', methods=['GET'])
|
|
def get_discipline(discipline_uuid):
|
|
discipline = disciplines.get(str(discipline_uuid))
|
|
if discipline:
|
|
return jsonify(discipline)
|
|
return jsonify({'error': 'Not found'}), 404
|
|
|
|
# добавление нового заказа
|
|
@app.route('/disciplines', methods=['POST'])
|
|
def create_discipline():
|
|
data = request.json
|
|
discipline_uuid = str(uuid.uuid4())
|
|
discipline = {
|
|
'uuid': discipline_uuid,
|
|
'number': data['number'],
|
|
'discipline': data['discipline'],
|
|
'teacher_uuid': data['teacher_uuid']
|
|
}
|
|
disciplines[discipline_uuid] = discipline
|
|
return jsonify(discipline), 201
|
|
|
|
# изменение заказа по uuid
|
|
@app.route('/disciplines/<uuid:discipline_uuid>', methods=['PUT'])
|
|
def update_discipline(discipline_uuid):
|
|
discipline = disciplines.get(str(discipline_uuid))
|
|
if not discipline:
|
|
return jsonify({'error': 'Not found'}), 404
|
|
data = request.json
|
|
discipline['number'] = data['number']
|
|
discipline['discipline'] = data['discipline']
|
|
discipline['teacher_uuid'] = data['teacher_uuid']
|
|
return jsonify(discipline)
|
|
|
|
# удаление заказа по uuid
|
|
@app.route('/disciplines/<uuid:discipline_uuid>', methods=['DELETE'])
|
|
def delete_discipline(discipline_uuid):
|
|
if str(discipline_uuid) in disciplines:
|
|
del disciplines[str(discipline_uuid)]
|
|
return '', 204
|
|
return jsonify({'error': 'Not found'}), 404
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5001) |