feat(chat): add random public_id and fix users blocked route
Some checks failed
CI / test (push) Failing after 20s

- add chats.public_id random identifier with migration 0011
- expose public_id in chat API payloads
- use chat public_id in message search UI label
- fix users router order so /users/blocked no longer conflicts with /users/{user_id}
This commit is contained in:
2026-03-08 02:34:24 +03:00
parent 34edf2bae5
commit 0b4bb19425
8 changed files with 73 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ from sqlalchemy import Boolean, DateTime, Enum as SAEnum, ForeignKey, String, Un
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database.base import Base
from app.utils.id_generator import generate_public_id
if TYPE_CHECKING:
from app.messages.models import Message
@@ -28,6 +29,7 @@ class Chat(Base):
__tablename__ = "chats"
id: Mapped[int] = mapped_column(primary_key=True, index=True)
public_id: Mapped[str] = mapped_column(String(24), unique=True, index=True, nullable=False, default=generate_public_id)
type: Mapped[ChatType] = mapped_column(SAEnum(ChatType), nullable=False, index=True)
title: Mapped[str | None] = mapped_column(String(255), nullable=True)
handle: Mapped[str | None] = mapped_column(String(64), nullable=True, unique=True, index=True)

View File

@@ -9,6 +9,7 @@ class ChatRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: int
public_id: str
type: ChatType
title: str | None = None
display_title: str | None = None

View File

@@ -66,6 +66,7 @@ async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat)
return ChatRead.model_validate(
{
"id": chat.id,
"public_id": chat.public_id,
"type": chat.type,
"title": chat.title,
"display_title": display_title,
@@ -375,6 +376,7 @@ async def discover_public_chats_for_user(db: AsyncSession, *, user_id: int, quer
ChatDiscoverRead.model_validate(
{
"id": chat.id,
"public_id": chat.public_id,
"type": chat.type,
"title": chat.title,
"handle": chat.handle,