generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 21
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 #807 from hackforla/fastapi-conversion
Fastapi conversion
- Loading branch information
Showing
27 changed files
with
449 additions
and
640 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import APIRouter, status | ||
|
||
health_router = APIRouter() | ||
|
||
|
||
@health_router.get("/", status_code=status.HTTP_200_OK) | ||
def health(): | ||
return "UP" |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from .user_roles import UserRole | ||
from . import schemas | ||
from .user_repo import UserRepository | ||
|
||
from app.modules.deps import DbSessionDep | ||
|
||
from fastapi import APIRouter | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/") | ||
def get_hosts(db_session: DbSessionDep) -> list[schemas.User]: | ||
with db_session.begin(): | ||
user_repo = UserRepository(db_session) | ||
all_users = user_repo.get_users_with_role(UserRole.HOST) | ||
return all_users |
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
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
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,31 +1,63 @@ | ||
from typing import Annotated | ||
from fastapi import APIRouter, HTTPException, status, Depends | ||
|
||
from fastapi import Depends, APIRouter, HTTPException, Response, Security | ||
# from fastapi.responses import RedirectResponse | ||
|
||
# from app.modules.deps import ( | ||
# DbSessionDep, | ||
# CognitoIdpDep, | ||
# ) | ||
from app.modules.deps import DbSessionDep, get_form_1, get_form_2 | ||
|
||
router = APIRouter() | ||
|
||
|
||
# @router.post("/guest/") | ||
# def post_guest_intake_profile(body, guest: Depends(aim_guest)): | ||
# forms_repo = FormsRepository(DataAccessLayer.session()) | ||
|
||
# form_id = forms_repo.add_form(body) | ||
# form = forms_repo.get_form_json(form_id) | ||
# if form: | ||
# return form, 200 | ||
# return {}, 404 | ||
|
||
|
||
# @router.get("/guest/{form_id}") | ||
# def get_guest_intake_profile(form_id, guest: Depends(aim_guest)): | ||
# forms_repo = FormsRepository(DataAccessLayer.session()) | ||
|
||
# form = forms_repo.get_form_json(form_id) | ||
# if form: | ||
# return form, 200 | ||
# return f"Form with id {form_id} does not exist.", 404 | ||
@router.put("/responses/{user_id}", status_code=status.HTTP_501_NOT_IMPLEMENTED) | ||
def update_intake_profile_responses(user_id, body, db_session: DbSessionDep): | ||
pass | ||
# TODO: Implement update intake profile responses | ||
# with db_session.begin() as session: | ||
# user_repo = UserRepository(session) | ||
# forms_repo = FormsRepository(session) | ||
# user = user_repo.get_user(token_info['Username']) | ||
|
||
# form = forms_repo.get_form(form_id) | ||
# if not form: | ||
# return f"Form with id {form_id} does not exist.", 404 | ||
|
||
# valid_field_ids = form.get_field_ids() | ||
# for response in body: | ||
# response["user_id"] = user.id | ||
# if response["field_id"] not in valid_field_ids: | ||
# return f"Form {form_id} does not contain field id {response['field_id']}", 400 | ||
|
||
# forms_repo.add_user_responses(user.id, body) | ||
|
||
# return {}, 204 | ||
|
||
|
||
@router.get("/responses/{user_id}", status_code=status.HTTP_501_NOT_IMPLEMENTED) | ||
def get_intake_profile_responses(user_id, db_session: DbSessionDep): | ||
pass | ||
# TODO: Implement get Intake Profile responses | ||
# with db_session.begin() as session: | ||
# user_repo = UserRepository(session) | ||
# forms_repo = FormsRepository(session) | ||
|
||
# form = forms_repo.get_form_json(form_id) | ||
# if not form: | ||
# return f"Form with id {form_id} does not exist.", 404 | ||
|
||
# user = user_repo.get_user(token_info['Username']) | ||
# responses = forms_repo.get_user_responses(user.id, form_id) | ||
# if responses: | ||
# return responses, 200 | ||
# return [], 202 | ||
|
||
|
||
@router.get("/form/{profile_id}", status_code=status.HTTP_200_OK) | ||
def get_intake_profile_form(profile_id: int, | ||
profile_form_1: Annotated[str, Depends(get_form_1)], | ||
profile_form_2: Annotated[str, Depends(get_form_2)]): | ||
"""Get the Intake Profile form definition.""" | ||
if profile_id == 1: | ||
return profile_form_1 | ||
if profile_id == 2: | ||
return profile_form_2 | ||
|
||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, | ||
detail=f"Form with id {profile_id} does not exist.") |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.