Ejemplo n.º 1
0
def updatePayment(p_id):
	''' PUT /api/v1/payments/6 	HTTP/1.1
		{"c_type" : "offsite"}

		Result : {
					"data": {
					"p_type": "offsite"
					},
					"meta": {
					"code": 200,
					"message": "Updated Successfully"
					}
				}
	'''
	with SessionManager(Session) as session:
		try:
			sql_payment = session.query(Payment).filter(Payment.id == p_id).one()
			sql_payment.p_type = request.json.get('p_type', sql_payment.p_type)
			session.commit()
			return jsonify(update_envelop(200, data=request.json))
		except IntegrityError:
			# if name already exsits in database  
			return jsonify(error_envelop(400, 'Integrity Error','Name already Exists'))
		except NoResultFound:
			return jsonify(error_envelop(404, 'ValueError', 'Id : {0} not found'.format(p_id)))
	#now the item is succesfulluy updated
	return jsonify(error_envelop(400,'UnknownError','Error need to be identified'))
Ejemplo n.º 2
0
def setDineTable():
	'''This function is used to store the new DineTable in the database
		Example : POST /api/v1/dinetables HTTP/1.1
		{ "capicity": 4, "alias" : "Table1", "status" : "empty"}

		Result : {
					"meta": {
					"code": 200,
					"message": "Created Successfully"
					}
				}
	'''
	with SessionManager(Session) as session:
		try:
			
			capacity = request.json['capacity']
			alias = request.json['alias']
			status = request.json.get('status', 'empty')
			dine_table = DineTable(capacity=capacity, alias=alias, status=status)
			session.add(dine_table)
			session.commit()
			return jsonify(post_envelop(200, data = request.json))

		except DataError: #this excepyion might probably occur if the value key has a value of non integer
			return jsonify(error_envelop(400, 'DataError', 'Use the correct value'))

		except IntegrityError:
			return jsonify(error_envelop(400, 'IntegrityError','Value : {0} already exists'.format(alias)))

		except:
			return jsonify(error_envelop(400,'UnknownError','Error need to be identified'))
Ejemplo n.º 3
0
def setPayment():
	'''This function is used to store the new payment in the database
		Example : POST /api/v1/payments HTTP/1.1
		{ "p_type": " onsite"}

		Result : {
					"meta": {
					"code": 200,
					"message": "Created Successfully"
					}
				}
	'''
	with SessionManager(Session) as session:
		try:
			
			p_type = request.json['p_type']
			payment = Payment(p_type=p_type)
			session.add(payment)
			session.commit()
			return jsonify(post_envelop(200, data = request.json))

		except DataError: #this excepyion might probably occur if the value key has a value of non integer
			return jsonify(error_envelop(400, 'DataError', 'Use the correct value'))

		except IntegrityError:
			return jsonify(error_envelop(400, 'IntegrityError','Value : {0} already exists'.format(p_type)))

		except:
			return jsonify(error_envelop(400,'UnknownError','Error need to be identified'))
Ejemplo n.º 4
0
def getCustomer(c_id):
    with SessionManager(Session) as session:
        try:
            sql_customer = session.query(Customer).filter(
                Customer.id == c_id).one()
            customer = dict(
                first_name=sql_customer.first_name,
                middle_name=sql_customer.middle_name,
                last_name=sql_customer.last_name,
                contact_number=sql_customer.contact_number,
                address=sql_customer.address,
                gender=sql_customer.gender,
                age=sql_customer.age,
                email=sql_customer.email,
                id=sql_customer.id,
                customer_join_date=sql_customer.customer_join_date,
                membership=dict(
                    m_type=sql_customer.c_membership.m_type,
                    discount=sql_customer.c_membership.discount,
                    description=sql_customer.c_membership.description,
                    id=sql_customer.c_membership.id))
            return jsonify(envelop(data=customer, code=200))
        except NoResultFound:
            return jsonify(
                error_envelop(404, 'NoResultFound',
                              'Id : {0} Not Found'.format(c_id)))
    return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 5
0
def setVat():
	'''This function is used to store the new vat in the database
		Example : POST /api/v1/vats HTTP/1.1
		{"name" : "food", "value":34}

		Result : {
					"meta": {
					"code": 200,
					"message": "Created Successfully"
					}
					}
	'''
	with SessionManager(Session) as session:
		try:
			name = request.json['name']
			value = request.json['value']
			vat = Vat(name=name, value=value)
			session.add(vat)
			session.commit()
			return jsonify(post_envelop(200, data = request.json))

		except DataError: #this excepyion might probably occur if the value key has a value of non integer
			return jsonify(error_envelop(400, 'DataError', 'Use the correct value'))

		except IntegrityError:
			return jsonify(error_envelop(400, 'IntegrityError','Value : {0} already exists'.format(name)))

		except:
			return jsonify(error_envelop(400,'UnknownError','Error need to be identified'))
Ejemplo n.º 6
0
def getCustomerByMembership(m_id, c_id):

    with SessionManager(Session) as session:
        try:
            sql_customer = session.query(Customer).filter(
                Customer.id == c_id).one()
            sql_membership = sql_customer.c_membership
            customer = dict(id=sql_customer.id,
                            uri=url_for('getCustomerByMembership',
                                        m_id=m_id,
                                        c_id=c_id),
                            first_name=sql_customer.first_name,
                            middle_name=sql_customer.middle_name,
                            last_name=sql_customer.last_name,
                            contact_number=sql_customer.contact_number,
                            gender=sql_customer.gender,
                            age=sql_customer.age,
                            email=sql_customer.email,
                            customer_join_date=sql_customer.customer_join_date,
                            address=sql_customer.address,
                            membership=dict(m_type=sql_membership.m_type,
                                            discount=sql_membership.discount,
                                            id=sql_membership.id,
                                            uri=url_for('getMembership',
                                                        m_id=m_id)))
            return jsonify(envelop(customer, 200))

        except NoResultFound:  #causes when there is no requested id in the database
            return jsonify(
                error_envelop(404, 'NoResultFound',
                              ' Cannot Get!!Id : {0} Not Found'.format(c_id)))

        except:
            return jsonify(
                error_envelop(400, 'UnknownError', 'Something went wrong'))
Ejemplo n.º 7
0
def updateEmployeePosition(p_id):
    ''' PUT /api/v1/dientables/6 	HTTP/1.1
		{"name" : " positions name"}

		Result : {
					"meta": {
					"code": 200,
					"message": "Updated Successfully"
					}
				}
	'''
    with SessionManager(Session) as session:
        try:
            sql_position = session.query(EmployeePosition).filter(
                EmployeePosition.id == p_id).one()
            sql_position.name = request.json.get('name', sql_position.name)
            sql_position.description = request.json.get(
                'description', sql_position.description)
            session.commit()
            return jsonify(update_envelop(200, data=request.json))
        except IntegrityError:
            # if name already exsits in database
            return jsonify(
                error_envelop(400, 'Integrity Error', 'Name already Exists'))
        except NoResultFound:
            return jsonify(
                error_envelop(404, 'ValueError',
                              'Id : {0} not found'.format(p_id)))

    return jsonify(error_envelop(400, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 8
0
def updateDineTable(d_id):
	''' PUT /api/v1/dientables/6 	HTTP/1.1
		{"alias" : "new table name", "capacity" : 3}

		Result : {
					"data": {
					"capacity": 3,
					"alias" : "new table name"
					},
					"meta": {
					"code": 200,
					"message": "Updated Successfully"
					}
				}
	'''
	with SessionManager(Session) as session:
		try:
			sql_dinetable = session.query(DineTable).filter(DineTable.id == d_id).one()
			sql_dinetable.alias = request.json.get('alias', sql_dinetable.alias)
			sql_dinetable.capacity = request.json.get('capacity', sql_dinetable.capacity)
			sql_dinetable.status = request.json.get('status', sql_dinetable.status)
			session.commit()
			return jsonify(update_envelop(200, data=request.json))
		except IntegrityError:
			# if name already exsits in database  
			return jsonify(error_envelop(400, 'Integrity Error','Name already Exists'))
		except NoResultFound:
			return jsonify(error_envelop(404, 'ValueError', 'Id : {0} not found'.format(d_id)))
		except DataError:
			return jsonify(error_envelop(404, 'DataError', 'Please use the status of enum : (unorder, order, served, cooking, empty) defined'))
	return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 9
0
def getMembership(m_id):
    '''This function will return the particular payment from list of payments
		Example : GET /api/v1/dinetables/1 	HTTP/1.1
		Result : {
				"alias": "Robus",
				"capacity": 8,
				"id": 1,
				"uri" : "/api/v1/dinetables/1"
				}
	'''
    with SessionManager(Session) as session:
        try:
            sql_membership = session.query(Membership).filter(
                Membership.id == m_id).one()
            m_type = sql_membership.m_type
            discount = sql_membership.discount
            description = sql_membership.description
            id = sql_membership.id
            uri = url_for('getMembership', m_id=sql_membership.id)
            data = dict(m_type=m_type,
                        discount=discount,
                        description=description,
                        id=id,
                        uri=uri)
            return jsonify(envelop(data, 200))
        except NoResultFound:
            return jsonify(
                error_envelop(404, 'NoResultFound',
                              'Id : {0} Not Found'.format(m_id)))
    return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 10
0
def getEmployeePosition(p_id):
    '''This function will return the particular payment from list of payments
		Example : GET /api/v1/dinetables/1 	HTTP/1.1
		Result : {
				"alias": "Robus",
				"capacity": 8,
				"id": 1,
				"uri" : "/api/v1/dinetables/1"
				}
	'''
    with SessionManager(Session) as session:
        try:
            sql_position = session.query(EmployeePosition).filter(
                EmployeePosition.id == p_id).one()
            name = sql_position.name
            description = sql_position.description
            id = sql_position.id
            uri = url_for('getEmployeePosition', p_id=sql_position.id)
            data = dict(name=name, description=description, id=id, uri=uri)
            return jsonify(envelop(data, 200))
        except NoResultFound:
            return jsonify(
                error_envelop(404, 'NoResultFound',
                              'Id : {0} Not Found'.format(p_id)))
    return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 11
0
def updateVat(vat_id):
	''' PUT /api/v1/vats/6 	HTTP/1.1
		{"name" : "New vat name", "value" : 34}

		Result : {
					"data": {
					"name": "New"
					},
					"meta": {
					"code": 200,
					"message": "Updated Successfully"
					}
				}
	'''
	with SessionManager(Session) as session:
		try:
			sql_vat = session.query(Vat).filter(Vat.id == vat_id).one()
			sql_vat.name = request.json.get('name', sql_vat.name)
			sql_vat.value = request.json.get('value', sql_vat.value)
			session.commit()
			return jsonify(update_envelop(200, data=request.json))
		except IntegrityError:
			# if name already exsits in database  
			return jsonify(error_envelop(400, 'Integrity Error','Name already Exists'))
		except NoResultFound:
			return jsonify(error_envelop(404, 'ValueError', 'Id : {0} not found'.format(vat_id)))
	#now the item is succesfulluy updated
	return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 12
0
def updateServiceCharge(s_id):
	''' PUT /api/v1/servicecharges/6 	HTTP/1.1
		{"name" : "New service name", "value" : 34}

		Result : {
					"data": {
					"name": "New service name"
					},
					"meta": {
					"code": 200,
					"message": "Updated Successfully"
					}
				}
	'''
	with SessionManager(Session) as session:
		try:
			sql_service = session.query(ServiceCharge).filter(ServiceCharge.id == s_id).one()
			sql_service.name = request.json.get('name', sql_service.name)
			sql_service.value = request.json.get('value', sql_service.value)
			session.commit()
			return jsonify(update_envelop(200, data=request.json))
		except IntegrityError:
			# if name already exsits in database  
			return jsonify(error_envelop(400, 'Integrity Error','Name already Exists'))
		except NoResultFound:
			return jsonify(error_envelop(404, 'ValueError', 'Id : {0} not found'.format(s_id)))
	#now the item is succesfulluy updated
	return jsonify(error_envelop(400,'UnknownError','Error need to be identified'))
Ejemplo n.º 13
0
def setEmployeePosition():
    '''This method is used to store the new position for the employee
		Example : POST /api/v1/employeepostions 
		{"name" : "Cook", "description" : "THis is desription"}
	'''

    with SessionManager(Session) as session:
        try:
            name = request.json['name']
            description = request.json.get('description', 'NA')
            sql_pos = EmployeePosition(name=name, description=description)
            session.add(sql_pos)
            session.commit()
            return jsonify(post_envelop(200, data=request.json))

        except DataError:  #this excepyion might probably occur if the value key has a value of non integer
            return jsonify(
                error_envelop(400, 'DataError', 'Use the correct value'))

        except IntegrityError:
            return jsonify(
                error_envelop(400, 'IntegrityError',
                              'Value : {0} already exists'.format(name)))

        except:
            return jsonify(
                error_envelop(400, 'UnknownError',
                              'Error need to be identified'))
Ejemplo n.º 14
0
def setBill():

    with SessionManager(Session) as session:
        try:
            total_price = request.json['total_price']
            on_site = request.json.get('on_site')
            customer_id = request.json['customer_id']
            dinetable_id = request.json['dinetable_id']
            employee_id = request.json['employee_id']
            payment_id = request.json['payment_id']
            vat_id = request.json['vat_id']
            service_charge_id = request.json['service_charge_id']
            bill_description = request.json.get('bill_description', 'NA')

            item_orders = request.json['item_orders']

            if len(item_orders) < 1:
                return jsonify(
                    error_envelop(400, 'BillError',
                                  'Please enter atleast one item!!'))
            #if there is more than one elements in bills then create a new bill object
            bill = Bill(total_price=total_price,
                        bill_description=bill_description,
                        on_site=on_site,
                        customer_id=customer_id,
                        dinetable_id=dinetable_id,
                        employee_id=employee_id,
                        payment_id=payment_id,
                        vat_id=vat_id,
                        service_charge_id=service_charge_id)
            session.add(bill)

            for item_order in item_orders:
                item_id = item_order['item_id']
                quantity = item_order['quantity']
                order_price = item_order['order_price']
                session.add(
                    ItemOrder(item_id=item_id,
                              quantity=quantity,
                              order_price=order_price,
                              bill=bill))

            session.commit()
            return jsonify(post_envelop(200, data=request.json))

        except DataError:  #this excepyion might probably occur if the value key has a value of non integer
            return jsonify(
                error_envelop(400, 'DataError', 'Use the correct value'))
        except IntegrityError:
            return jsonify(
                error_envelop(400, 'IntegrityError',
                              'Foreign Key violations. Use the correct id'))

        except:
            return jsonify(
                error_envelop(400, 'UnknownError',
                              'Error need to be identified'))
Ejemplo n.º 15
0
def deleteDineTable(d_id):
	with SessionManager(Session) as session:
		try:
			sql_dinetable = session.query(DineTable).filter(DineTable.id == d_id).one()
			session.delete(sql_dinetable)
			session.commit()
			return jsonify(delete_envelop(200))
		except NoResultFound: #causes when there is no requested id in the database
			return jsonify(error_envelop(404, 'NoResultFound', 'Id : {0} Not Found'.format(d_id)))
	#if no except is caught
	return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 16
0
def getBill(b_id):
    with SessionManager(Session) as session:
        try:
            bill = session.query(Bill).filter(Bill.id == b_id).one()
            #cus = bill.customer

            customer = bill.customer.first_name if bill.customer else 'Not Available'
            dinetable = bill.dinetable.alias if bill.dinetable else 'Not Available'
            employee = bill.employee.first_name if bill.employee else 'Not Available'
            payment = bill.payment.p_type if bill.payment else 'Not Available'
            vat = bill.vat.name if bill.vat else 'Not Available'
            service_charge = bill.service_charge.name if bill.service_charge else 'Not Available'

            bill_description = bill.bill_description
            on_site = bill.on_site
            total_price = bill.total_price
            bill_time_stamp = bill.bill_time_stamp

            items_orders = bill.items
            list_item_orders = []
            for item_order in items_orders:
                list_item_orders.append(
                    dict(item_id=item_order.item_id,
                         bill_id=item_order.bill_id,
                         quantity=item_order.quantity,
                         order_price=item_order.order_price,
                         order_time_stamp=item_order.order_time_stamp,
                         item_name=item_order.item.name
                         if item_order.item else 'Not Available',
                         item_unit_price=item_order.item.unit_price
                         if item_order.item else 0.0))

            b = dict(customer=customer,
                     dinetable=dinetable,
                     employee=employee,
                     payment=payment,
                     vat=vat,
                     bill_time_stamp=str(bill_time_stamp),
                     service_charge=service_charge,
                     bill_description=bill_description,
                     on_site=on_site,
                     total_price=total_price,
                     item_orders=list_item_orders)

            return jsonify(envelop(data=b, code=200))

        except NoResultFound:
            return jsonify(
                error_envelop(404, 'NoResultFound',
                              'Id : {0} Not Found'.format(b_id)))
    return jsonify(error_envelop(400, 'UnknownError', 'Somethig went wrong'))
Ejemplo n.º 17
0
def deleteEmployeePosition(p_id):
    with SessionManager(Session) as session:
        try:
            sql_position = session.query(EmployeePosition).filter(
                EmployeePosition.id == p_id).one()
            session.delete(sql_position)
            session.commit()
            return jsonify(delete_envelop(200))
        except NoResultFound:  #causes when there is no requested id in the database
            return jsonify(
                error_envelop(404, 'NoResultFound',
                              'Id : {0} Not Found'.format(p_id)))
    #if no except is caught
    return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 18
0
def deleteBill(b_id):
    with SessionManager(Session) as session:
        try:
            bill = session.query(Bill).filter(Bill.id == b_id).one()
            session.delete(bill)
            session.commit()
            return jsonify(delete_envelop(code=200))

        except NoResultFound:  #causes when there is no requested id in the database
            return jsonify(
                error_envelop(
                    404, 'NoResultFound',
                    ' Cannot delete!!Id : {0} Not Found'.format(b_id)))

    return jsonify(error_envelop(400, 'UnknownError', 'Somethig went wrong'))
Ejemplo n.º 19
0
def getCustomersByMembership(m_id):
    '''A function to get the customers based on memberships'''

    with SessionManager(Session) as session:
        try:
            sql_customers = session.query(Customer).filter(
                Customer.membership_id == m_id).order_by(Customer.id).all()
            customers = [
                dict(first_name=customer.first_name,
                     middle_name=customer.middle_name,
                     last_name=customer.last_name,
                     contact_number=customer.contact_number,
                     address=customer.address,
                     gender=customer.gender,
                     age=customer.age,
                     email=customer.email,
                     id=customer.id,
                     uri=url_for('getCustomerByMembership',
                                 m_id=m_id,
                                 c_id=customer.id),
                     customer_join_date=customer.customer_join_date)
                for customer in sql_customers
            ]
            return jsonify(envelop(data=customers, code=200))

        except:
            return jsonify(
                error_envelop(400, 'UnkownError', 'Somethig went wrong'))
Ejemplo n.º 20
0
def getItem(item_id):
    ''' This function is used to get the particular item in items..
	Example : GET /api/v1/items/1 HTTP/1.1
	Result : {
				"description": "No Description Available",
				"id": 1,
				"item_photo_uri": "Image URI Not Available",
				"name": "coke",
				"unit_price": 45
				}
	'''
    item = {}
    with SessionManager(Session) as sesion:
        #check to see if id exisst in items list
        try:
            sql_item = sesion.query(Item).filter(Item.id == item_id).one()
            sql_item_cat = sql_item.item_category

            item['name'] = sql_item.name
            item['id'] = sql_item.id
            item['url_id'] = url_for('getItem', item_id=item_id)
            item['item_photo_uri'] = sql_item.item_photo_uri
            item['description'] = sql_item.description
            item['unit_price'] = sql_item.unit_price
            item['item_category'] = dict(name=sql_item_cat.name,
                                         extra=sql_item_cat.extra,
                                         id=sql_item_cat.id)
        except:
            return jsonify(error_envelop(404, 'ValueError', 'Invalid ID'))
    return jsonify(envelop(data=item, code=200))
Ejemplo n.º 21
0
def getEmployeesByPositions(p_id):
    '''A function to get the customers based on Positions'''

    with SessionManager(Session) as session:
        try:
            sql_employees = session.query(Employee).filter(
                Employee.employee_position_id == p_id).order_by(
                    Employee.id).all()
            employees = [
                dict(
                    first_name=employee.first_name,
                    middle_name=employee.middle_name,
                    last_name=employee.last_name,
                    contact_number=employee.contact_number,
                    address=employee.address,
                    gender=employee.gender,
                    age=employee.age,
                    email=employee.email,
                    id=employee.id,
                    date_of_birth=str(employee.date_of_birth),
                    salary=employee.salary,
                    photo_uri=employee.photo_uri,
                    #uri = url_for('getCustomerByMembership', m_id=m_id, c_id = customer.id),
                    join_date=str(employee.join_date.date()))
                for employee in sql_employees
            ]
            return jsonify(envelop(data=employees, code=200))

        except:
            return jsonify(
                error_envelop(400, 'UnkownError', 'Somethig went wrong'))
Ejemplo n.º 22
0
def getMemberships():
    '''This function will return the all the payments available
		Example : GET /api/v1/dinetables HTTP/1.1
		Result : {
					"data": [
					  {
					"capacity": 2,
					"alias" : "table 1",
					"status" : "empty"
					
					},.....
		'''

    with SessionManager(Session) as session:
        try:
            sql_memberships = session.query(Membership).order_by(
                Membership.id).all()
            memberships = [
                dict(m_type=membership.m_type,
                     id=membership.id,
                     discount=membership.discount,
                     uri=url_for('getMembership', m_id=membership.id),
                     description=membership.description)
                for membership in sql_memberships
            ]
            return jsonify(envelop(memberships, 200))
        except:
            return jsonify(
                error_envelop(400, ' UnkownError', 'Error need to identified'))
Ejemplo n.º 23
0
def getCategoryItems(cat_id):
    '''This function is used to get all the items in the category
		Example : /api/v1/itemcategories/12/items 
		Result : this gets the items of particualar category
	'''
    list_of_items = []  #declaring the empty list outside the context manager
    with SessionManager(Session) as session:
        try:
            category = session.query(ItemCategory).filter(
                ItemCategory.id == cat_id).one()
            items = category.c_items
            list_of_items = [
                dict(id=item.id,
                     name=item.name,
                     unit_price=item.unit_price,
                     item_photo_uri=item.item_photo_uri,
                     url_id=url_for('getItem', item_id=item.id),
                     description=item.description) for item in items
            ]
        except:
            return jsonify(
                error_envelop(error_code=404,
                              error_type='Value Error',
                              error_message='ID is not available'))

    return jsonify(envelop(code=200, data=list_of_items, pagination=None))
Ejemplo n.º 24
0
def getEmployeePositions():
    '''This function will return the all the positions available
		Example : GET /api/v1/employeepositions HTTP/1.1
		Result : {
					"data": [
					  {
					"capacity": 2,
					"alias" : "table 1",
					"status" : "empty"
					
					},.....
		'''

    with SessionManager(Session) as session:
        try:
            sql_positions = session.query(EmployeePosition).order_by(
                EmployeePosition.id).all()
            positions = [
                dict(name=position.name,
                     id=position.id,
                     uri=url_for('getEmployeePosition', p_id=position.id),
                     description=position.description)
                for position in sql_positions
            ]
            return jsonify(envelop(positions, 200))
        except:
            return jsonify(
                error_envelop(400, ' UnkownError', 'Error need to identified'))
Ejemplo n.º 25
0
def getDinetables():
	'''This function will return the all the payments available
		Example : GET /api/v1/dinetables HTTP/1.1
		Result : {
					"data": [
					  {
					"capacity": 2,
					"alias" : "table 1",
					"status" : "empty"
					
					},.....
		'''
	
	with SessionManager(Session) as session:
		try:
			sql_dinetables = session.query(DineTable).order_by(DineTable.id).all()
			dinetables = [dict(capacity=dinetable.capacity,
							   id=dinetable.id,
							   alias = dinetable.alias,
							   uri = url_for('getDineTable', d_id=dinetable.id),
							   status = dinetable.status
								   ) for dinetable in sql_dinetables]
			return jsonify(envelop(dinetables, 200))
		except:
			return jsonify(error_envelop(400, ' UnkownError', 'Error need to identified'))
Ejemplo n.º 26
0
def getEmployees():
    from datetime import date
    with SessionManager(Session) as session:
        sql_employees = session.query(Employee).order_by(Employee.id).all()
        employees = [
            dict(
                first_name=employee.first_name,
                middle_name=employee.middle_name,
                last_name=employee.last_name,
                contact_number=employee.contact_number,
                address=employee.address,
                gender=employee.gender,
                age=employee.age,
                email=employee.email,
                id=employee.id,
                date_of_birth=str(employee.date_of_birth),
                salary=employee.salary,
                photo_uri=employee.photo_uri,
                position=dict(name=employee.e_position.name,
                              description=employee.e_position.description,
                              id=employee.e_position.id),
                #uri = url_for('getCustomerByMembership', m_id=m_id, c_id = customer.id),
                join_date=str(employee.join_date.date()))
            for employee in sql_employees
        ]
        return jsonify(envelop(data=employees, code=200))
    return jsonify(
        error_envelop(400, 'UnknownError', 'Error need to be identified'))
Ejemplo n.º 27
0
def updateMembership(m_id):
    ''' PUT /api/v1/dientables/6 	HTTP/1.1
		{"alias" : "new table name", "capacity" : 3}

		Result : {
					"data": {
					"capacity": 3,
					"alias" : "new table name"
					},
					"meta": {
					"code": 200,
					"message": "Updated Successfully"
					}
				}
	'''
    with SessionManager(Session) as session:
        try:
            sql_membership = session.query(Membership).filter(
                Membership.id == m_id).one()
            sql_membership.m_type = request.json.get('m_type',
                                                     sql_membership.m_type)
            sql_membership.discount = request.json.get('discount',
                                                       sql_membership.discount)

            #check weather the discount is between 0 and 100
            if not 0 <= int(sql_membership.discount) < 100:
                return jsonify(
                    error_envelop(
                        400, 'DataError',
                        'Enter the valid discount amount (0 to 100)'))

            sql_membership.description = request.json.get(
                'description', sql_membership.description)
            session.commit()
            return jsonify(update_envelop(200, data=request.json))
        except IntegrityError:
            # if name already exsits in database
            return jsonify(
                error_envelop(400, 'Integrity Error', 'Name already Exists'))
        except NoResultFound:
            return jsonify(
                error_envelop(404, 'ValueError',
                              'Id : {0} not found'.format(m_id)))

    return jsonify(error_envelop(100, 'UnknownError', 'UnknownError Found'))
Ejemplo n.º 28
0
def setCustomersByMembership(m_id):
    '''This function is used to set the customer based on membership_id as a foriegn key'''

    with SessionManager(Session) as session:
        try:
            first_name = request.json['first_name']
            last_name = request.json['last_name']
            middle_name = request.json.get('middle_name', 'NA')
            contact_number = request.json.get('contact_number', 'NA')
            address = request.json.get('address', 'NA')
            gender = request.json['gender']
            age = request.json['age']
            email = request.json.get('email', 'NA')
            if not 6 <= int(age) < 99:
                return jsonify(
                    error_envelop(400, "Age Error",
                                  "Please enter the age between 6 and 99 "))

            c = Customer(first_name=first_name,
                         last_name=last_name,
                         contact_number=contact_number,
                         address=address,
                         gender=gender,
                         age=age,
                         membership_id=m_id,
                         middle_name=middle_name,
                         email=email)
            session.add(c)
            session.commit()
            return jsonify(post_envelop(200, data=request.json))

        except DataError:  #this excepyion might probably occur if the value key has a value of non integer
            return jsonify(
                error_envelop(400, 'DataError', 'Use the correct value'))

        except IntegrityError:
            return jsonify(
                error_envelop(
                    400, 'IntegrityError',
                    'Violates foreign key ({0}) constraint'.format(m_id)))

        except:
            return jsonify(
                error_envelop(400, 'UnknownError',
                              'Error need to be identified'))
Ejemplo n.º 29
0
def setMembership():
    '''This function is used to store the new Membership in the database
		Example : POST /api/v1/memberships HTTP/1.1
		{ "m_type": "general", "discount" : 10, "description" : "some description"}

		Result : {
					"meta": {
					"code": 200,
					"message": "Created Successfully"
					}
				}
	'''
    with SessionManager(Session) as session:
        try:

            m_type = request.json['m_type']
            discount = request.json['discount']
            if not 0 <= int(discount) < 100:
                return jsonify(
                    error_envelop(
                        400, 'DataError',
                        'Enter the valid discount amount (0 to 100)'))
            description = request.json.get('description',
                                           'No Description Available')
            membership = Membership(m_type=m_type,
                                    discount=discount,
                                    description=description)
            session.add(membership)
            session.commit()
            return jsonify(post_envelop(200, data=request.json))

        except DataError:  #this excepyion might probably occur if the value key has a value of non integer
            return jsonify(
                error_envelop(400, 'DataError', 'Use the correct value'))

        except IntegrityError:
            return jsonify(
                error_envelop(400, 'IntegrityError',
                              'Value : {0} already exists'.format(m_type)))

        except:
            return jsonify(
                error_envelop(400, 'UnknownError',
                              'Error need to be identified'))
Ejemplo n.º 30
0
def deleteEmployeeByPosition(p_id, e_id):

    with SessionManager(Session) as session:
        try:
            sql_employee = session.query(Employee).filter(
                Employee.id == e_id).one()
            session.delete(sql_employee)
            session.commit()
            return jsonify(delete_envelop(200))

        except NoResultFound:  #causes when there is no requested id in the database
            return jsonify(
                error_envelop(
                    404, 'NoResultFound',
                    ' Cannot delete!!Id : {0} Not Found'.format(e_id)))

        except:
            return jsonify(
                error_envelop(400, 'UnknownError', 'Somethig went wrong'))