Skip to content

Commit

Permalink
removed loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Krrupa committed May 26, 2022
1 parent d6a1f41 commit 2c415e0
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions app/routers/organizations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi import APIRouter, status, HTTPException
from app.settings import Settings
from settings import Settings
from database import client
from models import Organization, OrganizationResponse
import secrets
Expand All @@ -22,23 +22,18 @@ def generate_random_string():
@router.post("/", response_model=OrganizationResponse)
async def create_organization(organization: Organization):
organization = jsonable_encoder(organization)
number_of_loops = 3

while number_of_loops > 0:
# create an API key
key = generate_random_string()

# create an API key
key = generate_random_string()

# check if API key exists
if (client.quiz.organization.find_one({"key": key})) is None:
organization["key"] = key
new_organization = client.quiz.organization.insert_one(organization)
created_organization = client.quiz.organization.find_one(
{"_id": new_organization.inserted_id}
)
return created_organization

number_of_loops -= 1
# check if API key exists
if (client.quiz.organization.find_one({"key": key})) is None:
organization["key"] = key
new_organization = client.quiz.organization.insert_one(organization)
created_organization = client.quiz.organization.find_one(
{"_id": new_organization.inserted_id}
)
return created_organization


@router.get("/authenticate/{api_key}", response_model=OrganizationResponse)
Expand Down

0 comments on commit 2c415e0

Please sign in to comment.