Skip to content

Commit

Permalink
Improving API Call Dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
philipokiokio committed Jan 17, 2023
1 parent 0b44a22 commit 012a8bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/projects/mixer_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def project_rate_header(project: Project = Depends(mixer_header)):
project.id
)

if pj_rate_for_last_hour.count >= 50:
if pj_rate_for_last_hour.count >= 2:
raise HTTPException(
detail="This Project has reached it maximum call for the hour, check back in an hour",
detail=f"This Project has reached it maximum call for the hour: {pj_rate_for_last_hour.count}, check back in an hour",
status_code=status.HTTP_400_BAD_REQUEST,
)

Expand Down
6 changes: 3 additions & 3 deletions src/projects/project_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@project_router.post(
"{org_slug}/create/",
"/{org_slug}/create/",
status_code=status.HTTP_201_CREATED,
response_model=schemas.MessageProjectResp,
)
Expand Down Expand Up @@ -42,7 +42,7 @@ def get_projects(org_slug: str, current_user: dict = Depends(get_current_user)):
def fetch_project(
org_slug: str, slug: str, current_user: dict = Depends(get_current_user)
):
resp = project_service.get_project(slug, org_slug)
resp = project_service.get_project(org_slug, slug)
return resp


Expand All @@ -68,7 +68,7 @@ def update_project(
current_user: dict = Depends(get_current_user),
):

resp = project_service.update_project(slug, update_project)
resp = project_service.update_project(org_slug, slug, update_project)

return resp

Expand Down
8 changes: 5 additions & 3 deletions src/projects/project_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ def project_does_not_exist(self):
status_code=status.HTTP_404_NOT_FOUND,
)

def orm_call(project: Project):
def orm_call(self, project: Project):
project_ = jsonable_encoder(project)

if project.org:
project_["org"] = project.org
if project.creator:
project_["creator"] = project.creator

project_["count_per_hour"] = project.pj_rate
return project_

def org_check(self, org_slug):
Expand All @@ -38,6 +40,7 @@ def org_check(self, org_slug):
raise HTTPException(
detail="Org does not Exist", status_code=status.HTTP_404_NOT_FOUND
)
return org_check

def create_project(
self,
Expand All @@ -49,7 +52,6 @@ def create_project(
org_check = self.org_check(org_slug)

create_project_ = create_project.dict()

project_check = self.project_repo.get_project_name(
create_project.name, org_check.id
)
Expand Down Expand Up @@ -106,7 +108,7 @@ def get_projects(self, org_slug) -> schemas.MessageListProjectResp:

projects_ = []
for project in projects:
projects_.append(project)
projects_.append(self.orm_call(project))

return {
"message": "Projects retrieved Successful",
Expand Down
6 changes: 6 additions & 0 deletions src/projects/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ class User(AbstractModel):
last_name: str


class PjRate(AbstractModel):
count: int


class ProjectResp(ProjectCreate):
id: int
slug: str
api_key: str
org: Optional[Org]
is_premium: bool
creator: Optional[User]
count_per_hour: List[PjRate]


class ProjectUpdate(AbstractModel):
Expand Down

0 comments on commit 012a8bf

Please sign in to comment.