Skip to content

Commit

Permalink
Protected parameters to private
Browse files Browse the repository at this point in the history
  • Loading branch information
alannesanni committed Dec 11, 2023
1 parent 3f6f7fe commit 542680a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/repositories/cite_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, database: Database = default_database) -> None:
database (Database, optional): Tietokantayhteydestä vastaava olio.
"""

self._database: Database = database
self.__database: Database = database

def add_cite(self, cite: Cite) -> None:
"""Kutsuu tietokannan add_cite() funktiota
Expand All @@ -22,30 +22,30 @@ def add_cite(self, cite: Cite) -> None:
cite (Cite): Cite olio
"""

self._database.cursor.execute(
self.__database.cursor.execute(
"""
INSERT INTO Cites (id, type) VALUES (?, ?)
""",
(cite.id, cite.type),
)

for name in cite.authors:
self._database.cursor.execute(
self.__database.cursor.execute(
"""
INSERT INTO Authors (cite_id, name) VALUES (?, ?)
""",
(cite.id, name),
)

for name, content in cite.fields.items():
self._database.cursor.execute(
self.__database.cursor.execute(
"""
INSERT INTO Fields (cite_id, name, content) VALUES (?, ?, ?)
""",
(cite.id, name, content),
)

self._database.connection.commit()
self.__database.connection.commit()

def get_all_cites(self) -> list[Cite]:
"""Palauttaa listan kaikista viitteistä"""
Expand All @@ -63,19 +63,19 @@ def get_all_cites(self) -> list[Cite]:

def get_all_ids(self) -> list[str]:
"""Hakee tietokannasta viitteiden id:t"""
ids = self._database.cursor.execute("SELECT id FROM Cites").fetchall()
ids = self.__database.cursor.execute("SELECT id FROM Cites").fetchall()
return [id[0] for id in ids]

def get_all_types(self) -> dict[str, str]:
"""Hakee tietokannasta viitteen tyypit"""
types = self._database.cursor.execute("SELECT id, type FROM Cites").fetchall()
types = self.__database.cursor.execute("SELECT id, type FROM Cites").fetchall()
return dict(types)

def get_all_authors(self) -> dict[str, list[str]]:
"""Hakee tietokannasta viitteen tekijät."""
authors = {}
for id in self.get_all_ids():
authors_query = self._database.cursor.execute(
authors_query = self.__database.cursor.execute(
"SELECT name FROM Authors WHERE cite_id = ?", (id,)
)
authors[id] = [author[0] for author in authors_query]
Expand All @@ -86,7 +86,7 @@ def get_all_fields(self) -> dict[str, dict[str, str]]:
"""Hakee tietokannasta viitteen tiedot"""
fields = {}
for id in self.get_all_ids():
fields_query = self._database.cursor.execute(
fields_query = self.__database.cursor.execute(
"SELECT name, content FROM Fields WHERE cite_id = ?", (id,)
)
fields[id] = dict(fields_query.fetchall())
Expand All @@ -96,16 +96,16 @@ def get_all_fields(self) -> dict[str, dict[str, str]]:
def remove_all_cites(self) -> None:
"""Poistaa kaikki viitteet."""

self._database.initialize()
self.__database.initialize()

def remove_cite(self, id: str) -> None:
"""Poistaa tietokannasta viitteen, jolla on annettu id.
Args:
id (str): Poistettavan viitteen id
"""
self._database.cursor.execute("""DELETE FROM Cites WHERE id = ?""", (id,))
self._database.connection.commit()
self.__database.cursor.execute("""DELETE FROM Cites WHERE id = ?""", (id,))
self.__database.connection.commit()


cite_repository = CiteRepository()

0 comments on commit 542680a

Please sign in to comment.