feat: Update endpoint endpoint
This commit is contained in:
parent
9149f9f438
commit
9acd1953ac
@ -0,0 +1,25 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
class TimezoneRequest(BaseModel):
|
||||||
|
timezone: str
|
||||||
|
|
||||||
|
class TimezoneResponse(BaseModel):
|
||||||
|
current_time: str
|
||||||
|
|
||||||
|
@router.post("/timezone", response_model=TimezoneResponse)
|
||||||
|
async def get_current_time(request: TimezoneRequest):
|
||||||
|
"""
|
||||||
|
Get the current time for a given timezone
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
tz = timezone(request.timezone)
|
||||||
|
except ValueError as e:
|
||||||
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
|
||||||
|
current_time = datetime.now(tz).isoformat()
|
||||||
|
return {"current_time": current_time}
|
Loading…
x
Reference in New Issue
Block a user