def modify(self,user): try: valida = Validate() validateForm = valida.validateForm(user,['email','nome']) if validateForm['status'] =='erro': return validateForm email = user['email'] nome = user['nome'] senha = Utils.passwordEncode(user['senha']) if user['senha'] != '' else '' userExists = self._userExists(email=email) if userExists['status'] == 'erro': return userExists if len(userExists['mensagem']['conteudo']) == 0: raise Exception('Email informado não está cadastrado!') queryHandler= QueryHandler() queryResult = queryHandler.queryExec(operationType='update',proc='userModify',variables=[email,senha,nome]) if queryResult['status'] == 'erro': return queryResult return responseHandler.success(content='Alterações realizadas com sucesso!') except Exception as error: return responseHandler.error(content=error)
def modifyPlant(self, plant): try: validate = Validate() validatePlant = validate.validateForm( form=plant, param=['id-planta', 'nome-planta']) if validatePlant['status'] == 'error': return validatePlant self.id = plant['id-planta'] self.name = plant['nome-planta'] getPlant = self.getPlants(idPlant=self.id) if getPlant['status'] == 'erro': return getPlant if len(getPlant['mensagem']['conteudo']) == 0: raise Exception('Planta não Cadastrada!') queryHandler = QueryHandler() modifyPlant = queryHandler.queryExec( proc='plantModify', variables=[self.id, self.name], operationType='update') if modifyPlant['status'] == 'error': return modifyPlant return responserHandler.success( content='Nome alterado com sucesso') except Exception as error: return responserHandler.error(content=error)
def createPlant(self, plant): try: validate = Validate() validatePlant = validate.validateForm( form=plant, param=['id-estufa', 'nome-planta']) if validatePlant['status'] == 'erro': return validatePlant self.id = Utils.idGenerator() self.date = Utils.dateCapture() self.name = plant['nome-planta'] self.idGreen = plant['id-estufa'] self.photo = 'https://www.svgrepo.com/show/7691/plant.svg' queryHandler = QueryHandler() createPlant = queryHandler.queryExec(operationType='insert', variables=[ self.name, self.id, self.date, self.photo, self.idGreen ], proc='plantRegister') if createPlant['status'] == 'erro': return createPlant return responserHandler.success( content='Planta cadastrada com sucesso!') except Exception as error: return responserHandler.error(content=str(error))
def register(self, user): try: validateRegister = self._validateUserRegister(user=user) if validateRegister['status'] == 'erro': raise Exception (validateRegister['mensagem']['conteudo']) self.id = Utils.idGenerator() self.name = user['nome'] self.password = Utils.passwordEncode(user['senha']) self.date = Utils.dateCapture() self.email = user['email'] queryHandler = QueryHandler() queryResult = queryHandler.queryExec(operationType='insert',variables=[self.id, self.name, self.email, self.password, self.date],proc='userRegister') if queryResult['status'] == 'erro': return queryResult greenery = Greenery() newGreenery = greenery.createGreenery(userId=self.id) if newGreenery['status'] =='erro': return newGreenery return responseHandler.success(content='Usuário cadastrado com sucesso!') except Exception as error: return responseHandler.error(content=str(error))
def modifyGreenery(self, form): try: validate = Validate() valForm = validate.validateForm(form=form, param=['estufa-id', 'estufa-nome']) if valForm['status'] == 'erro': return valForm self.name = form['estufa-nome'] self.id = form['estufa-id'] getGreenery = self.getGreenerys(greenId=self.id) if getGreenery['status'] == 'erro': return getGreenery if len(getGreenery['mensagem']['conteudo']) == 0: raise Exception('Estufa não cadastrada!') queryHandler = QueryHandler() modify = queryHandler.queryExec(operationType='update', proc='greeneryModify', variables=[self.name, self.id]) if modify['status'] == 'erro': return modify return responseHandler.success( content='Nome da estufa alterado com sucesso!') except Exception as error: return responseHandler.error(content=error)
def createGreenery(self, userId): try: self.user_id = userId self.id = Utils.idGenerator() self.name = 'Estufa 1' self.date = Utils.dateCapture() self.photo = 'https://images.pexels.com/photos/5472378/pexels-photo-5472378.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260' queryHandler = QueryHandler() queryResult = queryHandler.queryExec(operationType='insert', variables=[ self.id, self.name, self.date, self.photo, self.user_id ], proc='greenRegister') if queryResult['status'] == 'erro': return queryResult element = Element() newElements = element.createElements(idEstufa=self.id) if newElements['status'] == 'erro': return newElements return responseHandler.success( content='Estufa cadastrada com sucesso!') except Exception as error: return responseHandler.error(content=error)
def modifyElement(self,form): try: validate = Validate() valForm = validate.validateForm(form=form, param=['elemento-id','elemento-nome']) if valForm['status'] == 'erro': return valForm self.name= form['elemento-nome'] self.id = form['elemento-id'] getElements = self.getElements(idElem=self.id) if getElements['status'] == 'erro': return getElements if len(getElements['mensagem']['conteudo']) == 0: raise Exception('Elemento não cadastrado!') queryHandler = QueryHandler() modify = queryHandler.queryExec(operationType='update',proc='elementModify', variables=[self.name,self.id]) if modify['status'] == 'erro': return modify return responseHandler.success(content='Nome do elemento alterado com sucesso!') except Exception as error: return responseHandler.error(content=str(error))
def _userExists(self,email): try: queryHandler = QueryHandler() queryResult = queryHandler.queryExec(operationType='select',variables=[email],proc='userLogin') return queryResult except Exception as error: return responseHandler.error(content=error)
def getElements(self, idEstufa='', idElem=''): try: queryHandler = QueryHandler() element = queryHandler.queryExec(operationType='select',variables=[idEstufa,idElem],proc='getElements') return element except Exception as error: return responseHandler.error(content=error)
def getPlants(self, idGreen='', idPlant=''): try: queryHandler = QueryHandler() plants = queryHandler.queryExec(operationType='select', variables=[idGreen, idPlant], proc='getPlant') return plants except Exception as error: return responserHandler.error(content=error)
def getGreenerys(self, userId='', greenId=''): try: self.user_id = userId queryHandler = QueryHandler() greenerys = queryHandler.queryExec( operationType='select', variables=[self.user_id, greenId], proc='getGreenerys') return greenerys except Exception as error: return responseHandler.error(content=error)
def deletePlant(self, idPlant): try: queryHandler = QueryHandler() deletePlant = queryHandler.queryExec(operationType='delete', proc='plantDelete', variables=[idPlant]) if deletePlant['status'] == 'error': return deletePlant return responserHandler.success( content='Planta Deletada com sucesso!') except Exception as error: return responserHandler.error(content=str(error))
def _setToken(self): try: self.token = Utils.codeGenerator() queryHandler = QueryHandler() queryResult = queryHandler.queryExec(operationType='update',variables=[self.email,self.token,Utils.dateCapture(days = 1)], proc='newToken') print (queryResult) if queryResult['status'] =='erro': return queryResult return responseHandler.success(content='Token cadastrado') except Exception as error: return responseHandler.error(content=error)