def _make_response_data_model( name: str, fields: Dict[str, Raw], skip_none: Optional[bool] = False ) -> Tuple[Model, Model]: model = Model(f"{name}Data", fields) return model, Model( f"{name}Response", {"message": String(), "data": Nested(model, skip_none=skip_none)} )
"info_url": String, # "created_at_iso8601": "2019-09-20T04:47:50", "created_at_iso8601": DateTime(attribute="created_at"), # "created_at_rfc822": "Fri, 20 Sep 2019 04:47:50 -0000", "created_at_rfc822": DateTime(attribute="created_at", dt_format="rfc822"), # "deadline": "09/20/19 10:59:59 PM UTC-08:00", "deadline": String(attribute="deadline_str"), "deadline_passed": Boolean, # "time_remaining": "16 hours 41 minutes 42 seconds", "time_remaining": String(attribute="time_remaining_str"), # "owner": { # "email": "*****@*****.**", # "public_id": "475807a4-8497-4c5c-8d70-109b429bb4ef", # } "owner": Nested(widget_owner_model), # "link": "/api/v1/widgets/first_widget", "link": Url("api.widget"), }, ) pagination_links_model = Model( "Nav Links", { "self": String, "prev": String, "next": String, "first": String, "last": String }, )
"recipeId": _recipe_id, } recipe_with_id_model = Model("RecipeWithId", _recipe_with_id) # All fields present in DynamoDB _db_recipe = { **_recipe_with_id, "categories": List(Integer), "createTime": _create_time, "updateTime": _update_time, } db_recipe_data, _db_recipe_response_model = _make_response_data_model( "DbRecipe", _db_recipe, skip_none=True) _recipe_update = { "add": Nested(recipe_model), "remove": Nested(recipe_model), "update": Nested(recipe_model), } recipe_update_model = Model("RecipeUpdate", _recipe_update) _batch_recipe_delete = {"recipeIds": List(_recipe_id)} batch_recipe_delete_model = Model("BatchRecipeDelete", _batch_recipe_delete) _batch_recipe_update = { "recipeIdToUpdate1": Nested(recipe_update_model), "recipeIdToUpdate2": Nested(recipe_update_model), } batch_recipe_update_model = Model("BatchRecipeUpdate", _batch_recipe_update) _batch_recipe_add = {"recipes": List(Nested(recipe_model))}
from flask_restx.fields import Integer, List, Nested, String from models import db_category_data from models.common import _make_response_data_model from models.requests.recipes import ( _db_recipe, _db_recipe_response_model as db_recipe_response_model, db_recipe_data, recipe_model, ) recipe_update_response_data, recipe_update_response_model = _make_response_data_model( "UpdateRecipe", { "existingCategories": List(Integer), "newCategories": List(Nested(db_category_data, skip_none=True)), "categoryFailedAdds": List(String), "imgSrc": String(), }, skip_none=True, ) recipe_add_response_data, recipe_add_response_model = _make_response_data_model( "AddRecipe", { **_db_recipe, "existingCategories": List(Integer), "newCategories": List(Nested(db_category_data, skip_none=True)), "categoryFailedAdds": List(String), }, skip_none=True,
category_model = Model("Category", _category) _category_with_id = { **_category, "categoryId": _category_id, } category_with_id_model = Model("CategoryWithId", _category_with_id) # All fields present in DynamoDB _db_category = { **_category_with_id, "createTime": _create_time, "updateTime": _update_time, } db_category_data, _db_category_response_model = _make_response_data_model( "DbCategory", _db_category, skip_none=True) _category_update = {"update": Nested(category_model)} category_update_model = Model("CategoryUpdate", _category_update) _batch_category_delete = {"categoryIds": List(_category_id)} batch_category_delete_model = Model("BatchCategoryDelete", _batch_category_delete) _batch_category_update = { "categoryIdToUpdate1": Nested(category_update_model), "categoryIdToUpdate2": Nested(category_update_model), } batch_category_update_model = Model("BatchCategoryUpdate", _batch_category_update)
from flask_restx import Model from flask_restx.fields import String, List, Nested person = Model( 'Person Model', { 'id': String(), 'name': String(), 'gender': String(), 'eye_color': String(), 'hair_color': String(), 'age': String(), }) film_model = Model( 'Film Model', { 'id': String(), 'title': String(), 'description': String(), 'director': String(), 'producer': String(), 'release_date': String(), 'rt_score': String(), 'people': List(Nested(person)), })
DATA_SOURCE_NAME_FIELD_NAME: String(required=True), }, ) CompleteInputSourceModel = Model.clone( "DatabaseTableCompleteInputSourceModel", InputSourceModel, { DOC_NAME: String(), }, ) InputSourceEditionModel = Model( "DatabaseTableInputSourceEditionModel", {INPUT_SOURCE_FIELDS: List(Nested(InputSourceModel))}, ) CompleteInputSourcesListModel = Model( "DatabaseTableCompleteInputSourcesListModel", {INPUT_SOURCE_FIELDS: List(Nested(CompleteInputSourceModel))}, ) MODELS = [ BaseInputSourceModel, InputSourceModel, CompleteInputSourceModel, InputSourceEditionModel, CompleteInputSourcesListModel, ]
blueprint = Blueprint('apiv2', __name__, url_prefix='/api/v2') api = Api( blueprint, version='2.0', title=settings.api.title, description=settings.api.description, ) ns = api.namespace('mawaqit', description='Provides Mawaqit') mawaqit = api.model('Mawaqit', { settings.column_names_en.date: Date(), settings.column_names_en.wilaya: Nested(api.model('Wilaya', { 'code': String(), 'arabic_name': String(), 'english_name': String(), })), settings.salawat_en.fajr: Time(), settings.salawat_en.chorok: Time(), settings.salawat_en.dhohr: Time(), settings.salawat_en.asr: Time(), settings.salawat_en.maghrib: Time(), settings.salawat_en.icha: Time(), }) # TODO: add validation to say: day and (from and to) are mutually execlusive """ Time filtering: * If no time filter is speified, mawaqait of the current date will be returned * You can filter time in various ways:
_db_category_response_model as db_category_response_model, db_category_data, ) category_delete_response_data, category_delete_response_model = _make_response_data_model( "DeleteCategory", { "updatedRecipes": List(Integer), "failedUpdatedReipes": List(Integer) }, skip_none=True, ) batch_category_get_response_data, batch_category_get_response_model = _make_response_data_model( "BatchGetCategory", {"categories": List(Nested(db_category_data, skip_none=True))}) ( batch_category_update_response_data, batch_category_update_response_model, ) = _make_response_data_model("BatchUpdateCategory", {"failedUpdates": List(Integer)}, skip_none=True) ( batch_category_delete_response_data, batch_category_delete_response_model, ) = _make_response_data_model( "BatchDeleteCategory", { "updatedRecipes": List(Integer),