34 lines
840 B
Python
34 lines
840 B
Python
from fastapi import FastAPI
|
|
from google.cloud import firestore
|
|
|
|
app = FastAPI()
|
|
db = firestore.Client.from_service_account_json('fastapi-firestore-filipriec-824499994d80.json')
|
|
|
|
|
|
@app.get("/products")
|
|
async def get_products():
|
|
docs = db.collection('somarina').stream()
|
|
|
|
result = []
|
|
for d in docs:
|
|
item = {
|
|
"id": d.id,
|
|
"title": d.to_dict().get("somarina_title", "Unknown"),
|
|
"value": d.to_dict().get("somarina_value", 0)
|
|
}
|
|
result.append(item)
|
|
|
|
return result
|
|
|
|
@app.get("/structure")
|
|
async def get_structure():
|
|
result = []
|
|
for col in db.collections():
|
|
for doc in col.stream():
|
|
result.append({
|
|
"collection": col.id,
|
|
"id": doc.id,
|
|
"data": doc.to_dict()
|
|
})
|
|
return result
|