feat: create model

This commit is contained in:
Timothy J. Baek
2024-05-24 22:21:57 -07:00
parent ca3108a54d
commit dac9634242
13 changed files with 286 additions and 951 deletions

View File

@@ -166,7 +166,9 @@ class ModelsTable:
model = Model.get(Model.id == id)
return ModelModel(**model_to_dict(model))
except:
except Exception as e:
print(e)
return None
def delete_model_by_id(self, id: str) -> bool:

View File

@@ -28,16 +28,24 @@ async def get_models(user=Depends(get_verified_user)):
@router.post("/add", response_model=Optional[ModelModel])
async def add_new_model(form_data: ModelForm, user=Depends(get_admin_user)):
model = Models.insert_new_model(form_data, user.id)
if model:
return model
else:
async def add_new_model(
request: Request, form_data: ModelForm, user=Depends(get_admin_user)
):
if form_data.id in request.app.state.MODELS:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.DEFAULT(),
detail=ERROR_MESSAGES.MODEL_ID_TAKEN,
)
else:
model = Models.insert_new_model(form_data, user.id)
if model:
return model
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.DEFAULT(),
)
############################