예제 #1
0
 def create_users_topic_list( self, db: Session, *, id: str = id ):
      # Desestruturando (Unpacking) os valores do Request Body config          
     users = UsersRepository.get_by_topic(db, id=id)
             
     response_users = [response_user(user) for user in users]        
     
     return response_users
예제 #2
0
 def create_users_list( self, db: Session, ):
      # Desestruturando (Unpacking) os valores do Request Body config
     users = UsersRepository.get_all(db)
             
     response_users = [response_user(user) for user in users]        
     
     return response_users
예제 #3
0
    def validate_id( self, db: Session, *, id: str = id ) -> Dict[UsersModel,UserResponseSchema]:
        user = UsersRepository.get_by_id( db, id=id )        
        if not user:        
            raise HTTPException( status_code=400, detail="Usuário não encontrado." )

        return {
            "db_object": user,
            "response": response_user(user)
        }
예제 #4
0
    def update_user(

        self,
        db: Session,
        *,
        db_object: UsersModel,
        infos_object: Union[UserUpdateSchema,  Dict[str, Union[str, StatusOptions]]]

    ):        
        # Reforçando que o id que chega no Params seja o mesmo que o Request Body
        # infos_object['id'] = id 
        
        if "email" in infos_object:
            UsersService.validate_email(db, email=infos_object.email)
        if "username" in infos_object:
            UsersService.validate_username(db, username=infos_object.username)    
        if "password" in infos_object:       
            infos_object["password"] = Auth.hash_password(infos_object["password"])

        updated_user = UsersRepository.update(db, db_object=db_object, req_object=infos_object)
        
        return response_user(updated_user)
예제 #5
0
    def create_user( self, db: Session, *, object: UserRequestSchema ):

        created_user = UsersRepository.create(db, req_object=object)
    
        return response_user(created_user)
예제 #6
0
    def remove_user( self, db: Session, *, id: str = id ):        
        removed_user = UsersRepository.remove(db, id=id)

        return response_user(removed_user)