Ajout bricoloc
parent
d7987cc4e7
commit
2feadab0fe
@ -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
|
||||
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="Flask">
|
||||
<option name="enabled" value="true" />
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
|
||||
</component>
|
||||
</module>
|
||||
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/bricoloc.iml" filepath="$PROJECT_DIR$/.idea/bricoloc.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@ -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()
|
||||
@ -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)
|
||||
@ -0,0 +1,2 @@
|
||||
pika
|
||||
flask
|
||||
@ -0,0 +1,55 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Location d'Équipements</title>
|
||||
<style>
|
||||
body { max-width: 600px; margin: 0 auto; padding: 20px; }
|
||||
.form-group { margin-bottom: 15px; }
|
||||
label { display: block; margin-bottom: 5px; }
|
||||
input, select { width: 100%; padding: 8px; }
|
||||
button { padding: 10px 20px; background-color: #4CAF50; color: white; border: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Location d'Équipements de Bricolage</h1>
|
||||
<form id="rentalForm" onsubmit="submitForm(event)">
|
||||
<div class="form-group">
|
||||
<label for="product">Produit:</label>
|
||||
<select id="product" name="product" required>
|
||||
<option value="perceuse">Perceuse</option>
|
||||
<option value="tondeuse">Tondeuse</option>
|
||||
<option value="ponceuse">Ponceuse</option>
|
||||
<option value="scie">Scie</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="quantity">Quantité:</label>
|
||||
<input type="number" id="quantity" name="quantity" min="1" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="customer_name">Nom du client:</label>
|
||||
<input type="text" id="customer_name" name="customer_name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="duration">Durée de location (jours):</label>
|
||||
<input type="number" id="duration" name="duration" min="1" required>
|
||||
</div>
|
||||
<button type="submit">Soumettre</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function submitForm(event) {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(document.getElementById('rentalForm'));
|
||||
|
||||
fetch('/submit_rental', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => alert(data.message))
|
||||
.catch(error => alert('Erreur: ' + error));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue