コード例 #1
0
    def put(self) -> Response:
        body = request.get_json()
        roomID = Rooms.objects(roomID=body['roomID'])
        if len(roomID) > 0:

            schema = Kanpai.Object({
                'roomID': Kanpai.String().required(),
                'roomType': Kanpai.String().required(),
                'person': Kanpai.String().required(),
                'price': Kanpai.String().required(),
                'room_status': Kanpai.String().required(),
            })
            validate_result = schema.validate(body)
            if validate_result.get('success', False) is False:
                return Response(status=400)

            Rooms.objects(roomID=body['roomID']).update(
                set__roomType=body['roomType'],
                set__person=body['person'],
                set__price=body['price'],
                set__room_status=body['room_status'])

            res = jsonify({
                "data": [body],
                "message": "success",
                "status": 200
            })
            res.status_code = 200
            return res
        else:
            res = jsonify({"data": body, "message": "error", "status": 400})
            res.status_code = 400
            return res
コード例 #2
0
    def post(self) -> Response:
        body = request.get_json()

        roomID = Rooms.objects(roomID=body['roomID'])
        if not len(roomID) > 0:
            schema = Kanpai.Object({
                'roomID': Kanpai.String().required(),
                'roomType': Kanpai.String().required(),
                'person': Kanpai.String().required(),
                'price': Kanpai.String().required(),
                'room_status': Kanpai.String().required(),
            })
            validate_result = schema.validate(body)
            if validate_result.get('success', False) is False:
                res = jsonify({
                    "data": [body],
                    "message": "Argument error",
                    "status": 400
                })
                res.status_code = 400
                return res

            try:
                room = Rooms(**body)
                room.save()
                res = jsonify({
                    "data": [body],
                    "message": "success",
                    "status": 201
                })
                res.status_code = 201
                return res
            except NotUniqueError:
                res = jsonify({
                    "data": [body],
                    "message": "error",
                    "status": 400
                })
                res.status_code = 400
                return res
        else:
            res = jsonify({"data": [body], "message": "error", "status": 400})
            res.status_code = 400
            return res
コード例 #3
0
 def get(self) -> Response:
     roomID = request.args.get('roomID')
     room = Rooms.objects(roomID=roomID)
     if len(room) > 0:
         res = jsonify({"data": room, "message": "success", "status": 200})
         res.status_code = 200
         return res
     else:
         res = jsonify({"data": "null", "message": "error", "status": 204})
         res.status_code = 204
         return res
コード例 #4
0
 def delete(self) -> Response:
     body = request.get_json()
     room = Rooms.objects(roomID=body['roomID'])
     if len(room) > 0:
         room.delete()
         res = jsonify({"data": room, "message": "success", "status": 200})
         res.status_code = 200
         return res
     else:
         res = jsonify({"data": body, "message": "error", "status": 400})
         res.status_code = 400
         return res
コード例 #5
0
ファイル: controllers.py プロジェクト: congcoi226/MVC
 def get_class_and_room_with_room_id(self, room_id):
     response_room = Rooms().get_with_id(room_id)
     if not response_room:
         return None, None
     response_classes = Classes().get_with_room_id(room_id)
     return response_room, response_classes
コード例 #6
0
ファイル: transaction.py プロジェクト: sSlotty/ResortAPI
    def post(self) -> Response:
        body = request.get_json()
        transaction = body['transactionID']
        pipline = [{
            "$match": {
                "_id": transaction
            }
        }, {
            "$lookup": {
                'from': 'guests',
                'localField': 'guestID',
                'foreignField': '_id',
                'as': 'guest'
            }
        }, {
            "$lookup": {
                'from': 'rooms',
                'localField': 'roomID',
                'foreignField': '_id',
                'as': 'room'
            }
        }]
        x = Transactions.objects.aggregate(pipline)
        y = list(x)
        local = list(y)

        if local[0]['status'] == 'False':
            guest = local[0]['guest']
            room = local[0]['room']

            key = uuid.uuid4().int
            checkIN = str(local[0]['check_in']).format("%Y-%m-%d")
            checkOUT = body['check_out']
            days = days_between(checkIN, checkOUT)

            price = days * int(room[0]['price'])

            data = {
                'transactionID': transaction,
                'room': room[0],
                'roomID': room[0]["_id"],
                'roomType': room[0]["_id"],
                'roomID': room[0]["_id"],
                'roomID': room[0]["_id"],
                'price': price,
                'guest': {
                    'name': guest[0]['name'],
                    'tel': guest[0]['tel']
                },
                'check_in': checkIN,
                'check_out': checkOUT
            }

            Transactions.objects(transactionID=transaction).update(
                set__status="True",
                set__check_out=checkOUT,
                set__total_bill=str(price),
            )
            data_payment = {
                'paymentID': str(key)[0:5],
                'transactionID': transaction,
                'guestID': guest[0]['_id'],
                'room_price': room[0]['price'],
                'total_bill': price,
                'status': 'False'
            }

            try:
                payment = Payments(**data_payment)
                payment.save()

                Rooms.objects(roomID=room[0]['_id']).update(
                    set__room_status='True')

                res = jsonify({
                    "data": [None],
                    "message": "success",
                    "status": 200
                })
                res.status_code = 200
                return res
            except NotUniqueError:
                res = jsonify({
                    "data": "null",
                    "message": "error",
                    "status": 400
                })
                res.status_code = 400
                return res
        else:
            res = jsonify({"data": "null", "message": "error", "status": 400})
            res.status_code = 400
            return res
コード例 #7
0
ファイル: transaction.py プロジェクト: sSlotty/ResortAPI
    def post(self) -> Response:

        body = request.get_json()
        schema = Kanpai.Object({
            'userID': Kanpai.String().required(),
            'guestID': Kanpai.String().required(),
            'roomID': Kanpai.String().required(),
            'transaction_date': Kanpai.String(),
            'check_in': Kanpai.String().required()
        })
        print(body)

        room_id = Rooms.objects(
            roomID=body['roomID']).values_list('room_status')
        filter_status = list(room_id)
        status = filter_status[0]

        if status == "True":
            if len(room_id) > 0:
                key = uuid.uuid4().int
                data = {
                    'transactionID': str(key)[0:6],
                    'userID': body['userID'],
                    'guestID': body['guestID'],
                    'roomID': body['roomID'],
                    'transaction_date': datetime.utcnow(),
                    'check_in': body['check_in'],
                    'check_out': "None",
                    'total_bill': "None",
                    'status': 'False'
                }
                transaction = Transactions(**data)
                transaction.save()

                Rooms.objects(roomID=body['roomID']).update(
                    set__room_status="False")

                res = jsonify({
                    "data": [None],
                    "message": "success",
                    "status": 201
                })
                res.status_code = 201
                return res

            else:
                res = jsonify({
                    "data": [None],
                    "message": "No have room number",
                    "status": 400
                })
                res.status_code = 400
                return res
        else:
            res = jsonify({
                "data": [None],
                "message": "Room is not alivable",
                "status": 400
            })
            res.status_code = 400
            return res