def post(self):
     """
     Create an accommodation 
     <h2>Implemention Note: </h2>
     <p>Use this method to create an accommodation</p>
     """
     role = get_jwt_claims()['role']
     current_id = get_jwt_identity()
     if role == 1:
         return {"message": "You dont have permission"}
     data = self.parser.parse_args()
     _id = uuid.uuid4().hex
     if Accommodation.find_by_name(data['name']):
         return {'message': "Accommodation with that name already exist"}
     accommodation = Accommodation(
         id=_id,
         member_id=current_id,
         name=data['name'],
         property_type_id=data['property_type_id'],
         max_guess=data['max_guess'],
         room_type_id=data['room_type_id'],
         standard_guess=data['standard_guess'],
         status=data['status'])
     accommodation.save_to_db()
     return {'message': "Create accmmodation success"}
 def post(self):
     """
     Create a image\n
         <h2>Implementation Notes:</h2>
         <p>Use this method to create a new image</p>
         <ul>
             <li>Send a JSON object with the id of accommodation, member, image_url in the request body</li>
         </ul>
     """
     data = self.parser.parse_args()
     accommodation = Accommodation.find_by_id(data['accommodation_id'])
     if not accommodation:
         api.abort(code=404,
                   message="Cannot find the accommodation you need")
     member_id = accommodation.member_id
     current_id = get_jwt_identity()
     role = get_jwt_claims()['role']
     if not (role == 3 or current_id == member_id):
         api.abort(code=400, message="You dont have permisson")
     if Image.find_by_url(data['image_url']):
         return {"message": "This image already exist"}, 400
     image = Image(member_id=current_id,
                   accommodation_id=data['accommodation_id'],
                   image_url=data['image_url'])
     image.save_to_db()
     return {"message": "Upload image success"}, 200
 def post(self):
     """
     Create a promotion\n
         <h2>Implementation Notes:</h2>
         <p>Use this method to create a new promotion</p>
         <ul>
             <li>Send a JSON object with the new code, discount_amount and start_at and end_at in the request body</li>
         </ul>
     """
     # get the id and role of current user
     data = self.parser.parse_args()
     current_id = get_jwt_identity()
     role = get_jwt_claims()['role']
     accommodation = Accommodation.find_by_id(data['accommodation_id'])
     if not accommodation:
         api.abort(code=404, message="Cannot find the accommodation you need")
     member_id = accommodation.member_id
     if not (role == 3 or current_id == member_id):
         api.abort(code=400, message="You dont have permission")
     if Promotion.find_by_code(data['code']):
         api.abort(code=400, message="The promotion with that code already exist")
     promotion = Promotion(member_id=current_id, accommodation_id=data['accommodation_id'], code=data['code'],
                           discount_amount=data['discount_amount'], start_time=data['start_time'], end_time=data['end_time'])
     promotion.save_to_db()
     return {"message": "Create promotion success"}, 200
Exemple #4
0
 def get(self, accommodation_id):
     """
     Return the list comment belong to an accommodation
     """
     accommodation = Accommodation.find_by_id(accommodation_id)
     if not accommodation:
         api.abort(code=404,
                   message="Cannot find the acccommodation you need")
     return accommodation.comments
 def get(self):
     """
     Return the list of all accommodation have in database
     <h2>Implemention Note: </h2>
     <p>Use this method to get back the list of accommodation</p>
     """
     role = get_jwt_claims()['role']
     if role != 3:
         api.abort(code=400, message="You dont have permisson")
     return Accommodation.get_all_accommodation()
Exemple #6
0
 def post(self, accommodation_id):
     """
     Create a comment in an accommodation
     """
     accommodation = Accommodation.find_by_id(accommodation_id)
     if not accommodation:
         return {"message": "Cannot found the accommodation you need"}, 404
     data = self.parser.parse_args()
     current_id = get_jwt_identity()
     comment = Comment(user_id=current_id,
                       accommodation_id=accommodation_id,
                       content=data['content'])
     comment.save_to_db()
 def get(self, accommodation_id):
     """
     Return the detail accommodation 
     <h2>Implemention Note: </h2>
     <p>Use this method to get detail of accommodation</p>
     <ul>
     <li>Send the accommodation_id in URL path</li>
     </ul>
     """
     accommodation = Accommodation.find_by_id(accommodation_id)
     if not accommodation:
         api.abort(code=404,
                   message="Cannot find the accommodation that you need")
     return accommodation
 def delete(self, accommodation_id):
     """
     Delete an accommodation
     <h2>Implemention Note: </h2>
     <p>Use this method to delete an accommodation</p>
     <ul>
     <li>Send the accommodation_id in URL path</li>
     </ul>
     """
     role = get_jwt_claims()['role']
     current_id = get_jwt_identity()
     accommodation = Accommodation.find_by_id(accommodation_id)
     if not accommodation:
         return {"message": "Cannot find the accommodation you need"}, 404
     else:
         if not (role == 3 or current_id == accommodation.member_id):
             return {"message": "You dont have permisson"}, 400
         accommodation.delete()
         return {"message": "Delete the accommodation success"}, 200
 def put(self, accommodation_id):
     """
     Update an accommodation
     <h2>Implemention Note: </h2>
     <p>Use this method to update an accommodation</p>
     <ul>
     <li>Send the accommodation_id in URL path</li>
     </ul>
     """
     role = get_jwt_claims()['role']
     current_id = get_jwt_identity()
     accommodation = Accommodation.find_by_id(accommodation_id)
     if not accommodation:
         api.abort(code=404,
                   message="Cannot find the accommodation you need")
     else:
         if not (role == 3 or current_id == accommodation.member_id):
             api.abort(code=400, message="You dont have permission")
         data = request.get_json()
         for field in data:
             setattr(accommodation, field, data[field])
         accommodation.save_to_db()
         return {"message": "Update the accommodation success"}
def insert_room():
    data = read_json('rooms.json')
    for i in data:
        if i['property_type'] == "":
            property_type = 1
        else:
            property_type = i['property_type']
        if i['room_type'] == "":
            room_type = 1
        else:
            room_type = i['room_type']
        if i['bed_type'] == "":
            bed_type = 1
        else:
            bed_type = i['bed_type']
        rooms = Accommodation(id=i['id'], member_id=i['member_id'], property_type_id=property_type,
                              room_type_id=room_type, bed_type_id=bed_type, name=i['name'],
                              address=i['address'], description=i['description'], special_notices=i['special_note'],
                              max_guess=i['maximum_guests'], num_bathrooms=i['num_bathrooms'],
                              num_bedrooms=i['num_bedrooms'], num_beds=i['num_beds'],
                              apartment_manual=i['apartment_manual'], apartment_rule=i['apartment_rules'],
                              status=i['status'], checkin_guide="")
        save_db(rooms)
 def post(self, accommodation_id):
     """
     Create a booking \n
         <h2>Implementation Notes:</h2>
         <p>Use this method to create a new booking</p>
         <ul>
             <li>Send a JSON object with the status, accommodation_id, number_of_guess, number_of_night, total_price in the request body</li>
         </ul>
     """
     current_id = get_jwt_identity()
     role = get_jwt_claims()['role']
     if role != 1:
         return {"message": "You shoud not create booking"}, 400
     accommodation = Accommodation.find_by_id(accommodation_id)
     if not accommodation:
         return {"message": "Cannot find the accommodation you need"}, 404
     member_id = accommodation.member_id
     data = self.parser.parse_args()
     code = Booking.code_generation()
     # check if that code already exist.
     # if yes, create another code
     # if no, creat the booking
     while Booking.find_by_code(code):
         code = Booking.code_generation()
     booking = Booking(code=code,
                       status=data['status'],
                       number_of_guess=data['number_of_guess'],
                       number_of_night=data['number_of_night'],
                       total_price=data['total_price'],
                       check_in=data['check_in'],
                       check_out=data['check_out'],
                       member_id=member_id,
                       user_id=current_id,
                       accommodation_id=accommodation_id)
     booking.save_to_db()
     return {"message": "Create booking success"}, 200
 def get(self, accommodation_id):
     """
     Return the list of image that accommodation have\n
     <h2>Implementation Notes:</h2>
     <p>Use this method to get the list of image belong to specify accommodation</p>
     <ul>
         <li>Specify by id of accommodation that you want to get list of image in URL path</li>
     </ul>
     """
     accommodation = Accommodation.find_by_id(accommodation_id)
     if not accommodation:
         api.abort(code=404,
                   message="Cannot find the accmmodation you need")
     member_id = accommodation.member_id
     current_id = get_jwt_identity()
     role = get_jwt_claims()['role']
     if not (role == 3 or current_id == member_id):
         api.abort(code=400, message="You dont have permission")
     images = accommodation.images
     if len(images) == 0:
         return {
             "message": "This accommodation doesnt have any image yet"
         }, 200
     return images, 200
Exemple #13
0
def room():
    if request.method == 'GET':
        response_object = []
        room = Accommodation.query.all()
        for i in room:
            response_object.append({
                'data': {
                    'id': i.id,
                    'name': i.name,
                },
                'success': 1,
            })
        return make_response(jsonify(response_object)), 200
    elif request.method == 'POST':
        id = uuid.uuid4().hex
        name = request.json['name']
        address = request.json['address']
        member_id = request.json['member_id']
        description = request.json['description']
        special_notices = request.json['special_notices']
        bed_type_id = request.json['bed_type_id']
        room_type_id = request.json['room_type_id']
        property_type_id = request.json['property_type_id']
        max_guess = request.json['max_guess']
        num_bathrooms = request.json['num_bathrooms']
        num_bedrooms = request.json['num_bedrooms']
        num_beds = request.json['num_beds']
        status = request.json['status']
        apartment_manual = request.json['apartment_manual']
        apartment_rule = request.json['apartment_rule']
        checkin_guide = request.json['checkin_guide']
        accommodation_id = request.json['accommodation_id']
        additional_guess_fee = request.json['additional_guess_fee']
        cleaning_fee = request.json['cleaning_fee']
        security_fee = request.json['security_fee']
        monthly_price = request.json['monthly_price']
        nightly_price = request.json['nightly_price']
        weekend_price = request.json['weekend_price']
        cancelation_policy = request.json['cancelation_policy']
        check_in = request.json['check_in']
        check_out = request.json['check_out']
        room = Accommodation(id=id,
                             member_id=member_id,
                             property_type_id=property_type_id,
                             room_type_id=room_type_id,
                             bed_type_id=bed_type_id,
                             name=name,
                             address=address,
                             description=description,
                             special_notices=special_notices,
                             status=status,
                             max_guess=max_guess,
                             num_bathrooms=num_bathrooms,
                             num_bedrooms=num_bedrooms,
                             num_beds=num_beds,
                             apartment_manual=apartment_manual,
                             apartment_rule=apartment_rule,
                             checkin_guide=checkin_guide)
        price = Price(accommodation_id=accommodation_id,
                      additional_guess_fee=additional_guess_fee,
                      cleaning_fee=cleaning_fee,
                      security_fee=security_fee,
                      monthly_price=monthly_price,
                      nightly_price=nightly_price,
                      weekend_price=weekend_price,
                      cancelation_policy=cancelation_policy,
                      check_in=check_in,
                      check_out=check_out)
        db.session.add(room)
        db.session.add(price)
        db.session.commit()
        res = {
            'id': id,
            'name': room.name,
            'member_id': room.member_id,
            'address': room.address,
            'description': room.description,
            'special_notices': room.special_notices,
            'bed_type_id': room.bed_type_id,
            'room_type_id': room.room_type_id,
            'property_type_id': room.property_type_id,
            'max_guess': room.max_guess,
            'num_bathrooms': room.num_bathrooms,
            'num_bedrooms': room.num_bedrooms,
            'num_beds': room.num_beds,
            'status': room.status,
            'apartment_manual': room.apartment_manual,
            'apartment_rule': room.apartment_rule,
            'created_at': room.created_at,
            'accommodation_id': price.accommodation_id,
            'additional_guess_fee': price.additional_guess_fee,
            'cleaning_fee': price.cleaning_fee,
            'security_fee': price.security_fee,
            'monthly_price': price.monthly_price,
            'nightly_price': price.nightly_price,
            'weekend_price': price.weekend_price,
            'cancelation_policy': price.cancelation_policy,
            'check_in': price.check_in,
            'check_out': price.check_out
        }
        return jsonify(res)