コード例 #1
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
コード例 #2
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