def __get_person(self, user): person = Person.objects.get(user=user) return fn.Optional(person) \ .is_null(var.ERRORS.USER_NOT_EXIST) \ .is_verify(var.ERRORS.USER_IS_NOT_VERIFY) \ .make(self.__generate_jwt)
def delete(self, idObjective, idGoal, id): return fn.Optional(id)\ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(idGoal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__remove_task(idObjective, idGoal, id))
def get(self, id): objective = Objective.objects.get(pk=id, isActive=True) return fn.Optional(id) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(objective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(Response(data={ 'objective': ObjectiveSerializer(objective).data }))
def create(self, idObjective, idGoal): task, description = fn.Http(self.request).get_properties( ['task', 'description']) return fn.Optional(idObjective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(idGoal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(task) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__create_task(idObjective, idGoal, task, description))
def get(self, idObjective, id): goal = Goal.objects.filter(objective_id=idObjective).get(pk=id, isActive=True) return fn.Optional(id) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(goal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(Response(data={ 'goal': GoalSerializer(goal).data }))
def create(self, idObjective): goal, dateGoal = fn.Http(self.request).get_properties( ['goal', 'dateGoal']) return fn.Optional(idObjective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(goal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(dateGoal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__create_goal(idObjective, goal, dateGoal))
def get(self, idObjective, idGoal, id): task = Task.objects.filter(goal__id=idGoal, goal__objective__id=idObjective).get( pk=id, isActive=True) return fn.Optional(id) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(task) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(Response(data={ 'task': TaskSerializer(task).data }))
def __get_access_token(self, token): access_token = fn.Optional(token) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(AccessToken.objects.get(token=token)) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .get() if access_token.object.is_expired(): return access_token.set_execption( er.APIExceptionDetail().get_exception( HTTP_403_FORBIDDEN, var.ERRORS.INVALID_TOKEN)) return access_token.build(self.__get_user)
def update(self, id): name, lastName = fn.Http(self.request).get_properties( ['firstName', 'lastName']) return fn.Optional(id) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(name) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(lastName) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__update_user( id, name, lastName))
def login(self): username, password = fn.Http(self.request).get_properties( ['username', 'password']) user = authenticate(self.request, username=username, password=password) return fn.Optional(username) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(password) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(user) \ .is_null(var.ERRORS.USER_NOT_EXIST) \ .is_active(var.ERRORS.USER_IS_NOT_ACTIVE) \ .make(self.__get_person)
def create(self): objective, dateObjective, dificulty = fn.Http( self.request).get_properties([ 'objective', 'dateObjective', 'dificulty' ]) return fn.Optional(objective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(dateObjective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(dificulty) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__create_objective(objective, dateObjective, dificulty))
def __get_by_email(self, email): try: person = Person.objects \ .select_related('user') \ .filter(user__is_active=True) \ .get(user__email=email) except Exception as e: print(e, email) error = var.ERRORS.PASSWORD_RECOVERY_USER_NOT_EXIST return er.APIExceptionDetail().get(HTTP_500_INTERNAL_SERVER_ERROR, error['message'], error['code'], error['severity'], error['title']) return fn.Optional(person.user) \ .is_null(var.ERRORS.USER_NOT_EXIST) \ .is_active(var.ERRORS.USER_IS_NOT_ACTIVE) \ .httpReponse(self.__send_email_with_token(person.user, var.OBJECT.RECOVERY_EMAIL))
def create(self): name, lastName, username, password, password_confirmation = fn.Http( self.request).get_properties([ 'name', 'lastName', 'username', 'password', 'passwordConfirmation' ]) return fn.Optional(name) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(lastName) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(username) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(password) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .is_equals(var.ERRORS.USER_PASSWORD_NOT_MATCH, password_confirmation) \ .httpReponse(self.__create_user( name, lastName, username, password))
def password_recovery(self): email = fn.Http(self.request).get_property('email') return fn.Optional(email) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .build(self.__get_by_email)
def __get_token(self, token, token_type): return fn.Optional(Token.objects.get(token=token, type=token_type)) \ ._is('active', var.ERRORS.INVALID_TOKEN) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .build(self.__get_user)
def done(self, idObjective, id): return fn.Optional(idObjective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(id)\ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__done_goal(idObjective, id))
def delete(self, id): return fn.Optional(id)\ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__remove_objective(id))
def __get_user(self, token): return fn.Optional(token.user) \ .is_null(var.ERRORS.USER_NOT_EXIST) \ .is_active(var.ERRORS.USER_IS_NOT_ACTIVE) \ .get()