diff --git a/bricoloc/.idea/.gitignore b/bricoloc/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/bricoloc/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/bricoloc/.idea/bricoloc.iml b/bricoloc/.idea/bricoloc.iml new file mode 100644 index 0000000..459e8b3 --- /dev/null +++ b/bricoloc/.idea/bricoloc.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/bricoloc/.idea/inspectionProfiles/profiles_settings.xml b/bricoloc/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/bricoloc/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/bricoloc/.idea/misc.xml b/bricoloc/.idea/misc.xml new file mode 100644 index 0000000..db8786c --- /dev/null +++ b/bricoloc/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/bricoloc/.idea/modules.xml b/bricoloc/.idea/modules.xml new file mode 100644 index 0000000..215f31c --- /dev/null +++ b/bricoloc/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bricoloc/inventory-service.py b/bricoloc/inventory-service.py new file mode 100644 index 0000000..332ff42 --- /dev/null +++ b/bricoloc/inventory-service.py @@ -0,0 +1,38 @@ +# inventory_service.py +import pika +import json + +# RabbitMQ setup +RABBITMQ_HOST = 'localhost' +connection = pika.BlockingConnection(pika.ConnectionParameters(RABBITMQ_HOST)) +channel = connection.channel() +channel.queue_declare(queue='rental_requests') + +# Database simulation +inventory = { + 'perceuse': 5, + 'tondeuse': 3, + 'ponceuse': 4, + 'scie': 2 +} + +def process_rental(ch, method, properties, body): + rental_data = json.loads(body) + product = rental_data['product'] + quantity = rental_data['quantity'] + + if product in inventory and inventory[product] >= quantity: + inventory[product] -= quantity + print(f"Déstockage effectué: {quantity} {product}(s)") + print(f"Stock restant - {product}: {inventory[product]}") + else: + print(f"Erreur: Stock insuffisant pour {product}") + +channel.basic_consume( + queue='rental_requests', + on_message_callback=process_rental, + auto_ack=True +) + +print("Service de gestion des stocks démarré. En attente de demandes...") +channel.start_consuming() diff --git a/bricoloc/rental-request-service.py b/bricoloc/rental-request-service.py new file mode 100644 index 0000000..8e2b867 --- /dev/null +++ b/bricoloc/rental-request-service.py @@ -0,0 +1,45 @@ +# request_service.py +from flask import Flask, render_template, request, jsonify +import pika +import json + +app = Flask(__name__) + +# RabbitMQ setup +RABBITMQ_HOST = 'localhost' +connection = pika.BlockingConnection(pika.ConnectionParameters(RABBITMQ_HOST)) +channel = connection.channel() +channel.queue_declare(queue='rental_requests') + +# Database simulation +inventory = { + 'perceuse': 5, + 'tondeuse': 3, + 'ponceuse': 4, + 'scie': 2 +} + +@app.route('/') +def home(): + return render_template('rental_form.html') + +@app.route('/submit_rental', methods=['POST']) +def submit_rental(): + rental_data = { + 'product': request.form['product'], + 'quantity': int(request.form['quantity']), + 'customer_name': request.form['customer_name'], + 'rental_duration': int(request.form['duration']) + } + + # Send message to inventory service + channel.basic_publish( + exchange='', + routing_key='rental_requests', + body=json.dumps(rental_data) + ) + + return jsonify({"message": "Demande de location envoyée avec succès!"}) + +if __name__ == '__main__': + app.run(port=5000) diff --git a/bricoloc/requirements.txt b/bricoloc/requirements.txt new file mode 100644 index 0000000..a15c365 --- /dev/null +++ b/bricoloc/requirements.txt @@ -0,0 +1,2 @@ +pika +flask diff --git a/bricoloc/templates/rental_form.html b/bricoloc/templates/rental_form.html new file mode 100644 index 0000000..c356e4e --- /dev/null +++ b/bricoloc/templates/rental_form.html @@ -0,0 +1,55 @@ + + + + Location d'Équipements + + + +

Location d'Équipements de Bricolage

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + + +