def post(self): parser = reqparse.RequestParser() parser.add_argument('desc', type=str, required=True, help='브루어리 이름') parser.add_argument('available_day', type=str, required=False, help='투어가 가능한 날') parser.add_argument('price', type=int, required=False, help='브루어리 투어 가격') parser.add_argument('region', type=str, required=False, help='브루어리 지역') parser.add_argument('url_apply', type=str, required=False, help='브루어리 신청') parser.add_argument('url_logo', type=str, required=False, help='브루어리 로고') parser.add_argument('url_img', type=str, required=False, help='') parser.add_argument('home_page', type=str, required=False, help='브루어리 사이트') parser.add_argument('location_mapX', type=float, required=False, help='브루어리 좌표 - longitude') parser.add_argument('location_mapY', type=float, required=False, help='브루어리 좌표 - latitude') parser.add_argument('available', type=bool, required=False, help='투어 가능 여부') parser.add_argument('name', type=str, required=False, help='투어 이름') args = parser.parse_args(strict=True) location = [args['location_mapX'], args['location_mapY']] args.pop('location_mapX') args.pop('location_mapY') args['location'] = location logger.debug(str(args)) b = Brewery(**args) db.collection('brewery').document().set(b.to_dict()) return 201
def get_main_page(region) -> dict: """ :param region: :return: """ ret = {} banner = db.collection('banner').stream() if region == 'all': brewery = db.collection('brewery').stream() else: brewery = db.collection('brewery').where('region', '==', region).stream() ret['banners'] = list(map(lambda x: {key: x.to_dict()[key] for key in _banner_list}, banner)) logger.debug(f'{ret}') ret['breweries'] = list(map(lambda x: {key: x.to_dict()[key] for key in _breweries_list}, brewery)) logger.debug(f'{ret}') return ret
def get(self): parser = reqparse.RequestParser() parser.add_argument('BreweryName', type=str, required=True, help='브루어리 이름') args = parser.parse_args(strict=True) # BreweryName으로 브루어리 검색 brewery = db.collection('brewery').where('name', '==', args['BreweryName']).stream() try: brewery = Brewery.from_dict(next(iter(brewery)).to_dict()) except StopIteration: return f'Developing | NameNotFound' body = {} body['brewery'] = brewery.to_dict() return body, 201
from src.database import db from lib.flask_restplus import Resource, Namespace, fields, reqparse from src.main_page import get_main_page banners = db.collection('banner') ns_mp = Namespace(name='main-page', description='Main-Page') res_banners = ns_mp.model(name='banners', model={ 'title': fields.String(description='배너 제목'), 'url_imgs': fields.List(fields.String, description='이미지 URL') }) res_breweries = ns_mp.model(name='breweries', model={ 'name': fields.String(description='양조장 이름'), 'url_img': fields.String(description='양조장 이미지'), 'region': fields.String(description='양조장 지역') }) resource = ns_mp.model(name='main-page', model={ 'banners': fields.List(fields.Nested(res_banners)), 'breweries': fields.List(fields.Nested(res_breweries)) })