コード例 #1
0
    def post(self, user_id):
        # Get arguments
        args = self.parser.parse_args()

        # Validate user, address and cleaner ids
        if User.get_by_id(user_id) is None:
            abort(404, 'User not found')

        if Address.get_by_id(args['address_id']) is None:
            abort(404, 'Address not found')

        if Cleaner.get_by_id(args['cleaner_id']) is None:
            abort(404, 'Cleaner not found')

        # Create new order
        order = Order(user_id=user_id,
                      address_id=args['address_id'],
                      cleaner_id=args['cleaner_id'],
                      date=args['date'],
                      start_time=args['start_time'],
                      end_time=args['end_time'],
                      rooms=args['rooms'],
                      special_rooms=args['special_rooms'],
                      extra_services=args['extra_services'],
                      reference=args['reference'],
                      transaction=args['transaction'],
                      price=args['price'])

        # Persist and return order
        success = order.persist()
        if not success:
            abort(400, 'Parameters incorrect')

        return order, 201
コード例 #2
0
    def get(self, address_id):
        # Get address by id
        address = Address.get_by_id(address_id)
        if address is None:
            abort(404)

        # Return address
        return address
コード例 #3
0
    def put(self, address_id):
        # Get address by id
        address = Address.get_by_id(address_id)
        if address is None:
            abort(404)

        # Update address fields
        args = self.parser.parse_args()
        address.street = assign(args['street'], address.street)
        address.house_number = assign(args['house_number'],
                                      address.house_number)
        address.flat_number = assign(args['flat_number'], address.flat_number)
        address.post_code = assign(args['post_code'], address.post_code)
        address.city = assign(args['city'], address.city)
        address.country = assign(args['country'], address.country)
        address.neighbourhood = assign(args['neighbourhood'],
                                       address.neighbourhood)

        # Persist changes and return address
        address.persist()
        return address