-
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.
Implemented support for api create/get feature requests by slug or id.
- Loading branch information
Showing
11 changed files
with
120 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from typing import Dict | ||
|
||
from app.services.features import feature_with_slug_exists, generate_unique_feature_slug | ||
|
||
|
||
async def validate_feature_slug(body: Dict[str, str]) -> Dict[str, str]: | ||
|
||
slug_in = body.get("slug", "").strip() | ||
if not slug_in: | ||
body["slug"] = await generate_unique_feature_slug(title=body["title"]) | ||
elif await feature_with_slug_exists(slug_in): | ||
raise ValueError(f"Feature with slug '{slug_in}' already exists") | ||
return body |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
from typing import Optional | ||
|
||
from app.crud.base import CRUDBase | ||
from app.models.features import Feature | ||
from app.schemas.features import FeatureCreate, FeatureUpdate | ||
|
||
|
||
class CRUDFeature(CRUDBase[Feature, FeatureCreate, FeatureUpdate]): | ||
pass | ||
async def get_by_slug(self, slug: str) -> Optional[Feature]: | ||
return await self.model.filter(slug=slug).first() | ||
|
||
|
||
crud_feature = CRUDFeature(Feature) |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
from app.models.features import Feature | ||
from slugify import slugify # type: ignore | ||
|
||
|
||
def feature_with_slug_exists(slug: str) -> bool: | ||
# TODO Check for slug uniqueness | ||
return False | ||
async def feature_with_slug_exists(slug: str) -> bool: | ||
return bool(await Feature.get_or_none(slug=slug)) | ||
|
||
|
||
def generate_unique_feature_slug(title: str) -> str: | ||
async def generate_unique_feature_slug(title: str) -> str: | ||
slugified_title = slugify(title, max_length=50, word_boundary=True) | ||
if not feature_with_slug_exists(slugified_title): | ||
if not await feature_with_slug_exists(slugified_title): | ||
return slugified_title | ||
for index in range(99): | ||
numbered_slugified_title = f"{slugified_title[:47]}-{index}" | ||
if not feature_with_slug_exists(numbered_slugified_title): | ||
if not await feature_with_slug_exists(numbered_slugified_title): | ||
return numbered_slugified_title | ||
raise ValueError("Error generating slug") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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