Skip to content

Commit

Permalink
changing add/update user endpoint to be a post
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Feb 6, 2025
1 parent d41652b commit 819aba0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
15 changes: 14 additions & 1 deletion src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import shutil
from enum import Enum

from pydantic import BaseModel

class GenUtils:
"""
Expand Down Expand Up @@ -97,6 +97,19 @@ def cleanup(file_path: str):
shutil.rmtree(file_path)


class UserInfo(BaseModel):
"""
Class for user info
"""
email: str
password_hash: str | None = None
role_id: str | None = None
details: str | None = None
maxele_style: str | None = None
maxwvel_style: str | None = None
swan_style: str | None = None


class BrandName(str, Enum):
"""
Class enum for k8s job type names
Expand Down
35 changes: 12 additions & 23 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from src.common.pg_impl import PGImplementation
from src.common.security import Security
from src.common.bearer import JWTBearer
from src.common.utils import GenUtils, BrandName
from src.common.utils import GenUtils, BrandName, UserInfo
from src.common.geopoints import GeoPoint

# set the app version
Expand Down Expand Up @@ -910,13 +910,10 @@ async def verify_user(email: Union[str, None] = Query(default=None)):
return JSONResponse(content=ret_val, status_code=status_code, media_type="application/json")


@APP.get('/update_user', dependencies=[Depends(JWTBearer(security))], status_code=200, response_model=None)
async def update_user(email: Union[str, None] = Query(default=None), password_hash: Union[str, None] = Query(default=None),
role_id: Union[str, None] = Query(default=None), details: Union[str, None] = Query(default=None),
maxele_style: Union[str, None] = Query(default=None), maxwvel_style: Union[str, None] = Query(default=None),
swan_style: Union[str, None] = Query(default=None)):
@APP.post('/update_user', dependencies=[Depends(JWTBearer(security))], status_code=200, response_model=None)
async def update_user(user_info: UserInfo):
"""
update_user the user profile.
update the user profile.
<br/>&nbsp;&nbsp;&nbsp;The user's email address
<br/>&nbsp;&nbsp;&nbsp;The user's password (hashed)
<br/>&nbsp;&nbsp;&nbsp;The user's role
Expand All @@ -936,13 +933,10 @@ async def update_user(email: Union[str, None] = Query(default=None), password_ha
# init the kwargs variable
kwargs: dict = {}

# create the param list
params: list = ['email', 'password_hash', 'role_id', 'details', 'maxele_style', 'maxwvel_style', 'swan_style']

# loop through the SP params passed in
for param in params:
for a, v in user_info.__dict__.items():
# add this parm to the list
kwargs.update({param: 'null' if not locals()[param] else f"'{locals()[param]}'"})
kwargs.update({a: 'null' if v is None else f"'{v}'"})

# try to make the call for records
ret_val: dict = db_info.update_user(**kwargs)
Expand All @@ -968,11 +962,8 @@ async def update_user(email: Union[str, None] = Query(default=None), password_ha
return JSONResponse(content=ret_val, status_code=status_code, media_type="application/json")


@APP.get('/add_user', dependencies=[Depends(JWTBearer(security))], status_code=200, response_model=None)
async def add_user(email: Union[str, None] = Query(default=None), password_hash: Union[str, None] = Query(default=None),
role_id: Union[str, None] = Query(default=None), details: Union[str, None] = Query(default=None),
maxele_style: Union[str, None] = Query(default=None), maxwvel_style: Union[str, None] = Query(default=None),
swan_style: Union[str, None] = Query(default=None)):
@APP.post('/add_user', dependencies=[Depends(JWTBearer(security))], status_code=200, response_model=None)
async def add_user(user_info: UserInfo):
"""
Adds the user and their profile.
<br/>&nbsp;&nbsp;&nbsp;The user's email address
Expand All @@ -990,16 +981,14 @@ async def add_user(email: Union[str, None] = Query(default=None), password_hash:
ret_val: dict = {}
status_code: int = 200

try: # init the kwargs variable
try:
# init the kwargs variable
kwargs: dict = {}

# create the param list
params: list = ['email', 'password_hash', 'role_id', 'details', 'maxele_style', 'maxwvel_style', 'swan_style']

# loop through the SP params passed in
for param in params:
for a, v in user_info.__dict__.items():
# add this parm to the list
kwargs.update({param: 'null' if not locals()[param] else f"'{locals()[param]}'"})
kwargs.update({a: 'null' if v is None else f"'{v}'"})

# try to make the call for records
ret_val: dict = db_info.add_user(**kwargs)
Expand Down

0 comments on commit 819aba0

Please sign in to comment.