# Import flask dependencies
from flask import Blueprint, request, make_response, jsonify, g, session

# Import the database object from the main app module
from poultry import db
import json

# Import module models
from poultry.mod_auth.models import User
from poultry.mod_shed.models import Shed
from poultry.mod_bstock.models import Birdstock

mod_bstock = Blueprint('bstock', __name__, url_prefix='/bstock')


@mod_bstock.route('/create', methods=['POST'])
def create():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(" ")[1]
    else:
        auth_token = ''

    if auth_token:
        user_id = User.decode_auth_token(auth_token)
        if not isinstance(user_id, str):
            try:
                quantity = float(request.json['quantity'])
                btype = request.json['btype']
                age = float(request.json['age'])
                shed_number = int(request.json['shed'])
                shed = Shed.query.filter_by(shed=shed_number).first()
                bstock = Birdstock.query.filter_by(
                    bshed=shed_number, age=age, btype=btype).first()
                if not shed:
                    return make_response(jsonify({
                        'status': 'fail',
                        'message': 'Invalid shed number.',
                    })), 400
                elif not bstock:
                    new_bstock = Birdstock(shed=shed, quantity=quantity,
                                           btype=btype, age=age)
                    db.session.add(new_bstock)
                    db.session.commit()
                    return make_response(jsonify({
                        'status': 'success',
                        'message': 'Successfully bird stock is created.',
                    })), 201
                else:
                    update(bstock, quantity)
                    return make_response(jsonify({
                        'status': 'success',
                        'message': 'Bird stock successfully updated.'
                    })), 201
            except Exception as e:
                print(e)
                return make_response(jsonify({
                    'status': 'fail',
                    'message': 'Try again db error'
                })), 400

        return make_response(jsonify({
            'status': 'fail',
            'message': 'user_id is not an integer {}'.format(user_id)
        })), 401
    else:
        return make_response(jsonify({
            'status': 'fail',
            'message': 'Provide a valid auth token.'
        })), 401


def update(bstock, quantity):
    bstock.quantity += quantity
    db.session.add(bstock)
    db.session.commit()

e6f0e8f073966a3312484db813032cb837c21982
<mask token>


@mod_bstock.route('/create', methods=['POST'])
def create():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(' ')[1]
    else:
        auth_token = ''
    if auth_token:
        user_id = User.decode_auth_token(auth_token)
        if not isinstance(user_id, str):
            try:
                quantity = float(request.json['quantity'])
                btype = request.json['btype']
                age = float(request.json['age'])
                shed_number = int(request.json['shed'])
                shed = Shed.query.filter_by(shed=shed_number).first()
                bstock = Birdstock.query.filter_by(bshed=shed_number, age=
                    age, btype=btype).first()
                if not shed:
                    return make_response(jsonify({'status': 'fail',
                        'message': 'Invalid shed number.'})), 400
                elif not bstock:
                    new_bstock = Birdstock(shed=shed, quantity=quantity,
                        btype=btype, age=age)
                    db.session.add(new_bstock)
                    db.session.commit()
                    return make_response(jsonify({'status': 'success',
                        'message': 'Successfully bird stock is created.'})
                        ), 201
                else:
                    update(bstock, quantity)
                    return make_response(jsonify({'status': 'success',
                        'message': 'Bird stock successfully updated.'})), 201
            except Exception as e:
                print(e)
                return make_response(jsonify({'status': 'fail', 'message':
                    'Try again db error'})), 400
        return make_response(jsonify({'status': 'fail', 'message':
            'user_id is not an integer {}'.format(user_id)})), 401
    else:
        return make_response(jsonify({'status': 'fail', 'message':
            'Provide a valid auth token.'})), 401


<mask token>

<mask token>


@mod_bstock.route('/create', methods=['POST'])
def create():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(' ')[1]
    else:
        auth_token = ''
    if auth_token:
        user_id = User.decode_auth_token(auth_token)
        if not isinstance(user_id, str):
            try:
                quantity = float(request.json['quantity'])
                btype = request.json['btype']
                age = float(request.json['age'])
                shed_number = int(request.json['shed'])
                shed = Shed.query.filter_by(shed=shed_number).first()
                bstock = Birdstock.query.filter_by(bshed=shed_number, age=
                    age, btype=btype).first()
                if not shed:
                    return make_response(jsonify({'status': 'fail',
                        'message': 'Invalid shed number.'})), 400
                elif not bstock:
                    new_bstock = Birdstock(shed=shed, quantity=quantity,
                        btype=btype, age=age)
                    db.session.add(new_bstock)
                    db.session.commit()
                    return make_response(jsonify({'status': 'success',
                        'message': 'Successfully bird stock is created.'})
                        ), 201
                else:
                    update(bstock, quantity)
                    return make_response(jsonify({'status': 'success',
                        'message': 'Bird stock successfully updated.'})), 201
            except Exception as e:
                print(e)
                return make_response(jsonify({'status': 'fail', 'message':
                    'Try again db error'})), 400
        return make_response(jsonify({'status': 'fail', 'message':
            'user_id is not an integer {}'.format(user_id)})), 401
    else:
        return make_response(jsonify({'status': 'fail', 'message':
            'Provide a valid auth token.'})), 401


def update(bstock, quantity):
    bstock.quantity += quantity
    db.session.add(bstock)
    db.session.commit()

<mask token>
mod_bstock = Blueprint('bstock', __name__, url_prefix='/bstock')


@mod_bstock.route('/create', methods=['POST'])
def create():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(' ')[1]
    else:
        auth_token = ''
    if auth_token:
        user_id = User.decode_auth_token(auth_token)
        if not isinstance(user_id, str):
            try:
                quantity = float(request.json['quantity'])
                btype = request.json['btype']
                age = float(request.json['age'])
                shed_number = int(request.json['shed'])
                shed = Shed.query.filter_by(shed=shed_number).first()
                bstock = Birdstock.query.filter_by(bshed=shed_number, age=
                    age, btype=btype).first()
                if not shed:
                    return make_response(jsonify({'status': 'fail',
                        'message': 'Invalid shed number.'})), 400
                elif not bstock:
                    new_bstock = Birdstock(shed=shed, quantity=quantity,
                        btype=btype, age=age)
                    db.session.add(new_bstock)
                    db.session.commit()
                    return make_response(jsonify({'status': 'success',
                        'message': 'Successfully bird stock is created.'})
                        ), 201
                else:
                    update(bstock, quantity)
                    return make_response(jsonify({'status': 'success',
                        'message': 'Bird stock successfully updated.'})), 201
            except Exception as e:
                print(e)
                return make_response(jsonify({'status': 'fail', 'message':
                    'Try again db error'})), 400
        return make_response(jsonify({'status': 'fail', 'message':
            'user_id is not an integer {}'.format(user_id)})), 401
    else:
        return make_response(jsonify({'status': 'fail', 'message':
            'Provide a valid auth token.'})), 401


def update(bstock, quantity):
    bstock.quantity += quantity
    db.session.add(bstock)
    db.session.commit()

from flask import Blueprint, request, make_response, jsonify, g, session
from poultry import db
import json
from poultry.mod_auth.models import User
from poultry.mod_shed.models import Shed
from poultry.mod_bstock.models import Birdstock
mod_bstock = Blueprint('bstock', __name__, url_prefix='/bstock')


@mod_bstock.route('/create', methods=['POST'])
def create():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(' ')[1]
    else:
        auth_token = ''
    if auth_token:
        user_id = User.decode_auth_token(auth_token)
        if not isinstance(user_id, str):
            try:
                quantity = float(request.json['quantity'])
                btype = request.json['btype']
                age = float(request.json['age'])
                shed_number = int(request.json['shed'])
                shed = Shed.query.filter_by(shed=shed_number).first()
                bstock = Birdstock.query.filter_by(bshed=shed_number, age=
                    age, btype=btype).first()
                if not shed:
                    return make_response(jsonify({'status': 'fail',
                        'message': 'Invalid shed number.'})), 400
                elif not bstock:
                    new_bstock = Birdstock(shed=shed, quantity=quantity,
                        btype=btype, age=age)
                    db.session.add(new_bstock)
                    db.session.commit()
                    return make_response(jsonify({'status': 'success',
                        'message': 'Successfully bird stock is created.'})
                        ), 201
                else:
                    update(bstock, quantity)
                    return make_response(jsonify({'status': 'success',
                        'message': 'Bird stock successfully updated.'})), 201
            except Exception as e:
                print(e)
                return make_response(jsonify({'status': 'fail', 'message':
                    'Try again db error'})), 400
        return make_response(jsonify({'status': 'fail', 'message':
            'user_id is not an integer {}'.format(user_id)})), 401
    else:
        return make_response(jsonify({'status': 'fail', 'message':
            'Provide a valid auth token.'})), 401


def update(bstock, quantity):
    bstock.quantity += quantity
    db.session.add(bstock)
    db.session.commit()

# Import flask dependencies
from flask import Blueprint, request, make_response, jsonify, g, session

# Import the database object from the main app module
from poultry import db
import json

# Import module models
from poultry.mod_auth.models import User
from poultry.mod_shed.models import Shed
from poultry.mod_bstock.models import Birdstock

mod_bstock = Blueprint('bstock', __name__, url_prefix='/bstock')


@mod_bstock.route('/create', methods=['POST'])
def create():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(" ")[1]
    else:
        auth_token = ''

    if auth_token:
        user_id = User.decode_auth_token(auth_token)
        if not isinstance(user_id, str):
            try:
                quantity = float(request.json['quantity'])
                btype = request.json['btype']
                age = float(request.json['age'])
                shed_number = int(request.json['shed'])
                shed = Shed.query.filter_by(shed=shed_number).first()
                bstock = Birdstock.query.filter_by(
                    bshed=shed_number, age=age, btype=btype).first()
                if not shed:
                    return make_response(jsonify({
                        'status': 'fail',
                        'message': 'Invalid shed number.',
                    })), 400
                elif not bstock:
                    new_bstock = Birdstock(shed=shed, quantity=quantity,
                                           btype=btype, age=age)
                    db.session.add(new_bstock)
                    db.session.commit()
                    return make_response(jsonify({
                        'status': 'success',
                        'message': 'Successfully bird stock is created.',
                    })), 201
                else:
                    update(bstock, quantity)
                    return make_response(jsonify({
                        'status': 'success',
                        'message': 'Bird stock successfully updated.'
                    })), 201
            except Exception as e:
                print(e)
                return make_response(jsonify({
                    'status': 'fail',
                    'message': 'Try again db error'
                })), 400

        return make_response(jsonify({
            'status': 'fail',
            'message': 'user_id is not an integer {}'.format(user_id)
        })), 401
    else:
        return make_response(jsonify({
            'status': 'fail',
            'message': 'Provide a valid auth token.'
        })), 401


def update(bstock, quantity):
    bstock.quantity += quantity
    db.session.add(bstock)
    db.session.commit()
