def deactivate_customers(id): """ Deactivate a Customer This endpoint will deactivate a Customer based the body that is posted --- tags: - Customers produces: - application/json parameters: - name: id in: path description: ID of customer to retrieve type: integer required: true responses: 200: description: Customer updated the active status schema: $ref: '#/definitions/Customer' 404: description: Pet not found """ customer = Customer.find(id) if not customer: abort(status.HTTP_404_NOT_FOUND, "Customer with id '{}' was not found.".format(id)) customer.active = False customer.save() return make_response(jsonify(customer.serialize()), status.HTTP_200_OK)
def get_customers(id): """ Retrieve a single Customer This endpoint will return a Customer based on it's id --- tags: - Customers produces: - application/json parameters: - name: id in: path description: ID of customer to retrieve type: integer required: true responses: 200: description: Customer returned schema: $ref: '#/definitions/Customer' 404: description: Customer not found """ customer = Customer.find(id) if not customer: raise NotFound("Customer with id '{}' was not found.".format(id)) return make_response(jsonify(customer.serialize()), status.HTTP_200_OK)
def delete_customers(id): """ Delete a Customer This endpoint will delete a Customer based the id specified in the path --- tags: - Customers description: Deletes a Customer from the database parameters: - name: id in: path description: ID of pet to delete type: integer required: true responses: 204: description: Customer deleted """ customer = Customer.find(id) if customer: customer.delete() return make_response('', status.HTTP_204_NO_CONTENT)
def update_customers(id): """ Update a Customer This endpoint will update a Customer based the body that is posted --- tags: - Customers consumes: - application/json produces: - application/json parameters: - name: id in: path description: ID of customer to retrieve type: integer required: true - in: body name: body schema: id: data required: - username - password - firstname - lastname - email - active - promo properties: username: type: string description: username for the Customer password: type: string description: password for the Customer firstname: type: string description: firstname for the Customer lastname: type: string description: lastname for the Customer address: type: string description: address for the Customer phone: type: string description: phone number for the Customer email: type: string description: email for the Customer active: type: boolean description: active status for the Customer promo: type: boolean description: promo status for the Customer responses: 200: description: Customer updated schema: $ref: '#/definitions/Customer' 400: description: Bad Request (the posted data was not valid) """ check_content_type('application/json') customer = Customer.find(id) if not customer: raise NotFound("Customer with id '{}' was not found.".format(id)) data = request.get_json() app.logger.info(data) customer.deserialize(data) customer.id = id customer.save() return make_response(jsonify(customer.serialize()), status.HTTP_200_OK)