-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
27 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def get_slug_in_metadata(metadata:list) ->list: | ||
""" | ||
Retrieves the value corresponding to the label 'Slug' from a list of metadata items. | ||
""" | ||
for item in metadata: | ||
for key,value in item["label"].items(): | ||
if value[0].lower() == "slug": | ||
return list(item["value"].values())[0] | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
from fastapi import HTTPException | ||
import logging | ||
from utils.metadata_slug import get_slug_in_metadata | ||
|
||
#config logger | ||
logging.basicConfig(level=logging.INFO,handlers=[logging.StreamHandler()]) | ||
logger = logging.getLogger(__name__) | ||
|
||
async def get_slug(repo,id): | ||
try: | ||
_metadata = await repo.get_slug(id) | ||
if _metadata is None or "value" not in _metadata[0] or "none" not in _metadata[0]["value"]: | ||
if _metadata is None : | ||
raise HTTPException(status_code=404, detail=f"Slug not found for the associated ID: {id}") | ||
slug = _metadata[0]["value"]["none"][0] | ||
slug = get_slug_in_metadata(_metadata)[0] | ||
return slug | ||
except Exception as e: | ||
logger.error(f"Failed to get the slug: {e}") | ||
raise HTTPException(status_code=404, detail=f"Slug not found for the associated ID: {id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters