def pair_user(placeId, userId): pool = filter.get_active_pool(userId) pair = filter.get_active_pair(userId) if status.is_place(placeId) == False: return response(msg="Wrong place ID.", payload={"status": "noPair"}, code=200) if status.is_noPair(userId): try: db_session.add(Pool(placeId=placeId, userId=userId)) except BaseException as err: db_session.rollback() logging.error("SQL is rollback. error is: {}", err) raise err else: db_session.commit() reply.pairing(userId) message.push_customer_menu(userId, Context.menu_waiting_cancel) return response(msg="User start to pair.", payload={"status": "pairing"}, code=200) elif status.is_pairing(userId): reply.pairing(userId) return response(msg="User is exist and pairing.", payload={"status": "pairing"}, code=200) else: return response(msg="User is chatting.", payload={"status": "paired"}, code=200) return "success"
def seed(): init_db() place_count = Place.query.filter().count() if place_count == 0: db_session.add( Place(id="1111", name="木木卡的黑店", longitude="25.066765", latitude="121.526336")) db_session.commit()
def register(): """ View function to register new user """ try: user = user_schema.load(request.get_json()) db_session.add(user) db_session.commit() return (json.dumps(user_schema.dump(user)), 200, { 'content-type': 'application/json' }) except ValidationError as err: return make_response(jsonify({'message': err.messages}), 422)
def user_colors(user_id): """ View function to retrieve colors by user. """ if request.method == 'GET': colors = db_session.query(Color).filter_by(user_id=user_id).all() return (json.dumps(colors_schema.dump(colors)), 200, {'content_type': 'application/json'}) try: data = request.get_json() data['user_id'] = user_id color = color_schema.load(data) db_session.add(color) db_session.commit() return (json.dumps(color_schema.dump(color)), 200, {'content-type': 'application/json'}) except ValidationError as err: return make_response(jsonify({'message': err.messages}), 422)
def user_moods(user_id): """ View function to retrieve moods by user. """ if request.method == 'GET': moods = db_session.query(Mood).filter_by(user_id=user_id).all() return (json.dumps(moods_schema.dump(moods)), 200, { 'content_type': 'application/json' }) try: data = request.get_json() color = db_session.query(Color).get(data['color_id']) data['user_id'] = user_id data['color_hex'] = color.hex_code mood = mood_schema.load(data) db_session.add(mood) db_session.commit() return (json.dumps(mood_schema.dump(mood)), 200, { 'content-type': 'application/json' }) except ValidationError as err: return make_response(jsonify({'message': err.messages}), 422)