diff --git a/main.py b/main.py index 1a62d28..5a4e28c 100644 --- a/main.py +++ b/main.py @@ -135,6 +135,14 @@ async def update_secret(secret: Secret, current_user: dict = Depends(get_current return token +@app.delete('/secret') +async def delete_secret(secret: Secret, current_user: dict = Depends(get_current_user)): + """Deletes the secret with the given id""" + secret.user_id = current_user['id'] + # print(secret.model_dump()) + user_id, secret_id = queries.DELETE_SECRET(secret.model_dump()) + + @app.get('/secret') async def list_secret(current_user: dict = Depends(get_current_user)): """Returns the encrypted secrets of the user.""" diff --git a/queries.py b/queries.py index 9eb5546..5cd6a50 100644 --- a/queries.py +++ b/queries.py @@ -143,6 +143,19 @@ UPDATE_SECRET = DbQuery( rows='single' ) +DELETE_SECRET = DbQuery( + """ + DELETE from secrets + WHERE + user_id = :user_id + and id = :id + RETURNING user_id, id + """, + type='write', + returns=True, + rows='single' +) + GET_SECRETS = DbQuery( """ SELECT *