added delete method and query

This commit is contained in:
Gourav Kumar 2024-07-14 17:40:07 +05:30
parent 6a1429614b
commit a089ffa884
2 changed files with 21 additions and 0 deletions

View File

@ -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."""

View File

@ -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 *