diff --git a/endpoints/api/v1/endpoint.post.py b/endpoints/api/v1/endpoint.post.py new file mode 100644 index 0000000..e6c7cf2 --- /dev/null +++ b/endpoints/api/v1/endpoint.post.py @@ -0,0 +1,48 @@ +from fastapi import APIRouter, Depends, HTTPException +from core.database import fake_users_db +import uuid +import random +import string + +router = APIRouter() + +@router.post("/signup-codes") +async def generate_signup_codes( + count: int = 1, + length: int = 8, + prefix: str = "" +): + """Generate unique signup invitation codes""" + codes = [] + existing_codes = [user.get("signup_code") for user in fake_users_db.values()] + + for _ in range(count): + while True: + code = prefix + ''.join(random.choices( + string.ascii_uppercase + string.digits, + k=length + )) + if code not in existing_codes: + codes.append(code) + break + + # Store codes in database for future validation + batch_id = str(uuid.uuid4()) + for code in codes: + fake_users_db[f"signup_code_{code}"] = { + "code": code, + "batch_id": batch_id, + "used": False, + "created_at": "2024-01-01T00:00:00Z" # Demo timestamp + } + + return { + "message": f"Successfully generated {count} signup codes", + "batch_id": batch_id, + "codes": codes, + "metadata": { + "prefix": prefix, + "length": length, + "expires_in": "30 days" + } + } \ No newline at end of file