shortenit/shortenit/models/objects.py
Elia el Lazkani 4c36f35492 fix(): Removes the timestamp from the API endpoint
The timestamp is generated by the database call, the value was mapped to
TTL. It is currently removed from the API, the TTL can be added later
when needed.
2024-12-25 15:32:00 +01:00

27 lines
1,020 B
Python

from datetime import datetime
from typing import List
from pydantic import AnyHttpUrl
from sqlalchemy import DateTime, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql import func
import shortenit.models.base as base
class Link(base.Base):
__tablename__ = "links"
id: Mapped[int] = mapped_column(primary_key=True, index=True, init=False)
data: Mapped[AnyHttpUrl] = mapped_column(String, index=True)
pointers: Mapped[List["Pointer"]] = relationship(back_populates="link")
timestamp: Mapped[datetime] = mapped_column(default=func.now())
class Pointer(base.Base):
__tablename__ = "pointers"
id: Mapped[int] = mapped_column(primary_key=True, index=True, init=False)
data: Mapped[str] = mapped_column(index=True)
ttl: Mapped[int]
link_id: Mapped[int] = mapped_column(ForeignKey("links.id"))
link: Mapped["Link"] = relationship(back_populates="pointers")
timestamp: Mapped[datetime] = mapped_column(default=func.now())