Exemple #1
0
def delete(id):
    conn = connectToDb()
    cur = conn.cursor()

    try:
        cur.execute('delete from alocacao where id = %s', (id, ))
        conn.commit()
        cur.close()
    except (Exception, psycopg2.DatabaseError) as error:
        print(error)
    finally:
        if conn is not None:
            conn.close()

    return "Cadastro deletado com sucesso"
Exemple #2
0
def get_login_by_id(id):
    conn = connectToDb()
    cur = conn.cursor(cursor_factory=RealDictCursor)

    try:
        cur.execute('select * from alocacao where id = %s', (id, ))
        result = cur.fetchone()
        cur.close()
    except (Exception, psycopg2.DatabaseError) as error:
        print(error)
    finally:
        if conn is not None:
            conn.close()

    return jsonify(result)
def api_verbs():
    if request.method == 'GET':
        conn = connectToDb()
        cur = conn.cursor(cursor_factory=RealDictCursor)

        try:
            cur.execute('select * from autenticacao')
            result = cur.fetchall()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return jsonify(result)

    elif request.method == 'POST':
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        insert into autenticacao (username, email, nome, sobrenome, senha)
                        values (%s, %s, %s, %s, %s);
                        ''', (dados['username'], dados['email'], dados['nome'],
                              dados['sobrenome'], dados['senha']))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return "Cadastro efetuado com sucesso"

    else:
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        update autenticacao 
                        set email = %s, nome = %s, sobrenome = %s, senha = %s 
                        where username = %s
                        ''', (
                    dados['email'],
                    dados['nome'],
                    dados['sobrenome'],
                    dados['senha'],
                    dados['username'],
                ))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return ("Cadastro atualizado com sucesso")
Exemple #4
0
def api_verbs():
    if request.method == 'GET':
        conn = connectToDb()
        cur = conn.cursor(cursor_factory=RealDictCursor)

        try:
            cur.execute('select * from alocacao')
            result = cur.fetchall()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return jsonify(result)

    elif request.method == 'POST':
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        insert into alocacao (usuario, livro, data_locacao, data_devolucao)
                        values (%s, %s, %s, %s);
                        ''', (dados['usuario'], dados['livro'],
                              dados['data_locacao'], dados['data_devolucao']))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return "Cadastro efetuado com sucesso"

    else:
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        update alocacao 
                        set usuario = %s, livro = %s, data_locacao = %s, data_devolucao = %s 
                        where id = %s
                        ''',
                (dados['usuario'], dados['livro'], dados['data_locacao'],
                 dados['data_devolucao'], dados['id']))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return ("Cadastro atualizado com sucesso")
def api_verbs():
    if request.method == 'GET':
        conn = connectToDb()
        cur = conn.cursor(cursor_factory=RealDictCursor)

        try:
            cur.execute('select * from livros')
            result = cur.fetchall()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return jsonify(result)

    elif request.method == 'POST':
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        insert into livros (titulo, autor, editora, descricao, datapublicacao)
                        values (%s, %s, %s, %s, %s);
                        ''',
                (dados['titulo'], dados['autor'], dados['editora'],
                 dados['descricao'], dados['datapublicacao']))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return "Livro inserido com sucesso"

    else:
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        update livros
                        set titulo = %s, autor = %s, editora = %s, descricao = %s, datapublicacao = %s
                        where id = %s
                        ''',
                (dados['titulo'], dados['autor'], dados['editora'],
                 dados['descricao'], dados['datapublicacao'], dados['id']))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return ("Livro atualizado com sucesso")
Exemple #6
0
def api_verbs():
    if request.method == 'GET':
        conn = connectToDb()
        cur = conn.cursor(cursor_factory=RealDictCursor)

        try:
            cur.execute('select * from editora')
            result = cur.fetchall()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return jsonify(result)

    elif request.method == 'POST':
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        insert into editora (nome, email, telefone)
                        values (%s, %s, %s);
                        ''',
                (dados['nome'], dados['email'], dados['telefone']))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return "Editora inserido com sucesso"

    else:
        dados = request.json

        conn = connectToDb()
        cur = conn.cursor()

        try:
            cur.execute(
                '''
                        update editora
                        set nome = %s, email = %s, telefone = %s
                        where id = %s
                        ''', (dados['nome'], dados['email'], dados['telefone'],
                              dados['id']))
            conn.commit()
            cur.close()
        except (Exception, psycopg2.DatabaseError) as error:
            print(error)
        finally:
            if conn is not None:
                conn.close()

        return ("Editora atualizado com sucesso")