Skip to content

Commit

Permalink
Merge pull request #8 from link-shrink/implement-milestones
Browse files Browse the repository at this point in the history
milestones
  • Loading branch information
akbarjorayev authored Feb 5, 2025
2 parents 25d4331 + 6f17e07 commit 3cce7a6
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions firestoreDB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .save_firestore import save_firestore
from .get_firestore import get_firestore
from .get_firestore_where import get_firestore_where
from .increase_firestore import increase_firestore
7 changes: 7 additions & 0 deletions firestoreDB/increase_firestore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from firebase_admin import firestore
from .init_firestore import db


async def increase_firestore(field: str, quantity: int):
doc_ref = db.collection("milestones").document("links")
doc_ref.update({field: firestore.Increment(quantity)})
5 changes: 5 additions & 0 deletions link/post_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import firestoreDB
import validator
import milestones


async def post_data(original_link: str, link_id: str):
Expand All @@ -8,5 +9,9 @@ async def post_data(original_link: str, link_id: str):

data = {"link_id": link_id, "original_link": original_link}

await milestones.increase_quantity()
await milestones.increase_short_length(f"keskn.uz/{link_id}")
await milestones.increase_original_length(original_link)
await firestoreDB.save_firestore("links", link_id, data)

return data
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_response(data):
return {
"ok": True,
"link_id": link_id,
"short_link": f"keskn.uz/{link_id}",
"short_link": f"https://keskn.uz/{link_id}",
"original_link": data["original_link"],
}

Expand All @@ -31,7 +31,7 @@ async def get_link(link_id):
if len(data) == 0:
return {"ok": False, "message": "Link not found"}

return data[0]
return get_response(data[0])


class CreateLink(BaseModel):
Expand Down
3 changes: 3 additions & 0 deletions milestones/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .quantity import increase_quantity
from .short_length import increase_short_length
from .original_length import increase_original_length
5 changes: 5 additions & 0 deletions milestones/original_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import firestoreDB


async def increase_original_length(original_link: str) -> None:
await firestoreDB.increase_firestore("original_length", len(original_link))
5 changes: 5 additions & 0 deletions milestones/quantity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import firestoreDB


async def increase_quantity() -> None:
await firestoreDB.increase_firestore("quantity", 1)
5 changes: 5 additions & 0 deletions milestones/short_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import firestoreDB


async def increase_short_length(short_link: str) -> None:
await firestoreDB.increase_firestore("short_length", len(short_link))

0 comments on commit 3cce7a6

Please sign in to comment.