Spaces:
Sleeping
Sleeping
Ajit Panday
commited on
Commit
·
c83ffdd
1
Parent(s):
8d78a08
Fix customer timestamps and add customer list endpoint
Browse files- app/models.py +2 -2
- main.py +15 -0
app/models.py
CHANGED
|
@@ -22,8 +22,8 @@ class Customer(Base):
|
|
| 22 |
api_key = Column(String(64), unique=True, nullable=False)
|
| 23 |
webhook_url = Column(String(255), nullable=True, default=None) # URL where call results will be sent
|
| 24 |
is_active = Column(Boolean, default=True)
|
| 25 |
-
created_at = Column(DateTime(timezone=True),
|
| 26 |
-
updated_at = Column(DateTime(timezone=True), onupdate=
|
| 27 |
|
| 28 |
def __repr__(self):
|
| 29 |
return f"<Customer {self.name}>"
|
|
|
|
| 22 |
api_key = Column(String(64), unique=True, nullable=False)
|
| 23 |
webhook_url = Column(String(255), nullable=True, default=None) # URL where call results will be sent
|
| 24 |
is_active = Column(Boolean, default=True)
|
| 25 |
+
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
| 26 |
+
updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 27 |
|
| 28 |
def __repr__(self):
|
| 29 |
return f"<Customer {self.name}>"
|
main.py
CHANGED
|
@@ -310,6 +310,21 @@ async def health_check():
|
|
| 310 |
"""Health check endpoint"""
|
| 311 |
return {"status": "healthy"}
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
if __name__ == "__main__":
|
| 314 |
import uvicorn
|
| 315 |
host = os.getenv("HOST", "0.0.0.0")
|
|
|
|
| 310 |
"""Health check endpoint"""
|
| 311 |
return {"status": "healthy"}
|
| 312 |
|
| 313 |
+
@app.get("/api/v1/customers", response_model=List[Customer])
|
| 314 |
+
async def list_customers(
|
| 315 |
+
db: Session = Depends(get_db),
|
| 316 |
+
current_admin: str = Depends(get_current_admin)
|
| 317 |
+
):
|
| 318 |
+
"""List all customers"""
|
| 319 |
+
try:
|
| 320 |
+
customers = db.query(CustomerModel).all()
|
| 321 |
+
return customers
|
| 322 |
+
except Exception as e:
|
| 323 |
+
raise HTTPException(
|
| 324 |
+
status_code=500,
|
| 325 |
+
detail=f"Failed to list customers: {str(e)}"
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
if __name__ == "__main__":
|
| 329 |
import uvicorn
|
| 330 |
host = os.getenv("HOST", "0.0.0.0")
|