Improvements upon api and database api
This commit is contained in:
parent
34ae028698
commit
dc6ba8f462
4 changed files with 95 additions and 7 deletions
61
app.py
61
app.py
|
|
@ -13,6 +13,7 @@ import uvicorn
|
|||
|
||||
from dba import *
|
||||
from models import (
|
||||
AssetUpdateDefinition,
|
||||
AuthModel,
|
||||
ColumnConditionCompat,
|
||||
CreateUserDefinition,
|
||||
|
|
@ -719,6 +720,58 @@ async def itemsDelete(
|
|||
return OkResponse()
|
||||
|
||||
|
||||
@app.get(
|
||||
"/assets",
|
||||
name="Get assets",
|
||||
responses={
|
||||
200: {
|
||||
"model": list[Asset],
|
||||
"description": "List of assets",
|
||||
},
|
||||
403: {
|
||||
"model": ErrorResponse,
|
||||
"description": "Requesting this endpoint requires admin access token",
|
||||
},
|
||||
},
|
||||
)
|
||||
async def getAssets(access_token: str | None = Header(default=None)):
|
||||
is_admin = check_if_admin_access_token(connector, access_token)
|
||||
if not is_admin:
|
||||
return JSONResponse(
|
||||
ErrorResponse(error="Not allowed").dict(),
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
|
||||
assets = get_assets(connector)
|
||||
return assets
|
||||
|
||||
|
||||
@app.get(
|
||||
"/assets/tags",
|
||||
name="Get assets tags",
|
||||
responses={
|
||||
200: {
|
||||
"model": list[str],
|
||||
"description": "List of assets tags",
|
||||
},
|
||||
403: {
|
||||
"model": ErrorResponse,
|
||||
"description": "Requesting this endpoint requires admin access token",
|
||||
},
|
||||
},
|
||||
)
|
||||
async def getAssetsTags(access_token: str | None = Header(default=None)):
|
||||
is_admin = check_if_admin_access_token(connector, access_token)
|
||||
if not is_admin:
|
||||
return JSONResponse(
|
||||
ErrorResponse(error="Not allowed").dict(),
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
|
||||
assets = get_assets_tags(connector)
|
||||
return assets
|
||||
|
||||
|
||||
@app.get(
|
||||
"/assets/{fid}",
|
||||
name="Get asset",
|
||||
|
|
@ -824,11 +877,11 @@ async def createAsset(
|
|||
|
||||
@app.post(
|
||||
"/assets/{asset_id}/*",
|
||||
name="Update asset description",
|
||||
name="Update asset description and tags",
|
||||
responses={
|
||||
200: {
|
||||
"model": OkResponse,
|
||||
"description": "Asset description updated successfully",
|
||||
"description": "Asset description and tags updated successfully",
|
||||
},
|
||||
400: {
|
||||
"model": ErrorResponse,
|
||||
|
|
@ -846,7 +899,7 @@ async def createAsset(
|
|||
)
|
||||
async def updateAsset(
|
||||
asset_id: int,
|
||||
asset_description: str,
|
||||
asset_update: AssetUpdateDefinition,
|
||||
access_token: str | None = Header(default=None),
|
||||
):
|
||||
user = get_user_by_access_token(connector, access_token)
|
||||
|
|
@ -856,7 +909,7 @@ async def updateAsset(
|
|||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
|
||||
ok, e = update_asset(connector, asset_id, asset_description)
|
||||
ok, e = update_asset(connector, asset_id, asset_update.description, asset_update.tags)
|
||||
if not ok:
|
||||
if e:
|
||||
return JSONResponse(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue