-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from avantifellows/portal-backend-to-db-servic…
…e-changes Changes for moving logics from portal-backend to db-service
- Loading branch information
Showing
2 changed files
with
44 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,23 @@ | ||
from fastapi import APIRouter, HTTPException | ||
import requests | ||
from settings import settings | ||
from routes import group_session_db_url, group_db_url, auth_group_db_url | ||
from routes import group_session_db_url | ||
from helpers import db_request_token, is_response_valid, is_response_empty | ||
|
||
|
||
router = APIRouter(prefix="/session-group", tags=["Session-Group"]) | ||
|
||
|
||
def get_auth_group_details(auth_group_id): | ||
auth_group_response = requests.get( | ||
auth_group_db_url, params={"id": auth_group_id}, headers=db_request_token() | ||
) | ||
if is_response_valid( | ||
auth_group_response, "Auth group API could not fetch the data!" | ||
): | ||
auth_group_data = is_response_empty( | ||
auth_group_response.json()[0], True, "Auth group record does not exist!" | ||
) | ||
return auth_group_data | ||
|
||
|
||
def get_batch_from_group(group_id): | ||
response = requests.get( | ||
group_db_url, params={"id": group_id}, headers=db_request_token() | ||
) | ||
if is_response_valid(response, "Group API could not fetch the data!"): | ||
batch_data = is_response_empty( | ||
response.json()[0], True, "Group record does not exist!" | ||
) | ||
if batch_data: | ||
return get_auth_group_details(batch_data["child_id"]["auth_group_id"]) | ||
|
||
|
||
@router.get("/{session_id}") | ||
def get_group_for_session(session_id: str): | ||
response = requests.get( | ||
group_session_db_url, | ||
group_session_db_url + "/session-auth-group", | ||
params={"session_id": session_id}, | ||
headers=db_request_token(), | ||
) | ||
if is_response_valid(response, "Group Session API could not fetch the data!"): | ||
group_session_data = is_response_empty( | ||
response.json()[0], True, "Group Session record does not exist!" | ||
auth_group_data = is_response_empty( | ||
response.json(), True, "Auth group data does not exist!" | ||
) | ||
if group_session_data: | ||
return get_batch_from_group(group_session_data["group_id"]) | ||
if auth_group_data: | ||
return auth_group_data |