chore(fastapi): refactor webhook id to use different format
This commit is contained in:
parent
c143fdf964
commit
60f030abf7
2 changed files with 6 additions and 4 deletions
|
|
@ -1,5 +1,4 @@
|
|||
from typing import Optional
|
||||
import uuid
|
||||
from fastapi import APIRouter, Body, Depends, HTTPException, Path
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
|
@ -18,7 +17,7 @@ class SubscribeToWebhookRequest(BaseModel):
|
|||
|
||||
|
||||
class SubscribeToWebhookResponse(BaseModel):
|
||||
id: uuid.UUID
|
||||
id: str
|
||||
|
||||
|
||||
@API_V1_WEBHOOK_ROUTER.post(
|
||||
|
|
@ -40,7 +39,7 @@ async def subscribe_to_webhook(
|
|||
|
||||
@API_V1_WEBHOOK_ROUTER.delete("/unsubscribe", status_code=204)
|
||||
async def unsubscribe_to_webhook(
|
||||
id: uuid.UUID = Body(
|
||||
id: str = Body(
|
||||
embed=True, description="The ID of the webhook subscription to unsubscribe from"
|
||||
),
|
||||
sql_session: AsyncSession = Depends(get_async_session),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import secrets
|
||||
from typing import Optional
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
|
@ -9,7 +10,9 @@ from utils.datetime_utils import get_current_utc_datetime
|
|||
class WebhookSubscription(SQLModel, table=True):
|
||||
__tablename__ = "webhook_subscriptions"
|
||||
|
||||
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
||||
id: str = Field(
|
||||
default_factory=lambda: f"webhook-{secrets.token_hex(32)}", primary_key=True
|
||||
)
|
||||
created_at: datetime = Field(
|
||||
sa_column=Column(DateTime(timezone=True), nullable=False),
|
||||
default_factory=get_current_utc_datetime,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue