DAS_2023_1/antonov_dmitry_lab_3/service_b/app.py
DmitriyAntonov 23dfef9856 старт
2023-11-12 12:05:59 +04:00

39 lines
986 B
Python

from flask import Flask, jsonify, request
app = Flask(__name__)
# хранение данных сущности B
entity_b_data = []
@app.route('/entity_b', methods=['GET'])
def get_entity_b():
return jsonify(entity_b_data)
@app.route('/entity_b', methods=['POST'])
def create_entity_b():
new_entity = request.json
entity_b_data.append(new_entity)
return jsonify(new_entity), 201
@app.route('/entity_b/<int:id>', methods=['PUT'])
def update_entity_b(id):
for entity in entity_b_data:
if entity['id'] == id:
entity.update(request.json)
return jsonify(entity), 200
return jsonify({'error': 'Entity not found'}), 404
@app.route('/entity_b/<int:id>', methods=['DELETE'])
def delete_entity_b(id):
global entity_b_data
entity_b_data = [entity for entity in entity_b_data if entity['id'] != id]
return jsonify({'message': 'Entity deleted'}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)