From 7d6f23b52402351ace79e72f73ab7a55354010d0 Mon Sep 17 00:00:00 2001 From: arturiermolenko Date: Sat, 8 Jul 2023 00:31:15 +0200 Subject: [PATCH 1/2] Solution --- app/cinema | Bin 0 -> 12288 bytes app/main.py | 26 ++++++++++++------------- app/managers.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ app/models.py | 8 ++++++++ 4 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 app/cinema create mode 100644 app/managers.py create mode 100644 app/models.py diff --git a/app/cinema b/app/cinema new file mode 100644 index 0000000000000000000000000000000000000000..f56e4d94d94f2f8683266bb64465a7693f46a64f GIT binary patch literal 12288 zcmeI&!A`<37zgkch$bdb5;e;bjo-lo1mZ!%-HDA7$G|x>oJbubSu#do^Wc$p@F9Ez z--Va(-~(7B96%GUhWx*--M+2uw%<<6_Hb{9X+VR~WT;ZQU`56`yCh-WTbTmm8ZDwVL z#Xc&9eQG$Kypb-o-A2=LyL2bJWOck&!_gy}((%Y?>DsaFDhQ3 None: + self._connection = sqlite3.connect("cinema") + self.table_name = "actors" + + def create( + self, + first_name: str, + last_name: str + ) -> None: + self._connection.execute( + f"INSERT INTO {self.table_name}" + "(first_name, last_name) VALUES (?, ?)", + (first_name, last_name) + ) + self._connection.commit() + + def all(self) -> list[Actor]: + actors_cursor = self._connection.execute( + f"SELECT id, first_name, last_name FROM {self.table_name}" + ) + return [Actor(*row) for row in actors_cursor] + + def update( + self, + id_to_update: int, + new_first_name: str, + new_last_name: str + ) -> None: + self._connection.execute( + f"UPDATE {self.table_name} " + "SET (first_name, last_name) = (?, ?)" + "WHERE id = ?", + (new_first_name, new_last_name, id_to_update) + ) + self._connection.commit() + + def delete(self, id_to_delete: int) -> None: + self._connection.execute( + f"DELETE FROM {self.table_name} " + "WHERE id = ?", + (id_to_delete,) + ) + self._connection.commit() diff --git a/app/models.py b/app/models.py new file mode 100644 index 00000000..3e228ce3 --- /dev/null +++ b/app/models.py @@ -0,0 +1,8 @@ +from dataclasses import dataclass + + +@dataclass +class Actor: + id: int + first_name: str + last_name: str From 9331e08084e2e4c6d8d5591f9b430ed8871e5a13 Mon Sep 17 00:00:00 2001 From: arturiermolenko Date: Sat, 8 Jul 2023 18:06:01 +0200 Subject: [PATCH 2/2] Solution --- .gitignore | 1 + app/cinema | Bin 12288 -> 0 bytes app/main.py | 4 ++-- app/managers.py | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 app/cinema diff --git a/.gitignore b/.gitignore index d4a2e5c5..d43f5bee 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ venv/ .pytest_cache/ **__pycache__/ **db.sqlite3 +app/cinema diff --git a/app/cinema b/app/cinema deleted file mode 100644 index f56e4d94d94f2f8683266bb64465a7693f46a64f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&!A`<37zgkch$bdb5;e;bjo-lo1mZ!%-HDA7$G|x>oJbubSu#do^Wc$p@F9Ez z--Va(-~(7B96%GUhWx*--M+2uw%<<6_Hb{9X+VR~WT;ZQU`56`yCh-WTbTmm8ZDwVL z#Xc&9eQG$Kypb-o-A2=LyL2bJWOck&!_gy}((%Y?>DsaFDhQ3 None: - self._connection = sqlite3.connect("cinema") + self._connection = sqlite3.connect("cinema.db3") self.table_name = "actors" def create(