def delete(self, accountId: str):
        self.connection.open()
        sql = """
            DECLARE	@return_value int,
                    @estado int,
                    @salida nvarchar(1000)

            EXEC	@return_value = [dbo].[SPD_DeleteAccount]
                    @idAccount = ?,
                    @estado = @estado OUTPUT,
                    @salida = @salida OUTPUT
        """
        params = (accountId)
        self.connection.cursor.execute(sql, params)
        row = self.connection.cursor.rowcount
        print(row)
        if row == -1:
            raise DataBaseException("Error deleting account")

        try:
            self.connection.save()
            self.connection.close()
            return True
        except DataBaseException as ex:
            raise DataBaseException("Error al actualizar la Base de datos: ",
                                    ex)
    def exist_account(self, idAccount: str):
        sql = """\
            DECLARE	@return_value int,
                    @estado int,
                    @salida nvarchar(1000)

            EXEC	@return_value = [dbo].[SPS_AccountExist]
                    @idAccount = ?,
                    @estado = @estado OUTPUT,
                    @salida = @salida OUTPUT

            SELECT	@estado as N'@estado',
                    @salida as N'@salida'
        """
        try:
            self.connection.open()
            self.connection.cursor.execute(sql, idAccount)
        except Exception as ex:
            raise DataBaseException("Database connection error")

        row = self.connection.cursor.fetchval()
        result = False
        if row == -1:
            result = False
        else:
            result = True
        self.connection.close()
        return result
    def update(self, account: Account):
        self.connection.open()
        sql = """
        DECLARE	@return_value int,
                @salida nvarchar(1000),
                @estado int

        EXEC	@return_value = [dbo].[SPU_UpdateAccount]
                @idAccount = ?,
                @firstName = ?,
                @lastName = ?,
                @userName = ?,
                @birthday = ?,
                @cover = ?,
                @updated = ?,
                @salida = @salida OUTPUT,
                @estado = @estado OUTPUT
        """
        params = (account.idAccount, account.firstName, account.lastName,
                  account.userName, account.birthday, account.cover,
                  account.updatedDate)

        self.connection.cursor.execute(sql, params)
        try:
            self.connection.save()
            print(self.connection.cursor.rowcount, " Accounts updated")
            self.connection.close()
            return True
        except DataBaseException as identifier:
            raise DataBaseException("Error en la conexión a la BD")
Пример #4
0
    def execute(self, inputLoginAccount: LoginAccountInputDto):

        if not inputLoginAccount.user and not inputLoginAccount.password:
            raise EmptyFieldsException("Empty fields.")

        account = Account(None, None, None, inputLoginAccount.user,
                          inputLoginAccount.password, inputLoginAccount.user,
                          None, None, None, None, None, None, None)

        try:
            username_exists = self.repository.exist_userName(account.userName)
            email_exists = self.repository.exist_email(account.email)

            if not username_exists and not email_exists:
                raise UserNotExistsException("Username or email not exists.")

            if username_exists:
                account = self.repository.login_with_username(
                    account.userName, account.encode(account.password))
            else:
                account = self.repository.login_with_email(
                    account.email, account.encode(account.password))

            if not account:
                raise LoginFailedException("Incorrect credentials.")

            return account

        except DataBaseException as ex:
            raise DataBaseException(ex)
Пример #5
0
 def open(self):
     try:
         self.connection: pyodbc.Connection = pyodbc.connect(
             self.connectionString)
         self.cursor: pyodbc.Cursor = self.connection.cursor()
     except Exception as ex:
         raise DataBaseException(ex)
Пример #6
0
    def execute(self, inputAccount: CreateAccountInputDto):
        newAccount = Account.create(inputAccount.firstName,
                                    inputAccount.lastName, inputAccount.email,
                                    inputAccount.password,
                                    inputAccount.userName, inputAccount.gender,
                                    inputAccount.birthday, inputAccount.cover,
                                    inputAccount.typeRegister)

        if self.repository.exist_email(newAccount.email):
            raise EmailAlreadyExistException("Email already exist")

        if self.repository.exist_userName(newAccount.userName):
            raise UserNameAlreadyExistException("User name already exist")

        if inputAccount.cover:
            nameCover = Image.generate_name(inputAccount.userName)
            if Image.Image.save_image(inputAccount.cover, nameCover,
                                      "Account"):
                inputAccount.cover = nameCover
            else:
                inputPlaylist.cover = "defaultAccountCover.jpeg"

        try:
            account = self.repository.save(newAccount)
            return newAccount
        except DataBaseException:
            raise DataBaseException("Error en la base de datos")
Пример #7
0
    def execute(self, idAccount):

        try:
            exists = self.repository.exist_account(idAccount)
            if not exists:
                raise AccountNotExistException("Account not exist")

            return exists
        except DataBaseException as ex:
            raise DataBaseException(ex)
Пример #8
0
    def execute(self, inputAccount: DeleteAccountInputDto):
        if not inputAccount.idAccount:
            raise AccountInvalidException("Campos vacíos")

        if not self.repository.exist_account(inputAccount.idAccount):
            raise AccountNotExistException("Account not exist")

        try:
            result = self.repository.delete(inputAccount.idAccount)
            return result
        except AccountNotExistException as ex:
            raise AccountNotExistException(ex)
        except DataBaseException as ex:
            raise DataBaseException(ex)
    def save(self, account: Account):
        self.connection.open()
        sql = """
                DECLARE	@return_value int,
                @salida nvarchar(1000),
                @estado int

        EXEC	@return_value = [dbo].[SPI_CreateAccount]
                @IdAccount = ?,
                @firstName = ?,
                @lastName = ?,
                @email = ?,
                @password = ?,
                @userName = ?,
                @gender = ?,
                @birthday = ?,
                @cover = ?,
                @created = ?,
                @updated = ?,
                @contentCreator = ?,
                @typeRegister = ?,
                @salida = @salida OUTPUT,
                @estado = @estado OUTPUT

        SELECT	@salida as N'@salida',
                @estado as N'@estado'
        """
        params = (account.idAccount, account.firstName, account.lastName,
                  account.email, account.password, account.userName,
                  account.gender, account.birthday, account.cover,
                  account.createdDate, None, account.contentCreator,
                  account.typeRegister)

        self.connection.cursor.execute(sql, params)

        try:
            self.connection.save()
            print(self.connection.cursor.rowcount, " Account created")
            self.connection.close()
            return True
        except DataBaseException as ex:
            raise DataBaseException("Error en la conexión a la BD")