from flask_restx import Resource from jamaica.v1.restx import api from flask_sqlalchemy_session import current_session from jamaica.v1.serializers import GlasswareItem from barbados.caches.tablescan import GlasswareScanCache from barbados.factories.glassware import GlasswareFactory from barbados.serializers import ObjectSerializer ns = api.namespace('v1/glassware', description='Glassware.') @ns.route('') class GlasswaresEndpoint(Resource): @api.response(200, 'success') @api.marshal_list_with(GlasswareItem) def get(self): """ Return a list of all glassware. :return: List[Dict] """ serialized_glassware = GlasswareScanCache.retrieve() return serialized_glassware @api.response(201, 'created') @api.expect(GlasswareItem, validate=True) @api.marshal_with(GlasswareItem) def post(self): """ Create a new glassware.
from flask_restx import Resource from jamaica.v1.restx import api from flask_sqlalchemy_session import current_session from barbados.indexers import Indexers from barbados.indexes import Indexes ns = api.namespace('v1/indexes', description='Search indexes.') @ns.route('') class IndexesEndpoint(Resource): @api.response(200, 'success') def get(self): """ List all Indexes :return: List of Index keys """ return list(Indexes.get_indexes().keys()) @ns.route('/<string:name>') @api.doc(params={'name': 'An index name.'}) class IndexEndpoint(Resource): @api.response(200, 'success') def post(self, name): """ Re-index all objects that are supposed to be in an index. """ index = Indexes.get_index(name=name) indexer = Indexers.indexer_for(index)
import os import requests from flask_restx import Resource from jamaica.v1.restx import api from barbados.services.database import DatabaseService from barbados.services.logging import LogService from barbados.indexes import Indexes from barbados.caches import Caches ns = api.namespace('v1/setup', description='setup') @ns.route('') class SetupEndpoint(Resource): @api.response(200, 'success') def get(self): """ Setup the program. """ # Reset the database. DatabaseService.drop_all() DatabaseService.create_all() # Setup indexes. Each index init() will drop and re-create. Indexes.init() self._kibana_settings() # Clear all caches. Caches.init()
from flask_restx import Resource from jamaica.v1.restx import api from jamaica.v1.serializers import CocktailSearchItem, TextItem from jamaica.v1.cocktails.serializers import CocktailItem, CitationItem from jamaica.v1.cocktails.parsers import cocktail_list_parser from flask_sqlalchemy_session import current_session from barbados.search.cocktail import CocktailSearch from barbados.caches.tablescan import CocktailScanCache from barbados.caches.recipebibliography import RecipeBibliographyCache from barbados.caches.notebook import NotebookCache from barbados.factories.cocktail import CocktailFactory from barbados.serializers import ObjectSerializer from barbados.indexers.recipe import RecipeIndexer ns = api.namespace('v1/cocktails', description='Cocktail recipes.') @ns.route('') class CocktailsEndpoint(Resource): @api.response(200, 'success') @api.marshal_list_with(CocktailItem) def get(self): """ Return a list of all fully-detailed cocktail objects :return: List[Dict] """ serialized_cocktails = CocktailScanCache.retrieve() return serialized_cocktails @api.response(201, 'created')
from flask_restx import Resource from jamaica.v1.restx import api from jamaica.v1.lists.serializers import ListObject, ListSearchItem, ListItemObject from jamaica.v1.lists.parsers import list_parser from flask_sqlalchemy_session import current_session from barbados.factories.list import ListFactory from barbados.factories.listitem import ListItemFactory from barbados.serializers import ObjectSerializer from barbados.caches.tablescan import ListScanCache from barbados.indexers.list import ListIndexer from barbados.search.lists import ListsSearch from barbados.exceptions import FactoryUpdateException ns = api.namespace('v1/lists', description='Lists.') @ns.route('') class ListsEndpoint(Resource): @api.response(200, 'success') @api.marshal_list_with(ListObject) def get(self): """ List all Lists :return: List of List dicts """ return ListScanCache.retrieve() @api.response(201, 'created') @api.expect(ListObject, validate=True) @api.marshal_with(ListObject)
import json from flask_restx import Resource from jamaica.v1.restx import api from jamaica.v1.ingredients.serializers import IngredientObject, IngredientSearchItem, IngredientSubstitution from jamaica.v1.ingredients.parsers import ingredient_list_parser from flask_sqlalchemy_session import current_session from barbados.search.ingredient import IngredientSearch from barbados.caches.ingredienttree import IngredientTreeCache from barbados.caches.tablescan import IngredientScanCache from barbados.factories.ingredient import IngredientFactory from barbados.serializers import ObjectSerializer from barbados.indexers.ingredient import IngredientIndexer ns = api.namespace('v1/ingredients', description='Ingredient database.') @ns.route('') class IngredientsEndpoint(Resource): @api.response(200, 'success') @api.marshal_list_with(IngredientObject) def get(self): """ List all ingredients :return: List of Ingredient dicts """ serialized_ingredients = IngredientScanCache.retrieve() return serialized_ingredients @api.response(201, 'created')
from flask_restx import Resource from jamaica.v1.restx import api from barbados.caches import Caches ns = api.namespace('v1/caches', description='Caches.') @ns.route('') class CachesEndpoint(Resource): @api.response(200, 'success') def get(self): """ Return a list of all cache keys. :return: List[Dict] """ keys = Caches.cache_keys() return keys @ns.route('/<string:key>') @api.doc(params={'key': 'A cache key.'}) class CacheEndpoint(Resource): @api.response(204, 'successful invalidation') def delete(self, key): """ Invalidate a cache at a particular key :param key: The cache key to invalidate :return: None """ cache = Caches.get_cache(key)
from flask_sqlalchemy_session import current_session from barbados.factories.inventory import InventoryFactory from barbados.factories.cocktail import CocktailFactory from barbados.factories.reciperesolution import RecipeResolutionFactory from barbados.serializers import ObjectSerializer from barbados.caches.tablescan import InventoryScanCache from barbados.resolvers.recipe import RecipeResolver from barbados.caches.tablescan import CocktailScanCache from barbados.search.reciperesolution import RecipeResolutionSearch from barbados.indexers.reciperesolution import RecipeResolutionIndexer from barbados.indexers.inventory import InventoryIndexer from barbados.reports.inventory import InventoryReport ns = api.namespace('v1/inventories', description='Inventories.') @ns.route('') class InventoriesEndpoint(Resource): @api.response(200, 'success') @api.marshal_list_with(InventoryObject) def get(self): """ List all Inventories :return: List of Inventory dicts """ serialized_objects = InventoryScanCache.retrieve() return serialized_objects
from flask_restx import Resource from jamaica.v1.restx import api from flask import session, redirect, jsonify from flask_cognito import current_cognito_jwt from jamaica.auth import jamaica_authn_required, jamaica_authz_required, get_sign_in_url, get_sign_out_url ns = api.namespace('v1/auth', description='Authentication.') @ns.route('/info') class AuthInfoEndpoint(Resource): @api.response(200, 'success') @jamaica_authn_required() # @jamaica_authz_required() def get(self): """ Get information about the currently logged in session. :return: """ return jsonify(dict(current_cognito_jwt)) @ns.route('/login') class AuthLoginEndpoint(Resource): @api.response(302, 'redirect') def get(self): """ Return a redirect to the Cognito sign-in URL. :return: HTTP 302 """
from flask_restx import Resource from jamaica.v1.restx import api from flask_sqlalchemy_session import current_session from jamaica.v1.serializers import ConstructionItem from barbados.caches.tablescan import ConstructionScanCache from barbados.factories.construction import ConstructionFactory from barbados.serializers import ObjectSerializer ns = api.namespace('v1/constructions', description='Construction methods.') @ns.route('') class ConstructionsEndpoint(Resource): @api.response(200, 'success') @api.marshal_list_with(ConstructionItem) def get(self): """ List all Constructions. :return: List of serialized Construction objects. """ return ConstructionScanCache.retrieve() @api.response(201, 'created') @api.expect(ConstructionItem, validate=True) @api.marshal_with(ConstructionItem) def post(self): """ Insert new Construction. :return: Serialized Construction object.