From 2c415e0bde7bf5a9c3b824fa4be30cf9d6596e3d Mon Sep 17 00:00:00 2001 From: Krrupa <“sudonthineni@gmail.com@users.noreply.github.com”> Date: Thu, 26 May 2022 12:41:03 +0530 Subject: [PATCH] removed loop --- app/routers/organizations.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/routers/organizations.py b/app/routers/organizations.py index 39854ad9..94f5268c 100644 --- a/app/routers/organizations.py +++ b/app/routers/organizations.py @@ -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 @@ -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)