added delete method and query
This commit is contained in:
parent
6a1429614b
commit
a089ffa884
8
main.py
8
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."""
|
||||
|
13
queries.py
13
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 *
|
||||
|
Loading…
Reference in New Issue
Block a user