From 4c36f35492acbb03320d4ce8d81f617cd39e478c Mon Sep 17 00:00:00 2001 From: Elia el Lazkani Date: Wed, 25 Dec 2024 15:32:00 +0100 Subject: [PATCH] fix(#10): 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. --- frontend/src/components/URLShortener/URLShortener.tsx | 4 +--- shortenit/main.py | 2 +- shortenit/models/objects.py | 2 +- shortenit/web.py | 3 +-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/URLShortener/URLShortener.tsx b/frontend/src/components/URLShortener/URLShortener.tsx index 98397d0..f956873 100644 --- a/frontend/src/components/URLShortener/URLShortener.tsx +++ b/frontend/src/components/URLShortener/URLShortener.tsx @@ -28,13 +28,11 @@ export default function URLShortener() { } try { - const timestamp = Math.floor(Date.now() / 1000); // Send the POST request to the backend await axios .post("http://127.0.0.1:8000/api/v1/shorten", { - url: url, - timestamp: timestamp, + url: url }) .then((response) => { if (response) { diff --git a/shortenit/main.py b/shortenit/main.py index f9d90b1..7b8bc2b 100644 --- a/shortenit/main.py +++ b/shortenit/main.py @@ -51,7 +51,7 @@ def main() -> typing.NoReturn: sys.exit(0) -def shorten_it(config: dict, session: Session, data: str, ttl: int): +def shorten_it(config: dict, session: Session, data: str, ttl: int = 0): shortener = Shortener(session, config) identifier = shortener.generate_uuid() if identifier: diff --git a/shortenit/models/objects.py b/shortenit/models/objects.py index e7fc16c..716c107 100644 --- a/shortenit/models/objects.py +++ b/shortenit/models/objects.py @@ -21,7 +21,7 @@ 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[str] + 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()) diff --git a/shortenit/web.py b/shortenit/web.py index c9fdcac..f4920ab 100644 --- a/shortenit/web.py +++ b/shortenit/web.py @@ -57,7 +57,7 @@ class SiteHandler: self.shorten_url = shorten_url self.lenghten_url = lenghten_url self.shortenit_load_format = trafaret.Dict( - {trafaret.Key("url"): trafaret.URL, trafaret.Key("timestamp"): trafaret.Int} + {trafaret.Key("url"): trafaret.URL} ) def _get_server_config(self): @@ -87,7 +87,6 @@ class SiteHandler: self.configuration.get("Shortener", None), self.database, data["url"], - data["timestamp"], ) short_url = self._get_url(stub) except KeyError as e: