-
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.
Merge pull request #62 from ral-facilities/endpoint-for-editing-catal…
…ogue-category-#3 Partially edit catalogue categories
- Loading branch information
Showing
22 changed files
with
2,266 additions
and
330 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
46 changes: 46 additions & 0 deletions
46
inventory_management_system_api/models/custom_object_id_data_types.py
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,46 @@ | ||
""" | ||
Module for defining custom `ObjectId` data type classes used by Pydantic models. | ||
""" | ||
from bson import ObjectId | ||
|
||
from inventory_management_system_api.core.custom_object_id import CustomObjectId | ||
|
||
|
||
class CustomObjectIdField(ObjectId): | ||
""" | ||
Custom data type for handling MongoDB ObjectId validation. | ||
""" | ||
|
||
@classmethod | ||
def __get_validators__(cls): | ||
yield cls.validate | ||
|
||
@classmethod | ||
def validate(cls, value: str) -> CustomObjectId: | ||
""" | ||
Validate if the string value is a valid `ObjectId`. | ||
:param value: The string value to be validated. | ||
:return: The validated `ObjectId`. | ||
""" | ||
return CustomObjectId(value) | ||
|
||
|
||
class StringObjectIdField(str): | ||
""" | ||
Custom data type for handling MongoDB ObjectId as string. | ||
""" | ||
|
||
@classmethod | ||
def __get_validators__(cls): | ||
yield cls.validate | ||
|
||
@classmethod | ||
def validate(cls, value: ObjectId) -> str: | ||
""" | ||
Convert the `ObjectId` value to string. | ||
:param value: The `ObjectId` value to be converted. | ||
:return: The converted `ObjectId` as a string. | ||
""" | ||
return str(value) |
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
Oops, something went wrong.