sdacelo commited on
Commit
e538957
·
1 Parent(s): e1cda4b

update docs grouped

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -44,75 +44,79 @@ class Payment(BaseModel):
44
  payment_date: str
45
 
46
  # GET
47
-
48
- @app.get("/", summary="Accueil", description="Retourne un message de bienvenue à l'utilisateur.")
49
  def home():
50
  return {"Hello": "Cali"}
51
 
52
- @app.get("/customers/", response_model=List[Customer], summary="Obtenir tous les clients", description="Récupère une liste de tous les clients.")
 
53
  def get_customers():
54
  return efd.customers
55
 
56
- @app.get("/customer_id/{customer_id}", response_model=Customer, summary="Obtenir un client par ID", description="Retourne un client spécifique selon l'ID fourni.")
57
  def get_customer_by_id(customer_id: str):
58
  customer = next((c for c in efd.customers if c["customer_id"] == customer_id), None)
59
 
60
  if customer is None:
61
- raise HTTPException(status_code=404, detail="Client not found")
62
 
63
  return customer
64
 
65
- @app.get("/products/", response_model=List[Product], summary="Obtenir tous les produits", description="Retourne une liste de tous les produits.")
 
66
  def get_products():
67
  return efd.products
68
 
69
- @app.get("/sellers/", response_model=List[Seller], summary="Obtenir tous les vendeurs", description="Retourne une liste de tous les vendeurs.")
 
70
  def get_sellers():
71
  return efd.sellers
72
 
73
- @app.get("/orders/", response_model=List[Order], summary="Obtenir toutes les commandes", description="Retourne une liste de toutes les commandes passées.")
 
74
  def get_orders():
75
  return efd.orders
76
 
77
- @app.get("/payments/", response_model=List[Payment], summary="Obtenir tous les paiements", description="Retourne une liste de tous les paiements effectués.")
 
78
  def get_payments():
79
  return efd.payments
80
 
81
  # POST
82
- @app.post("/customers/", summary="Ajouter un client", description="Permet d'ajouter un nouveau client à la liste des clients.")
83
  def create_customer(customer: Customer):
84
  efd.customers.append(customer.model_dump())
85
- return {"message": "Client successfuly added !"}
86
 
87
- @app.post("/products/", summary="Ajouter un produit", description="Permet d'ajouter un nouveau produit à la liste des produits.")
88
  def create_product(product: Product):
89
  efd.products.append(product.model_dump())
90
  return {"message": "Product successfully added !"}
91
 
92
  # PUT
93
- @app.put("/customers/{customer_id}", summary="Mettre à jour un client", description="Permet de mettre à jour les informations d'un client en fonction de son ID.")
94
  def update_customer(customer_id: str, updated_customer: Customer):
95
  for customer in efd.customers:
96
  if customer["customer_id"] == customer_id:
97
  customer.update(updated_customer.model_dump())
98
- return {"message": "Client successfully updated !"}
99
- raise HTTPException(status_code=404, detail="Client not found")
100
 
101
- @app.put("/products/{product_id}", summary="Mettre à jour un produit", description="Permet de mettre à jour les informations d'un produit en fonction de son ID.")
102
  def update_product(product_id: str, updated_product: Product):
103
  for product in efd.products:
104
  if product["product_id"] == product_id:
105
  product.update(updated_product.model_dump())
106
  return {"message": "Product successfully updated !"}
107
- raise HTTPException(status_code=404, detail="Produit not found")
108
 
109
  # DELETE
110
- @app.delete("/customers/{customer_id}", summary="Supprimer un client", description="Permet de supprimer un client en fonction de son ID.")
111
  def delete_customer(customer_id: str):
112
  efd.customers = [c for c in efd.customers if c["customer_id"] != customer_id]
113
- return {"message": "Client successfully deleted !"}
114
 
115
- @app.delete("/products/{product_id}", summary="Supprimer un produit", description="Permet de supprimer un produit en fonction de son ID.")
116
  def delete_product(product_id: str):
117
  efd.products = [p for p in efd.products if p["product_id"] != product_id]
118
  return {"message": "Product successfully deleted !"}
 
44
  payment_date: str
45
 
46
  # GET
47
+ @app.get("/", summary="Home", description="Returns a welcome message to the user.")
 
48
  def home():
49
  return {"Hello": "Cali"}
50
 
51
+ # Grouped under 'Customers'
52
+ @app.get("/customers/", response_model=List[Customer], summary="Get all customers", description="Retrieves a list of all customers.", tags=["Customers"])
53
  def get_customers():
54
  return efd.customers
55
 
56
+ @app.get("/customer_id/{customer_id}", response_model=Customer, summary="Get a customer by ID", description="Returns a specific customer by the provided ID.", tags=["Customers"])
57
  def get_customer_by_id(customer_id: str):
58
  customer = next((c for c in efd.customers if c["customer_id"] == customer_id), None)
59
 
60
  if customer is None:
61
+ raise HTTPException(status_code=404, detail="Customer not found")
62
 
63
  return customer
64
 
65
+ # Grouped under 'Products'
66
+ @app.get("/products/", response_model=List[Product], summary="Get all products", description="Returns a list of all products.", tags=["Products"])
67
  def get_products():
68
  return efd.products
69
 
70
+ # Grouped under 'Sellers'
71
+ @app.get("/sellers/", response_model=List[Seller], summary="Get all sellers", description="Returns a list of all sellers.", tags=["Sellers"])
72
  def get_sellers():
73
  return efd.sellers
74
 
75
+ # Grouped under 'Orders'
76
+ @app.get("/orders/", response_model=List[Order], summary="Get all orders", description="Returns a list of all orders placed.", tags=["Orders"])
77
  def get_orders():
78
  return efd.orders
79
 
80
+ # Grouped under 'Payments'
81
+ @app.get("/payments/", response_model=List[Payment], summary="Get all payments", description="Returns a list of all payments made.", tags=["Payments"])
82
  def get_payments():
83
  return efd.payments
84
 
85
  # POST
86
+ @app.post("/customers/", summary="Add a customer", description="Allows you to add a new customer to the customers list.", tags=["Customers"])
87
  def create_customer(customer: Customer):
88
  efd.customers.append(customer.model_dump())
89
+ return {"message": "Customer successfully added !"}
90
 
91
+ @app.post("/products/", summary="Add a product", description="Allows you to add a new product to the products list.", tags=["Products"])
92
  def create_product(product: Product):
93
  efd.products.append(product.model_dump())
94
  return {"message": "Product successfully added !"}
95
 
96
  # PUT
97
+ @app.put("/customers/{customer_id}", summary="Update a customer", description="Allows you to update a customer's details by their ID.", tags=["Customers"])
98
  def update_customer(customer_id: str, updated_customer: Customer):
99
  for customer in efd.customers:
100
  if customer["customer_id"] == customer_id:
101
  customer.update(updated_customer.model_dump())
102
+ return {"message": "Customer successfully updated !"}
103
+ raise HTTPException(status_code=404, detail="Customer not found")
104
 
105
+ @app.put("/products/{product_id}", summary="Update a product", description="Allows you to update a product's details by its ID.", tags=["Products"])
106
  def update_product(product_id: str, updated_product: Product):
107
  for product in efd.products:
108
  if product["product_id"] == product_id:
109
  product.update(updated_product.model_dump())
110
  return {"message": "Product successfully updated !"}
111
+ raise HTTPException(status_code=404, detail="Product not found")
112
 
113
  # DELETE
114
+ @app.delete("/customers/{customer_id}", summary="Delete a customer", description="Allows you to delete a customer by their ID.", tags=["Customers"])
115
  def delete_customer(customer_id: str):
116
  efd.customers = [c for c in efd.customers if c["customer_id"] != customer_id]
117
+ return {"message": "Customer successfully deleted !"}
118
 
119
+ @app.delete("/products/{product_id}", summary="Delete a product", description="Allows you to delete a product by its ID.", tags=["Products"])
120
  def delete_product(product_id: str):
121
  efd.products = [p for p in efd.products if p["product_id"] != product_id]
122
  return {"message": "Product successfully deleted !"}