Ejemplo n.º 1
0
    def post(self):
        market_id = request.json['market_id']
        reserve_list = request.json['menu']
        order_time = request.json['time']
        finder = Market_Model.objects(market_id=market_id).first()

        if finder is None:
            return abort(409)

        while True:
            uuid = random.randrange(11111, 99999)
            if Orderlist_Model.objects(order_uuid=uuid).first() is None:
                break

        for Rmenu in reserve_list:
            flag = True
            for menu in finder['menu']:
                if Rmenu['name'] == menu['menu_name']:
                    flag = False

            if flag:
                abort(409)

        Sum = 0

        for s in reserve_list:
            Sum += s['price']

        user = User_Model.objects(id=get_jwt_identity()).first()

        if user['point'] < Sum:
            abort(409)

        user.update(point=user['point'] - Sum)

        user.save()

        owner = User_Model.objects(id=Market_Model.objects(
            market_id=market_id).first()['owner_id']).first()

        owner.update(point=owner['point'] + Sum)

        Orderlist_Model(order_uuid=uuid,
                        market_id=market_id,
                        customer_id=get_jwt_identity(),
                        order=reserve_list,
                        order_time=order_time).save()

        return "", 200
Ejemplo n.º 2
0
    def put(self):
        change_point = request.json['point']
        finder = User_Model.objects(id=get_jwt_identity()).first()

        finder.update(point=finder['point'] + change_point)

        return '', 201
Ejemplo n.º 3
0
    def delete(self):
        finder = User_Model.objects(id=get_jwt_identity()).first()
        markets = Market_Model.objects(owner_id=get_jwt_identity()).all()

        for market in markets:
            market.delete()

        finder.delete()

        return '', 200
Ejemplo n.º 4
0
    def get(self):
        user = User_Model.objects(id =
            get_jwt_identity()).first()

        return {
            "name": user['name'],
            "id": user['id'],
            "point": user['point'],
            "phone_num": user['phone_num']
        }, 200
Ejemplo n.º 5
0
    def post(self):
        register_id = request.json['id']
        register_name = request.json['name']
        register_pw = request.json['pw']
        register_phone_num = request.json['phone_num']
        user_type = request.json['type']
        basic_point = 0

        finder = User_Model.objects(id=register_id).first()

        if finder is not None:
            abort(409)

        User_Model(id=register_id,
                   pw=register_pw,
                   name=register_name,
                   point=basic_point,
                   phone_num=register_phone_num,
                   user_type=user_type).save()

        return '', 201
Ejemplo n.º 6
0
    def post(self):
        login_id = request.json['id']
        login_pw = request.json['pw']

        finder = User_Model.objects(id=login_id).first()

        if finder is None:
            return abort(409)

        if finder['pw'] == login_pw:
            return {
                "access_token": create_access_token(identity=login_id)
            }, 200

        return abort(409)
Ejemplo n.º 7
0
    def get(self):
        res = []
        finder = Market_Model.objects(owner_id=get_jwt_identity()).all()

        user = User_Model.objects(id=get_jwt_identity()).first()

        if finder is None:
            abort(409)

        if user['user_type'] == 0:
            abort(409)

        for market in finder:
            res.append({
                "name": market['name'],
                "image": market['image'],
                "location": market['location'],
                "tel_num": market['telephone_num'],
                "market_id": market['market_id']
            })

        return {"markets": res}, 201
Ejemplo n.º 8
0
    def post(self):
        register_name = request.json['name']
        register_loc = request.json['location']
        register_num = request.json['tel_num']
        register_image = request.json['image']
        owner_id = get_jwt_identity()

        if User_Model.objects(id = get_jwt_identity()).first()['user_type'] == 0:
            abort(409)

        finder = Market_Model.objects(location=register_loc).first()

        if finder is not None:
            return abort(409)

        finder = Market_Model.objects(telephone_num = register_loc).first()

        if finder is not None:
            return abort(409)

        while True:
            uuid = random.randrange(11111, 99999)
            if Market_Model.objects(market_id=uuid).first() is None:
                break


        Market_Model(
            owner_id = owner_id,
            name = register_name,
            location = register_loc,
            telephone_num = register_num,
            market_id = uuid,
            image = register_image,
            menu = []
        ).save()

        return '', 201
Ejemplo n.º 9
0
    def put(self):
        change_name = request.json['name']
        change_pw = request.json['pw']
        finder = User_Model.objects(id=get_jwt_identity()).first()

        if change_name == None and change_pw == None:
            abort(409)

        elif change_name == None:
            finder.update(
                pw=change_pw
            )

        elif change_pw == None:
            finder.update(
                name=change_name,
            )
        else:
            finder.update(
                name=change_name,
                pw=change_pw
            )

        return '', 201