-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-without-auth.py
29 lines (26 loc) · 925 Bytes
/
api-without-auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from flask import jsonify
from database import get_database_connection
from decorators import headers_required
from factory import create_order_service, create_user_service
from user import PartialUser
from app import create_app
import logging
app = create_app()
@app.route("/")
def list_users():
logging.info("Listing Users with orders")
service = create_user_service(get_database_connection())
users = service.get_users()
return jsonify({
"users": [user.model_dump() for user in users]
})
@app.route("/orders")
@headers_required
def list_orders(authenticated_user):
logging.info(f"Listing orders for User {authenticated_user.name}")
service = create_order_service(get_database_connection())
orders = service.get_orders_by_user(authenticated_user)
return jsonify({
"user": f"{authenticated_user.name}",
"orders": [order.model_dump() for order in orders]
})