Exemplo n.º 1
0
    def post(self):

        vl = req.get_json()
        isUserId = bool(vl[0].get('userId'))
        isStoreId = bool(vl[0].get('storeId'))

        if isStoreId:
            authorId = vl[0]['storeId']
            isExistStoreId = StoreModel.findByStoreId(authorId)
            if not bool(isExistStoreId):
                return gettex('NOT_FOUND'), 404
        else:
            authorId = vl[0]['userId']
            isExistUserId = bool(UserModel.findById(authorId))
            islimit = ProductModel.isLimit(authorId)

            if not isExistUserId:
                return gettex('NOT_FOUND'), 422

            if islimit:
                return gettex('LIMITED'), 401

        serial = ProductModel.findSerial()
        for value in vl:
            serial += 1
            proId = ProductModel.newProid(authorId, serial)
            value.update({'proId': proId})

        product = ProductSchema(many=True).load(vl, session=db.session)
        ProductModel.insertMany(product)
        return gettex('SUCCESS'), 201
Exemplo n.º 2
0
    def post(cls):
        data = req.get_json()
        store = StoreSchema().load(data, partial=('storeId', ))
        try:
            isExist = StoreModel.findByStoreName(data['storeName'])
            user = UserModel.findById(data['userId'])
            islimit = StoreModel.isLimit(data['userId'])
        except:
            return gettex('SOMETHING_WRONG'), 500

        if bool(isExist):
            return gettex('EXIST'), 422

        if not bool(user):
            return gettex('NOT_EXIST'), 404

        if islimit:
            return gettex('LIMITED'), 422

        try:
            storeId = f"ST_{store.findSerial() + 1}_{int(time())}_{user.userId}"
            store.storeId = storeId
            store.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return StoreSchema().dump(store)
Exemplo n.º 3
0
    def delete(self, userid):
        user = UserModel.findById(userid)
        if user is None:
            return gettex('NOT_FOUND'), 400
        try:
            user.delete()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
Exemplo n.º 4
0
    def delete(self,orderid):
        data = OrderHistoryModel.fetchById(orderid)
        if not bool(data):
            return gettex('NOT_FOUND'),404
        try:
            data.delete()
        except:
            return gettex('SOMETHING_WRONG'),500

        return gettex('SUCCESS'),201
Exemplo n.º 5
0
    def delete(cls, orderid):
        order = cls.model.findById(orderid)
        if not bool(order):
            return gettex('NOT_FOUND'), 404

        try:
            order.delete()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return gettex('SUCCESS'), 201
Exemplo n.º 6
0
    def delete(self, productid):
        product = ProductModel.findByProId(productid)
        if not bool(product):
            return gettex('NOT_FOUND'), 404

        try:
            product.delete()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return gettex('SUCCESS'), 201
Exemplo n.º 7
0
    def delete(cls, storeid):
        store = StoreModel.findByStoreId(storeid)
        if not bool(store):
            return gettex('NOT_FOUND'), 404

        try:
            store.delete()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return StoreSchema().dump(store)
Exemplo n.º 8
0
 def delete(self,catid):
     cat = CatagoryModel.findById(catid)
     if not bool(cat):
         return gettex('NOT_FOUND'),404
     
     try:
         cat.delete()
     except:
         return gettex('SOMETHING_WRONG'),500
     
     return CatagorySchema().dump(cat)
Exemplo n.º 9
0
    def put(self,catid):
        data = parser.parse_args()
        cat = CatagoryModel.findById(catid)
        if not bool(cat):
            return gettex('NOT_FOUND'),404
        
        cat.catName = data.catName
        try:
            cat.insert()
        except:
            return gettex('SOMETHING_WRONG'),500

        return CatagorySchema().dump(cat)
Exemplo n.º 10
0
    def post(cls):
        dataBody = parser.parse_args()
        brand = BrandSchema().load(dataBody, session=db.session)

        isExist = bool(BrandModel.findByBrandName(dataBody.brandName))
        if isExist:
            return gettex('EXIST'), 422
        try:
            brand.insert()
        except:
            return gettex('SOMETHING_WRONG'),500

        return BrandSchema().dump(brand)
Exemplo n.º 11
0
    def post(self):
        dataBody = parser.parse_args()
        dataBody.update({'catId':uuid4().hex})
        cat = CatagorySchema().load(dataBody,session=db.session)
        isExist = bool(CatagoryModel.findByName(dataBody.catName))

        if isExist:
            return gettex('EXIST'),422
        try:
            cat.insert()
        except:
            return gettex('SOMETHING_WRONG'),500

        return CatagorySchema().dump(cat)
Exemplo n.º 12
0
    def put(self):
        userid = get_jwt_claims()['userId']
        value = req.get_json()
        user = UserModel.findById(userid)
        if not bool(user):
            return gettex('NOT_FOUND'), 400

        try:
            user.name = value['name']
            user.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
Exemplo n.º 13
0
    def post(self):
        value = req.get_json()
        value.update({'userId': uuid4().hex})
        user = UserSchema().load(value, session=db.session)
        isEmail = bool(UserModel.findByEmail(user.email))
        isName = bool(UserModel.findByName(user.name))

        if isEmail or isName:
            return gettex('EXIST'), 422
        try:
            user.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
Exemplo n.º 14
0
    def put(cls, storeid):
        data = req.get_json()
        store = StoreModel.findByStoreId(storeid)
        if not bool(store):
            return gettex('NOT_FOUND'), 404

        try:
            store.storePicture = data['storePicture'] or None
            store.storeCoverImage = data['storeCoverImage'] or None
            store.storeLocation = data['storeLocation'] or None
            store.storeName = data['storeName']
            store.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return StoreSchema().dump(store)
Exemplo n.º 15
0
    def post(cls):
        value = parser.parse_args()
        user = UserModel.findByEmail(value.email)
        if user and safe_str_cmp(user.password, value.password):
            return cls.newToken(user)

        return gettex('NOT_FOUND'), 400
Exemplo n.º 16
0
    def put(self,brandid):

        value = parser.parse_args()
        data = BrandModel.findById(brandid)
        dataName = BrandModel.findByBrandName(value.brandName)

        if data is None:
            return gettex('NOT_FOUND'),404
            
        data.brandName = value.brandName
        try:
            data.insert()
        except:
            return gettex('SOMETHING_WRONG'),500

        return BrandSchema().dump(data)
Exemplo n.º 17
0
 def delete(self,brandid):
     data = BrandModel.findById(brandid)
     if data is None:
         return gettex('NOT_FOUND'),404
     
     data.delete()
     return BrandSchema().dump(data)
Exemplo n.º 18
0
    def post(cls):
        value = parser.parse_args()

        isUserId = cls.user.findById(value.userId)
        if not bool(isUserId):
            return gettex('NOT_FOUND'), 404

        orderid = cls.model.generateId(value.userId)
        value.update({'orderId': orderid})
        order = cls.schema().load(value, session=db.session)

        try:
            order.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return cls.schema().dump(order)
Exemplo n.º 19
0
    def put(self, productid):
        value = req.get_json()
        product = ProductModel.findByProId(productid)
        if not bool(product):
            return gettex('NOT_FOUND'), 404

        try:
            product.proName = value['proName']
            product.proPrice = value['proPrice']
            product.proImg = value['proImg']
            product.proQuantity = value['proQuantity']
            product.feature = value['feature']
            product.desc = value['desc']
            product.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return ProductSchema().dump(product)
Exemplo n.º 20
0
    def post(self):
        vl = req.get_json()

        for value in vl:
            if not bool(value.get('orderId')) or not bool(value.get('proId')):
                return gettex('NOT_FOUND'),404

            isExistOrderId = OrderModel.findById(value['orderId'])
            isExistProId = ProductModel.findByProId(value['proId'])
            if not bool(isExistOrderId) or not bool(isExistProId):
                return gettex('NOT_FOUND'),404

        data = OrderHistorySchema(many=True).load(vl,session=db.session)
        try:
            OrderHistoryModel.insertMany(data)
        except:
            return gettex('SOMETHING_WRONG'),500

        return gettex('SUCCESS'),201
Exemplo n.º 21
0
    def get(self, userid):
        user = UserModel.findById(userid)
        if user is None:
            return gettex('NOT_FOUND'), 400

        return UserSchema().dump(user)
Exemplo n.º 22
0
    def get(self,catid):
        cat = CatagoryModel.findById(catid)
        if not bool(cat):
            return gettex('NOT_FOUND'),404

        return CatagorySchema().dump(cat)
Exemplo n.º 23
0
    def get(self, productid):
        product = ProductModel.findByProId(productid)
        if not bool(product):
            return gettex('NOT_FOUND'), 404

        return ProductSchema().dump(product)
Exemplo n.º 24
0
    def get(cls, storeid):
        store = StoreModel.findByStoreId(storeid)
        if not bool(store):
            return gettex('NOT_FOUND'), 404

        return StoreSchema().dump(store)
Exemplo n.º 25
0
    def get(cls, orderid):
        order = cls.model.findById(orderid)
        if not bool(order):
            return gettex('NOT_FOUND'), 404

        return cls.schema().dump(order)
Exemplo n.º 26
0
    def get(self,orderid):
        data = OrderHistoryModel.fetchById(orderid)
        if not bool(data):
            return gettex('NOT_FOUND'),404

        return OrderHistorySchema.dump(data)