Esempio n. 1
0
 def put(self) -> Response:
     body = request.get_json()
     booking = Bookings.objects(bookingID=body['bookingID'])
     if len(booking) > 0:
         Bookings.objects(bookingID=body['bookingID']).update(
             set__status="กำลังตรวจ",
             set__update_at=str(datetime.utcnow()))
         response = Response("Success to updated booking")
         response = jsonify({"data":body,"message":"success","status":200})
         response.status_code = 200
         return response
     else:
         response = jsonify({"data":None,"message":"booking id is exit","status":204})
         response.status_code = 204
         return response
Esempio n. 2
0
 def delete(self) -> Response:
     body = request.get_json()
     obj = Bookings.objects(bookingID=body['bookingID'])
     obj.delete()
     response = jsonify({"data":body,"message":"success","status":200})
     response.status_code = 200
     return response
 def post(cls):
     username = request.json['user_name']
     restaurant_id = request.json['restaurant_id']
     phone = request.json['phone']
     email = request.json['email']
     no_of_seats = request.json['no_of_seats']
     booking_date = datetime.strptime(request.json['booking_date'],
                                      '%d/%m/%Y')
     customer_id = request.json['customer_id']
     message = f'Booking confirmed for today for {username} at {restaurant_id} for {no_of_seats} people \n. We ' \
               f' will contact you on phone no: {phone} & email :{email} with further details.'
     booking = Bookings(cust_name=username,
                        no_of_seats=no_of_seats,
                        booking_date=booking_date,
                        restaurant_id=restaurant_id,
                        customer_id=customer_id)
     booking.save_to_db()
     return booking.to_json(), 201
Esempio n. 4
0
 def get(self) -> Response:
     booking = Bookings.objects()
     if len(booking) > 0:
         response = jsonify({"data": booking,"message":"success","status":200})
         response.status_code = 200
         return response
     else:
         response = jsonify({"data":None,"message":"error","status":204})
         response.status_code = 204
         return response
Esempio n. 5
0
    def post(self) -> Response:

        schema = Kanpai.Object({
            'bookingID': Kanpai.String().required(),
            'staffID': Kanpai.String().required(),
            'patentID': Kanpai.String().required(),
            'detail': Kanpai.String().required(),
            'dateBooking': Kanpai.String().required(),
            'status': Kanpai.String().required(),
            'create_at': Kanpai.String().required(),
            'update_at': Kanpai.String().required()
        })

        body = request.get_json()

        key = uuid.uuid4().int
        data = {
            'bookingID': str(key)[0:6],
            'staffID': body['staffID'],
            'patentID': body['patentID'],
            'detail': body['detail'],
            'dateBooking': body['dateBooking'],
            'status': "กำลังรอคิว",
            'create_at': str(datetime.utcnow()),
            'update_at': str(datetime.utcnow())
        }

        validate_result = schema.validate(data)
        if validate_result.get('success', False) is False:
            response = jsonify({"data":None,"message":"error","status":400})
            response.status_code = 400
            return response
        patent = Patients.objects(patentID=body['patentID'])
        if len(patent) > 0:
            try:

                Bookings(**data).save()
                response = jsonify({"data":data,"message":"success","status":201})
                response.status_code = 201
                return response

            except NotUniqueError:
                response = jsonify({"data":None,"message":"ID already exit.","status":400})
                response.status_code = 400
                return response

        else:
            response = jsonify({"data":None,"message":"error","status":204})
            response.status_code = 204
            return response
Esempio n. 6
0
    def post(self) -> Response:
        body = request.get_json()
        booking = Bookings.objects(bookingID=body['bookingID'])
        print(len(booking))
        if len(booking) > 0:
            schema = Kanpai.Object({
                'reportID': Kanpai.String().required(),
                'bookingID': Kanpai.String().required(),
                'staffID': Kanpai.String().required(),
                'patentID': Kanpai.String().required(),
                'header': Kanpai.String().required(),
                'detail': Kanpai.String().required(),
                'create_at': Kanpai.String(),
                'update_at': Kanpai.String()
            })

            key = uuid.uuid4().int
            data = {
                'reportID': str(key)[0:6] + '_' + body['patentID'],
                'bookingID': body['bookingID'],
                'staffID': body['staffID'],
                'patentID': body['patentID'],
                'header': body['header'],
                'detail': body['detail'],
                'create_at': str(datetime.utcnow()),
                'update_at': str(datetime.utcnow())
            }

            validate_result = schema.validate(data)
            if validate_result.get('success', False) is False:
                response = jsonify({
                    "data": None,
                    "message": "error",
                    "status": 400
                })
                response.status_code = 400
                return response

            try:
                Bookings.objects(bookingID=body['bookingID']).update(
                    set__status="ตรวจเสร็จสิ้น",
                    set__update_at=str(datetime.utcnow()))

                Reports(**data).save()

                response = jsonify({
                    "data":
                    str(key)[0:6] + '_' + body['patentID'],
                    "message":
                    "success",
                    "status":
                    201
                })
                response.status_code = 201
                return response

            except NotUniqueError:
                response = jsonify({
                    "data": None,
                    "message": "ReportID already add to storage",
                    "status": 400
                })
                response.status_code = 400
                return response
        else:
            response = jsonify({
                "data": None,
                "message": "ReportID does not exist",
                "status": 400
            })
            response.status_code = 400
            return response