def data_load(payload): customers = Customer(0, payload['first_name'], payload['last_name'], payload['gender'], payload['age'], payload['email'], payload['address_line1'], payload['address_line2'], payload['phonenumber'], True) customers.save(redis)
def create_customers(): """ Creates a Customer This endpoint will create a Customer based the data in the body that is posted --- tags: - Customers consumes: - application/json produces: - application/json parameters: - in: body name: body schema: id: data required: - address_line1 - address_line2 - age - email - first_name - last_name - gender - phonenumber properties: address_line1: type: string description: address line 1 of the customer address_line2: type: string description: address line 2 of the customer age: type: integer description: age of the customer email: type: string description: email address of the customer first_name: type: string description: first name of the customer last_name: type: string description: last name of the customer gender: type: string description: gender of the customer phonenumber: type: string description: phone number of the customer responses: 201: description: Customer information schema: id: Customer properties: id: type: integer description: unique id assigned internally by service active: type: boolean description: the status of customer whether it is currently active (false in this case) address_line1: type: string description: address line 1 of the customer address_line2: type: string description: address line 2 of the customer age: type: integer description: age of the customer email: type: string description: email address of the customer first_name: type: string description: first name of the customer last_name: type: string description: last name of the customer gender: type: string description: gender of the customer phonenumber: type: string description: phone number of the customer 400: description: Bad Request (the posted data was not valid) """ id = 0 payload = request.get_json() if Customer.validate(payload): customer = Customer(id, payload['first_name'], payload['last_name'], payload['gender'], payload['age'], payload['email'], payload['address_line1'], payload['address_line2'], payload['phonenumber'], True) customer.save(redis) id = customer.id cust = Customer.find( redis, id ) # added so that the response body of POST matches that of the GET and we compare the results in the TDD in the same format as the json returned by Redis #message = customer.serialize() message = cust.serialize() rc = HTTP_201_CREATED else: message = {'error': 'Data is not valid'} rc = HTTP_400_BAD_REQUEST response = make_response(jsonify(message), rc) if rc == HTTP_201_CREATED: response.headers['Location'] = url_for('get_customers', id=id) return response