-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
349 additions
and
16 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import psycopg2 | ||
from Database import Database | ||
|
||
class FazMissao: | ||
|
||
def __init__(self, personagem: int, nomeMissao: str, status: bool): | ||
self.personagem = personagem | ||
self.nomeMissao = nomeMissao | ||
self.status = status | ||
pass | ||
|
||
def __init__(self): | ||
self.db = Database() | ||
pass | ||
|
||
def inserirFazMissao(self, personagem: int, nomeMissao: str, status: bool): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
|
||
cursor.execute("INSERT INTO fazmissao VALUES(%s, %s, %s);", (personagem, nomeMissao, status)) | ||
insercaoFazMissao = conexao.commit() | ||
return print("Missao inserida com sucesso!\n") | ||
|
||
except psycopg2.IntegrityError as e: | ||
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n") | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def deletarFazMissao(self, personagem: int): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor | ||
|
||
cursor.execute(f"DELETE FROM fazmissao WHERE personagem = '{personagem}';") | ||
delecaoFazMissao = cursor.commit() | ||
return print("Missao deletada com sucesso!\n") | ||
|
||
except psycopg2.IntegrityError as e: | ||
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n") | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def deletarFazMissaoEspecifica(self, personagem: int, nomeMissao: str): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
|
||
cursor.execute(f"DELETE FROM fazmissao WHERE personagem = '{personagem}' AND nomemissao = '{nomeMissao}';") | ||
delecaoFazMissao = conexao.commit() | ||
return print("Missao deletada com sucesso!\n") | ||
|
||
except psycopg2.IntegrityError as e: | ||
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n") | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def consultarFazMissao(self): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"SELECT * FROM fazmissao;") | ||
consulta = cursor.fetchall() | ||
|
||
if not consulta: | ||
print("Não foi possivel acessar a tabela\n") | ||
else: | ||
for i in consulta: | ||
print(i) | ||
return i | ||
|
||
except psycopg2.IntegrityError as e: | ||
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n") | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def consultarFazMissaoPersonagem(self, personagem: int): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"SELECT * FROM fazmissao WHERE personagem = '{personagem}';") | ||
consulta = cursor.fetchall() | ||
|
||
if not consulta: | ||
print("Não foi encontrada nenhuma missao desse personagem\n") | ||
else: | ||
for i in consulta: | ||
print(i) | ||
return i | ||
|
||
except psycopg2.IntegrityError as e: | ||
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n") | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def consultarFazMissaoNome(self, nome: str): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"SELECT * FROM fazmissao WHERE nomemissao = '{nome}';") | ||
consulta = cursor.fetchall() | ||
|
||
if not consulta: | ||
print("Não foi encontrada nenhuma missao com esse nome\n") | ||
else: | ||
for i in consulta: | ||
print(i) | ||
return i | ||
|
||
except psycopg2.IntegrityError as e: | ||
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n") | ||
|
||
finally: | ||
cursor.close() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import psycopg2 | ||
from typing import Optional | ||
from Database import Database | ||
|
||
class Instancia: | ||
|
||
def __init__(self, personagem: int, numero: int, vida: int, local: int, idPersonagem: int): | ||
self.personagem = personagem | ||
self.numero = numero | ||
self.vida = vida | ||
self.local = local | ||
self.idPersonagem = idPersonagem | ||
pass | ||
|
||
def __init__(self): | ||
self.db = Database() | ||
pass | ||
|
||
def inserirInstancia(self, personagem: int, numero: int, vida: int, local: int, idPersonagem: Optional[int]): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
|
||
# Ussando a formatação %s porque assim o psycop trata a tipagem e permite argumento None, pra quando | ||
# algo precisar ser nulo | ||
## i.inserirInstancia(3, 3, 37, 1, None) -> exemplo do None | ||
cursor.execute("INSERT INTO instancia VALUES (%s, %s, %s, %s, %s);", (personagem, numero, vida, local, idPersonagem)) | ||
insercaoInstancia = conexao.commit() | ||
return print("Instancia criada com sucesso!\n") | ||
|
||
except psycopg2.IntegrityError as e: | ||
print("Não foi possível inserir instancia na tabela: ", e) | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def deletarInstancia(self, personagem: int, numero: int): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"DELETE FROM instancia WHERE personagem = '{personagem}' AND numero = '{numero}';") | ||
delecaoInstacia = conexao.commit() | ||
return print("Instacia deletada com sucesso") | ||
|
||
except psycopg2.Error as e: | ||
print("Erro ao deletar em instancia", e) | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def consultarInstancia(self): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"SELECT * FROM instancia;") | ||
consulta = cursor.fetchall() | ||
if not consulta: | ||
print("Nao foi possivel ver instancias") | ||
else: | ||
for x in consulta: | ||
print(x) | ||
return x | ||
|
||
except psycopg2.Error as e: | ||
print("Erro ao executar a consulta:", e) | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def consultarInstanciaPersonagem(self, personagem: int): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"SELECT * FROM instancia WHERE personagem = '{personagem}';") | ||
consulta = cursor.fetchall() | ||
|
||
if not consulta: | ||
print("Não há nenhuma instancia com essas caracteristicas\n") | ||
else: | ||
for i in consulta: | ||
print(i) | ||
return i | ||
|
||
except psycopg2.Error as e: | ||
print("Não foi possivel fazer essa consulta") | ||
|
||
finally: | ||
cursor.close() | ||
|
||
def consultarInstanciaEspecifica(self, personagem: int, numero: int): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"SELECT * FROM instancia WHERE personagem = '{personagem}' AND numero = '{numero}';") | ||
consulta = cursor.fetchall() | ||
|
||
if not consulta: | ||
print("Não há nenhuma instancia com essas caracteristicas\n") | ||
else: | ||
for i in consulta: | ||
print(i) | ||
return i | ||
|
||
except psycopg2.Error as e: | ||
print("Não foi possivel fazer essa consulta") | ||
|
||
finally: | ||
cursor.close() | ||
|
||
## i = Instancia() | ||
## i.consultarInstancia() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import psycopg2 | ||
from database import Database | ||
from .Database import Database | ||
|
||
class Missao: | ||
def __init__(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import psycopg2 | ||
from .Database import Database | ||
|
||
|
||
class Personagem: | ||
def __init__(self): | ||
self.db = Database() | ||
pass | ||
|
||
def criarPersonagem(self, IDpersonagem,ATC:bool): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"""insert into personagem values({IDpersonagem},{ATC});""") | ||
insercaoPersonagem = conexao.commit() | ||
return print("Personagem criado com sucesso") | ||
except psycopg2.Error as e: | ||
print("Erro ao inserir personagem", e) | ||
finally: | ||
cursor.close() | ||
|
||
def consultarPersonagem(self): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"""Select * from personagem;""") | ||
consultarPersonagem = cursor.fetchall() | ||
for x in consultarPersonagem: | ||
print(x) | ||
|
||
except psycopg2.Error as e: | ||
print("") | ||
finally: | ||
cursor.close() | ||
|
||
def consultarPersonagemID(self, IDpersonagem:int): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
cursor.execute(f"""Select * from personagem where IDpersonagem = {IDpersonagem};""") | ||
consultarPersonagemID = cursor.fetchall() | ||
if(consultarPersonagemID == []): | ||
print('Não possui esse personagem') | ||
else: | ||
for x in consultarPersonagemID: | ||
print(x) | ||
except psycopg2.Error as e : | ||
print("Erro ao consultar personagem por ID:", e ) | ||
finally: | ||
cursor.close() | ||
|
||
def deletarPersonagem(self, IDpersonagem:int): | ||
try: | ||
conexao = self.db.conexao | ||
cursor = conexao.cursor() | ||
query = cursor.execute(f"""delete from personagem where IDpersonagem = {IDpersonagem};""") | ||
conexao.commit() | ||
query_exec = query | ||
except psycopg2.Error as e: | ||
print("Erro ao deletar em Mundo", e) | ||
finally: | ||
cursor.close() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .Mundo import * | ||
from .Regiao import * | ||
from .Local import * | ||
from .Personagem import * | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from Banco.Mundo import * | ||
from Banco.Personagem import * | ||
|
||
|
||
""" | ||
nomeMundoDestino = input("Digite o nome do seu mundoDeDestino: ") | ||
""" | ||
|
||
""" nomeMundo = input("Digite o nome do seu mundo: ") | ||
mundo = Mundo() | ||
mundo.deletarMundo(nomeMundo) | ||
mundo.consultarMundo() | ||
""" | ||
|
||
doan = Personagem() | ||
|
||
doan.criarPersonagem(4,False) | ||
print('\n') | ||
doan.consultarPersonagem() | ||
print('\n') | ||
doan.consultarPersonagemID(4) | ||
print('\n') | ||
doan.deletarPersonagem(4) | ||
doan.consultarPersonagem() |
File renamed without changes.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.