From 1bbc0631b6aaa59ef8c4b8cc35b139f72a4bdecd Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 12 Feb 2023 21:55:04 +0100 Subject: [PATCH] start add class --- __pycache__/database.cpython-310.pyc | Bin 2350 -> 2370 bytes article.py | 26 ++++++++++++++++++++++++++ database.json | 14 -------------- database.py | 2 +- grocery_list.py | 12 ++++++++++++ group.py | 23 +++++++++++++++++++++++ user.py | 25 +++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 article.py delete mode 100644 database.json create mode 100644 grocery_list.py create mode 100644 group.py create mode 100644 user.py diff --git a/__pycache__/database.cpython-310.pyc b/__pycache__/database.cpython-310.pyc index bea011148a7a1b77b8b3dd82dd9adb11462e1482..76694daa05ffb1a357227049f22d39d645bf7997 100644 GIT binary patch delta 467 zcmX|-ze@u#6vyvfa=F8DsOMy@t!=G%E&X9ztsO+fMI1!Y#V#T}hYl*FS3#+RxVSjT z!^sZqD2U+b>VF_^9lHBpm>1DNK6!cHZ{ADt>V0_bx$BM@YMdp%o9}P#1KSpAx2a}( zQ6V(?(1ih9o1xifT_faO^AcJvIO^0%PCs%^jafSDlbCg`wFBd>cnB;|_VJ z(+Y+bv5Jgu@Hof}Zt<(}xNWJ$@-Ad6bL6f;o9N3jM4{1SWX%Svp5 z!r!2nt4Y5gD+EWu=TbMVQsTdY5Qc9qyL*@5p^1W;81o?-FP|Et38J9Ah@zEEh$cnAAZ{*=#L8MwrWH&I z3qeHfY_;+)__N1fHLU!2RW6txW*YH@^yn;I1nSB7GZX6h{x$BzJQFrBxg3EE}o5wKQW>X-OSY;QZQKcVQ z&33h2Yc*s7!5YUO7K0Q<_@1DyoW*kQE#+J6{QTgS35p!NQ;CKLL6W0 d={$X}OcBxq?Mds%0zv1LsHzYG`jG*D Article: + """ + the article data + :param name: the name + :type name: str + :param id: uuid + :type id: str + :param price: price + :type price: float + :param quantity: quantity + :type quantity: int + :return: the article + :rtype: Article + """ + self.name = name; + self.id = id; + self.price = price; + self.quantity = quantity; + return (self); + + def __repr__(self): + return (f"Article(name={self.name},id={self.id},price={self.price},quantity={self.quantity})") + + def __str__(self): + return (self.__repr__()) diff --git a/database.json b/database.json deleted file mode 100644 index 33f2594..0000000 --- a/database.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "users": { - "1": { - "email": "camille@chauvet.pro", - "password": "b'$2b$12$FVOKVF9p/SlSv9ANVNDW.eOmv1f3qtB0WU86g4ED4B8J2fMBPZu7.'" - }, - "2": { - "email": "spam@camille.chauvet.pro", - "password": "b'$2b$12$D2DexgunhMTbYWkXmEQKw.Aa13W9QZE4CjsNUyaU5bSaZ8ZpdJ2hO'" - } - }, - "resets": {}, - "_default": {} -} \ No newline at end of file diff --git a/database.py b/database.py index 4455776..05a73b7 100644 --- a/database.py +++ b/database.py @@ -24,7 +24,7 @@ def user_exist(email: str): def add_user(email: str, password: str): password_hashed = hasher.hash_text(password) - users.insert({"email": email, "password": str(password_hashed)}); + users.insert({"email": email, "password": str(password_hashed), "id": uuid.uuid4()}); def check_password(email: str, password: str): password_hashed = get_user_by_email(email).get("password") diff --git a/grocery_list.py b/grocery_list.py new file mode 100644 index 0000000..0ded30c --- /dev/null +++ b/grocery_list.py @@ -0,0 +1,12 @@ +class GroceryList(): + def __init__(self, id: str, articles: list): + """ + Groceries List + :param id: uuid + :type id: str + :param articles: list of articles + :type articles: list[Article] + :return: the grocery list + :rtype: GroceryList + """ + self.id = str diff --git a/group.py b/group.py new file mode 100644 index 0000000..5065d1d --- /dev/null +++ b/group.py @@ -0,0 +1,23 @@ +class Group(): + def __init__(self, id: str, members: list, lists: list) -> Group: + """ + this class aims to store group with an id, a list of members, a lists of greceries lists + :param id: the uuid of the groups + :type id: int + :param members: the lists of members (User) + :type members: list[User] + :param lists: the lists of groceries lists + :type lists: list[GroceriesList] + :return: the group + :rtype: Group + """ + self.id = id; + self.members = members + self.lists: lists + return (self) + + def __str__(self): + return (f"Group(id={self.id},members={self.members},lists={self.lists})") + + def __repr__(self): + return (self.__str__()) diff --git a/user.py b/user.py new file mode 100644 index 0000000..0b0a70c --- /dev/null +++ b/user.py @@ -0,0 +1,25 @@ +class User(): + def __init__(self, mail: str, password: str, id: str, groups: list = []) -> User: + """ + User: store user data + :param mail: the mail address + :type mail: str + :param password: the password + :type password: str + :param id: the uuid + :type id: str + :param groups: the lists of groups the user is in + :type groups: list[Group] + :return: the user + :rtype: User + """ + self.mail = mail + self.password = password + self.id = id; + self.groups = groups + + def __repr__(self): + return (f"User(mail={self.mail},password={self.password},id={self.id},groups={self.groups})") + + def __str__(self): + return (self.__repr__())