コード例 #1
0
 def put(self, code):
     """
     Update a promotion\n
     <h2>Implementation Notes:</h2>
     Use this method to update a promotion with a given code \n
     <ul>
         <li>Send a JSON object with the new discount_amount or check_in_time in the request body</li>
         <li>Specify the Code of the promotion to get in the request URL path</li>
     </ul>
     """
     promotion = Promotion.find_by_code(code=code)
     if not promotion:
         api.abort(code=404, message="Cannot find the promotion that you need")
     member_id = promotion.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")
     data = request.get_json()
     for field in data:
         setattr(promotion, field, data[field])
     promotion.save_to_db()
     return {
         "message": "update your promotion success"
     }, 200
コード例 #2
0
 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
コード例 #3
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
コード例 #4
0
 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()
コード例 #5
0
 def get(self):
     """
     Return list of user account \n
         <h2>Implementation Notes:</h2>
         <p>Use this method to get list of member account</p>
     """
     role = get_jwt_claims()['role']
     if role != 3:
         api.abort(code=400, message="You dont have permission")
     return Member.get_all_member()
コード例 #6
0
 def get(self):
     """
     Return the list of booking\n
     <h2>Implementation Notes:</h2>
     <p>Use this method to get the list of booking</p>
     """
     role = get_jwt_claims()['role']
     if role != 3:
         api.abort(code=400, message="You dont have permission")
     return Booking.get_all_booking()
コード例 #7
0
 def get(self):
     """
     Return a list of user \n
     <h2> Implementation Notes:</h2>
     <p> Use this method to get the list of user\n
     """
     role = get_jwt_claims()['role']
     if role != 3:
         api.abort(code=400, message="You dont have permission")
     else:
         return User.get_all_users()
コード例 #8
0
 def get(self, code):
     """
     Return detail of a promotion with a given code\n
     <h2>Implementation Note:</h2>\n
     Use this method to get detail of a promotion with a given code
     <ul>
         <li>Specify the Code of the promotion to get in the request URL path</li>
     </ul>
     """
     promotion = Promotion.find_by_code(code=code)
     if not promotion:
         api.abort(code=400, message="Cannot find the promotion you need")
     return promotion
コード例 #9
0
 def get(self, member_id):
     """
     Return the list of promotion belong to particular member\n
     <h2>Implementation Notes:</h2>\n
     Use this method to get all the promotion of a member
     """
     role = get_jwt_claims()['role']
     if role == 1:
         api.abort(code=400, message="You dont have permission")
     member = Member.find_by_id(_id=member_id)
     if not member:
         api.abort(code=404, message="Cannot find the member user you need")
     return member.promotions
コード例 #10
0
 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
コード例 #11
0
 def get(self, member_id):
     """
     Return the list of booking for individual member\n
     <h2>Implementation Notes:</h2>
     <p>Use this method to get the list of booking for individual member</p>
     """
     role = get_jwt_claims()['role']
     current_id = get_jwt_identity()
     member = Member.find_by_id(member_id)
     if not member:
         api.abort(code=404, message="Cannot find the member you need")
     else:
         if not (role == 3 or current_id == member_id):
             api.abort(code=400, message="You dont have permission")
         return member.bookings
コード例 #12
0
 def get(self, user_id):
     """
     Return detail of a user account \n
         <h2>Implementation Notes:</h2>
         <p>Use this method to get detail of a user account</p>
         <ul>
             <li>Specify the user_id of user in URL path</li>
         </ul>
     """
     role = get_jwt_claims()['role']
     if role != 3:
         api.abort(code=400, message="You dont have permission")
     else:
         user = User.find_by_id(_id=user_id)
         if user:
             return user, 200
         return {"message": "Cannot find the account that you need"}, 400
コード例 #13
0
 def get(self, member_id):
     """
     Return detail of a member account \n
         <h2>Implementation Notes:</h2>
         <p>Use this method to get detail of a member account</p>
         <ul>
             <li>Specify the id of member in URL path</li>
         </ul>
     """
     role = get_jwt_claims()['role']
     if role != 3:
         api.abort(code=400, message="You dont have permisson")
     member = Member.find_by_id(_id=member_id)
     if not member:
         api.abort(code=404,
                   message="Cannot find the account that you need")
     return member, 200
コード例 #14
0
 def get(self, code):
     """
     Return detail  of a booking \n
     <h2> Implementation Notes:</h2>
     <p> Use this method to get detail of a booking\n
     <ul>
         <li>Include the code in the URL path</li>
     </ul>
     """
     role = get_jwt_claims()['role']
     current_id = get_jwt_identity()
     booking = Booking.find_by_code(code)
     if booking:
         if not (role == 3 or current_id == booking.user_id
                 or current_id == booking.member_id):
             api.abort(code=300, message="You dont have permission")
         return booking, 200
     return {"message": "Cannot find the booking"}, 400
コード例 #15
0
 def delete(self, image_id):
     """
     Delete a image with a given id\n
     <h2>Implementation Note:</h2>\n
     Use this method to delete a image with a given id
     <ul>
         <li>Specify the ID of the image to get in the request URL path</li>
     </ul>
     """
     role = get_jwt_claims()['role']
     current_id = get_jwt_identity()
     image = Image.find_by_id(image_id)
     if image:
         if not (role == 3 or current_id == image.member_id):
             api.abort(code=400, message="You dont have permission")
         image.delete()
         return {"message": "Delete image success"}, 200
     return {"message": "Cannot find the image that you need"}, 404
コード例 #16
0
 def delete(self, code):
     """
     Delete a promotion with a given code\n
     <h2>Implementation Note:</h2>\n
     Use this method to delete a promotion with a given code
     <ul>
         <li>Specify the Code of the promotion to get in the request URL path</li>
     </ul>
     """
     promotion = Promotion.find_by_code(code=code)
     if not promotion:
         api.abort(code=404, message="Cannot find the promotion you need")
     member_id = promotion.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, messag="You dont have permisson")
     promotion.delete()
     return {"message": "Promotion was deleted"}, 200
コード例 #17
0
 def get(self, member_id):
     """
     Return the list accommodation of a particular member
     <h2>Implemention Note: </h2>
     <p>Use this method to get back the list of accommodation for an individual</p>
     <ul>
     <li>Send the member_id in URL path</li>
     </ul>
     """
     role = get_jwt_claims()['role']
     current_id = get_jwt_identity()
     member = Member.find_by_id(member_id)
     if not (role == 3 or current_id == member_id):
         api.abort(code=400, messag="You dont have permission")
     else:
         if not member:
             api.abort(code=404,
                       message="Dont have the account you need in database")
         return member.accommodations
コード例 #18
0
 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
コード例 #19
0
 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"}
コード例 #20
0
 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